Piscine42

This commit is contained in:
2023-12-12 17:25:55 +01:00
commit e07184f084
62 changed files with 1572 additions and 0 deletions

25
C08/ex01/ft_boolean.h Executable file
View File

@@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_boolean.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/15 14:30:45 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:24:26 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_BOOLEAN_H
# define FT_BOOLEAN_H
# include <unistd.h>
# define EVEN(n) n % 2 == 0
typedef int t_bool;
# define FALSE 0
# define TRUE 1
# define EVEN_MSG "I have an even number of arguments.\n"
# define ODD_MSG "I have an odd number of arguments.\n"
# define SUCCESS 0
#endif

16
C08/ex02/ft_abs.h Executable file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_abs.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 12:25:59 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:40:44 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_ABS_H
# define FT_ABS_H
# define ABS(x) (((x) < 0) ? -(x) : (x))
#endif

20
C08/ex03/ft_point.h Executable file
View File

@@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_point.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/18 12:51:34 by fgras-ca #+# #+# */
/* Updated: 2022/12/18 12:53:57 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_POINT_H
# define FT_POINT_H
typedef struct point{
int x;
int y;
}t_point;
#endif

68
C08/ex04/ft_strs_to_tab.c Executable file
View File

@@ -0,0 +1,68 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strs_to_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/21 09:54:48 by fgras-ca #+# #+# */
/* Updated: 2022/12/21 11:15:13 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_stock_str.h"
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i])
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *dest;
int i;
i = 0;
dest = (char *) malloc(sizeof(char) * (ft_strlen(src) + 1));
if (dest == 0)
{
return (0);
}
while (src[i])
{
dest[i] = src[i];
i++;
}
dest[i] = 0;
return (dest);
}
struct s_stock_str *ft_strs_to_tab(int ac, char **av)
{
int i;
t_stock_str *tab;
if (ac < 1)
ac = 0;
tab = malloc(sizeof(t_stock_str) * (ac + 1));
if (tab == 0)
{
return (0);
}
i = 0;
while (i < ac)
{
tab[i].size = ft_strlen (av[i]);
tab[i].str = av[i];
tab[i].copy = ft_strdup (tab[i].str);
i++;
}
tab[i].str = 0;
return (tab);
}

72
C08/ex05/ft_show_tab.c Executable file
View File

@@ -0,0 +1,72 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_show_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/12/21 10:43:27 by fgras-ca #+# #+# */
/* Updated: 2022/12/21 11:44:58 by fgras-ca ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include "ft_stock_str.h"
struct s_stock_str *ft_strs_to_tab(int ac, char **av);
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *str)
{
int i;
i = 0;
while (str[i] != '\0')
{
write(1, &str[i], 1);
i++;
}
}
void ft_putnbr(int nb)
{
if (nb == -2147483648)
{
write(1, "-2147483648", 11);
}
else if (nb >= 0 && nb < 10)
{
ft_putchar(nb + 48);
}
else if (nb < 0)
{
ft_putchar('-');
ft_putnbr(nb * (-1));
}
else
{
ft_putnbr (nb / 10);
ft_putnbr (nb % 10);
}
}
void ft_show_tab(struct s_stock_str *par)
{
int i;
i = 0;
while (par[i].str)
{
ft_putstr(par[i].str);
ft_putchar('\n');
ft_putnbr(par[i].size);
ft_putchar('\n');
ft_putstr(par[i].copy);
ft_putchar('\n');
i++;
}
}

BIN
C08/fr.subject.pdf Normal file

Binary file not shown.