This commit is contained in:
Camille Chauvet
2023-05-17 16:45:25 +00:00
commit 29ed24d567
619 changed files with 16119 additions and 0 deletions

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 15:22:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:33:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_ft(int *nbr)
{
*nbr = 42;
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:27:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:53:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:46:50 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:51:16 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:58:15 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:35:36 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:37:49 by cchauvet #+# #+# */
/* Updated: 2022/07/19 19:06:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int c;
int d;
c = *a / *b;
d = *a % *b;
*a = c;
*b = d;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/14 19:18:13 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
while (*str != 0)
{
write(1, str++, 1);
}
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:34:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strlen(char *str)
{
int a;
a = 0;
while (*str != 0)
{
a++;
str++;
}
return (a);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/15 09:31:51 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:54:35 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}
void ft_rev_int_tab(int *tab, int size)
{
int i;
i = 0;
while (i < size / 2)
{
ft_swap(tab + i, tab + size - i - 1);
i++;
}
}

BIN
Correction/C01/ex08/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 19:08:01 by cchauvet #+# #+# */
/* Updated: 2022/07/20 15:41:40 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
void ft_sort_int_tab(int *tab, int size)
{
int i;
int j;
int tempo;
i = 0;
while (i < size)
{
j = 0;
while (j < size - 1)
{
if (tab[j] > tab[j + 1])
{
tempo = tab[j];
tab[j] = tab[j + 1];
tab[j + 1] = tempo;
}
j++;
}
i++;
}
}
#include <stdio.h>
int main()
{
int tab[] = {6,-5,9,3,2,1};
int i = 0;
ft_sort_int_tab(tab, 6);
while (i < 6)
{
printf("%d,", tab[i]);
i++;
}
}

BIN
Correction/C_07ma/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,54 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 09:56:34 by cchauvet #+# #+# */
/* Updated: 2022/07/28 19:22:14 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != 0)
{
dest[i] = src[i];
i++;
}
return (dest);
}
unsigned int ft_strlen(char *str)
{
unsigned int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *dest;
dest = malloc(sizeof(src) * ft_strlen(src));
ft_strcpy(dest, src);
return (dest);
}
#include <stdio.h>
int main(void)
{
char str[] = "Hello World !";
printf("%s\n", ft_strdup(str));
}

BIN
Correction/C_07ma/ex01/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,55 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 18:54:20 by cchauvet #+# #+# */
/* Updated: 2022/07/28 19:25:51 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int i;
int *tab;
tab = NULL;
if (max <= min)
return (tab);
tab = malloc(sizeof(*tab) * (max - min));
i = 0;
while (min + i < max)
{
*(tab + i) = min + i;
i++;
}
return (tab);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv)
{
int i;
int min;
int max;
int *tab;
if (argc > 2)
{
i = 0;
min = atoi(argv[1]);
max = atoi(argv[2]);
tab = ft_range(min, max);
while (i < max - min)
{
printf("%d, ", *(tab + i));
i++;
}
}
}

BIN
Correction/C_07ma/ex02/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 10:33:24 by cchauvet #+# #+# */
/* Updated: 2022/07/28 19:34:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_ultimate_range(int **range, int min, int max)
{
int i;
*range = NULL;
if (max <= min)
return (0);
*range = malloc(sizeof(*range) * (max - min));
i = 0;
while (min + i < max)
{
(*range)[i] = min + i;
i++;
}
return (max - min);
}
#include <stdio.h>
int main(void)
{
int temp1;
int *temp2;
int **tab;
temp1 = 0;
temp2 =&temp1;
tab = &temp2;
printf("%d", ft_ultimate_range(tab, 10, 2));
printf("\n");
//for (int ind = 0; ind<10; ind++)
//{
// printf("%i, ", (*tab)[ind]);
//}
return (0);
}

BIN
Correction/C_07ma/ex03/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,77 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/24 13:29:37 by cchauvet #+# #+# */
/* Updated: 2022/07/28 19:49:10 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *str)
{
char i;
i = 0;
while (str[i] != 0)
i++;
}
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
j = 0;
i = 0;
while (dest[i] != 0)
i++;
while (src[j] != 0)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = 0;
return (dest);
}
char *ft_strjoin(int size, char **strs, char *sep)
{
int i;
int word_counter;
char *out;
if (size == 0)
{
out = malloc(sizeof(*out));
out = "";
return (out);
}
i = 0;
while (i < size)
{
word_counter += ft_strlen(strs[i]);
word_counter += ft_strlen(sep);
i++;
}
out = malloc(sizeof(*out) * word_counter);
i = 0;
while (i < size)
{
ft_strcat(out, strs[i++]);
ft_strcat(out, sep);
}
return (out);
}
#include <stdio.h>
int main(int argc, char **argv)
{
printf("%s\n", ft_strjoin(argc, argv, " "));
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 15:05:40 by cchauvet #+# #+# */
/* Updated: 2022/07/25 09:59:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}

View File

@ -0,0 +1,19 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 15:04:52 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
while (*str != 0)
write(1, str++, 1);
}

View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 14:48:52 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:23 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putnbr(int nbr)
{
if (nbr == -2147483648)
{
ft_putnbr(-2);
ft_putnbr(147483648);
}
else if (nbr < 0)
{
ft_putchar('-');
ft_putnbr(-nbr);
}
else if (nbr > 9)
{
ft_putnbr(nbr / 10);
ft_putnbr(nbr % 10);
}
else
{
ft_putchar(nbr + 48);
}
}

View File

@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 10:08:23 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:00:39 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int i;
int sign;
int nbr;
i = 0;
sign = 1;
nbr = 0;
while (str[i] == ' ')
i++;
while (str[i] == '+' || str[i] == '-')
{
if (str[i] == '-')
sign = sign * -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9')
{
nbr = (nbr * 10 + (str[i] - '0'));
i++;
}
return (nbr * sign);
}

BIN
Correction/c04corec/ex04/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,78 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 13:52:59 by cchauvet #+# #+# */
/* Updated: 2022/07/25 16:14:09 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_baser(char *str)
{
int i;
int j;
int count;
i = -1;
while (str[++i] != 0)
{
count = 0;
j = 0;
while (str[j] != 0)
{
if (str[i] == str[j])
count++;
j++;
}
if (count > 1)
return (0);
if (str[i] == '+')
return (0);
if (str[i] == '-')
return (0);
}
if (i == 1)
return (0);
return (i);
}
void ft_put(char c)
{
write(1, &c, 1);
}
void ft_putnbr_base(int nbr, char *base)
{
int base_size;
base_size = ft_baser(base);
if (base_size == 0)
return ;
if (nbr == -2147483648)
{
ft_putnbr_base(-2, base);
ft_putnbr_base(147483648, base);
}
else if (nbr < 0)
{
ft_put('-');
ft_putnbr_base(-nbr, base);
}
else if (nbr > base_size - 1)
{
ft_putnbr_base(nbr / base_size, base);
ft_putnbr_base(nbr % base_size, base);
}
else
ft_put(base[nbr]);
}
int main(void)
{
ft_putnbr_base(56, "0123456789abcdef");
}

View File

@ -0,0 +1,73 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 14:48:20 by cchauvet #+# #+# */
/* Updated: 2022/07/25 10:01:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_baser(char *str)
{
int i;
int j;
int count;
i = -1;
while (str[++i] != 0)
{
count = 0;
j = 0;
while (str[j] != 0)
if (str[i] == str[j++])
count++;
if (count > 1 || str[i] == '+' || str[i] == '-')
return (0);
}
if (i == 1)
return (0);
return (i);
}
int ft_find(char *str, char to_find)
{
int i;
i = 0;
while (str[i] != 0)
{
if (str[i] == to_find)
return (i);
i++;
}
return (-1);
}
int ft_atoi_base(char *str, char *base)
{
int base_size;
int sign;
int nbr;
int i;
nbr = 0;
sign = 1;
base_size = ft_baser(base);
i = 0;
if (base == 0)
return (0);
while (str[i] != ' ')
i++;
while (str[i] == '+' || str[i] == '-')
if (str[i++] == '-')
sign = sign * -1;
while (ft_find(base, str[i]) != -1)
{
nbr = nbr * base_size + ft_find(base, str[i]);
str++;
}
return (nbr * sign);
}

View File

@ -0,0 +1,51 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 09:56:34 by cchauvet #+# #+# */
/* Updated: 2022/08/03 16:21:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != 0)
{
dest[i] = src[i];
i++;
}
dest[i] = '\0';
return (dest);
}
unsigned int ft_strlen(char *str)
{
unsigned int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *dest;
dest = malloc(sizeof(*dest) * (ft_strlen(src) + 1));
ft_strcpy(dest, src);
return (dest);
}
#include <stdio.h>
int main()
{
ft_strdup()
}

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 18:54:20 by cchauvet #+# #+# */
/* Updated: 2022/08/01 14:36:12 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int i;
int *tab;
tab = NULL;
if (max <= min)
return (tab);
tab = malloc(sizeof(*tab) * (max - min));
i = 0;
while (min + i < max)
{
*(tab + i) = min + i;
i++;
}
return (tab);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 10:33:24 by cchauvet #+# #+# */
/* Updated: 2022/08/01 14:36:41 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_ultimate_range(int **range, int min, int max)
{
int i;
*range = NULL;
if (max <= min)
return (0);
*range = malloc(sizeof(*range) * (max - min));
i = 0;
while (min + i < max)
{
(*range)[i] = min + i;
i++;
}
return (max - min);
}

View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/24 13:29:37 by cchauvet #+# #+# */
/* Updated: 2022/08/03 14:20:13 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
j = 0;
i = 0;
while (dest[i] != 0)
i++;
while (src[j] != 0)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = 0;
return (dest);
}
char *ft_strjoin(int size, char **strs, char *sep)
{
int i;
int word_counter;
char *out;
if (size == 0)
{
out = malloc(sizeof(*out));
out = "";
return (out);
}
i = -1;
while (++i < size)
{
word_counter += ft_strlen(strs[i]);
word_counter += ft_strlen(sep);
}
out = malloc(sizeof(*out) * word_counter);
i = 0;
while (i < size)
{
ft_strcat(out, strs[i++]);
if (i < size)
ft_strcat(out, sep);
}
return (out);
}

View File

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/01 16:20:17 by cchauvet #+# #+# */
/* Updated: 2022/08/01 16:20:49 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strstr(char *str, char *to_find)
{
unsigned int i;
unsigned int j;
i = 0;
while (str[i] != 0)
{
j = 0;
while (str[i + j] == to_find[j])
{
if (to_find[j + 1] == 0)
return (i);
j++;
}
i++;
}
return (i);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char **ft_split(char *str, char *sep)
{
char **tab;
int i;
int j;
int k;
i = 0;
j = 0;
tab = malloc(sizeof(*str) * ft_strlen(str));
while (str[i] != 0 && ft_strlen(str) > i)
{
k = i;
tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1));
while (i < k + ft_strstr(&str[k], sep))
{
tab[j][i - k] = str[i];
i++;
}
tab[j][i - k] = '\0';
i = k + ft_strstr(&str[k], sep) + ft_strlen(sep);
j++;
}
tab[j] = malloc(sizeof(char));
tab[j] = "";
return (tab);
}

BIN
Correction/cchauvetc06_1/a.out Executable file

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_program_name.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlauro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 13:22:56 by mlauro #+# #+# */
/* Updated: 2022/08/01 13:04:03 by mlauro ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
i = 0;
if (argc >= 0)
{
while (argv[0][i])
write(1, &argv[0][i++], 1);
}
write(1, "\n", 1);
}

View File

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_print_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlauro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 14:20:22 by mlauro #+# #+# */
/* Updated: 2022/07/25 14:23:49 by mlauro ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
int j;
i = 1;
j = 0;
while (i < argc)
{
j = 0;
while (argv[i][j])
{
write(1, &argv[i][j], 1);
j++;
}
write(1, "\n", 1);
i++;
}
return (0);
}

View File

@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlauro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 14:26:07 by mlauro #+# #+# */
/* Updated: 2022/08/01 14:22:25 by mlauro ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int main(int argc, char **argv)
{
int i;
int j;
i = argc;
while (i > 1)
{
j = 0;
while (argv[i - 1][j])
{
write(1, &argv[i - 1][j], 1);
j++;
}
write(1, "\n", 1);
i--;
}
return (0);
}

View File

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_params.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mlauro <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 14:29:51 by mlauro #+# #+# */
/* Updated: 2022/07/25 17:32:53 by mlauro ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] != '\0' && s2[i] != '\0')
{
if (s1[i] != s2[i])
{
return (s1[i] - s2[i]);
}
i++;
}
return (s1[i] - s2[i]);
}
void print_string(char *s)
{
int i;
i = 0;
while (s[i])
write(1, &s[i++], 1);
write(1, "\n", 1);
}
void ft_sort_argv(int argc, char **argv)
{
char *tmp;
int i;
int j;
i = 1;
while (i < argc - 1)
{
j = 0;
while (j < argc - 1)
{
if (ft_strcmp(argv[j], argv[j + 1]) > 0)
{
tmp = argv[j];
argv[j] = argv[j + 1];
argv[j + 1] = tmp;
}
j++;
}
i++;
}
}
int main(int argc, char **argv)
{
int i;
i = 1;
ft_sort_argv(argc, argv);
while (i < argc)
{
print_string(argv[i]);
i++;
}
}

BIN
Correction/corC05ma/ex00/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:18:33 by cchauvet #+# #+# */
/* Updated: 2022/07/28 17:23:42 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int nbr_out;
if (nb < 0)
return (0);
nbr_out = 1;
while (nb > 0)
{
nbr_out = nbr_out * nb;
nb--;
}
return (nbr_out);
}
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
if (argc > 1)
printf("%d", ft_iterative_factorial(atoi(argv[1])));
}

View File

@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:06:51 by cchauvet #+# #+# */
/* Updated: 2022/07/26 16:55:09 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
if (nb == 1)
return (nb);
else
return (nb * ft_recursive_factoriel(nb - 1));
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:17:04 by cchauvet #+# #+# */
/* Updated: 2022/07/26 16:55:22 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int nbr_out;
if (power < 0)
return (0);
if (power == 0)
return (1);
nbr_out = nb;
while (--power > 0)
nbr_out = nbr_out * nb;
return (nbr_out);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 17:28:20 by cchauvet #+# #+# */
/* Updated: 2022/07/27 17:42:57 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int power)
{
if (power < 0)
return (0);
if (power == 0)
return (1);
return (ft_recursive_power(nb, power - 1) * nb);
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 10:23:01 by cchauvet #+# #+# */
/* Updated: 2022/07/25 17:30:54 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (index == 0)
return (0);
if (index == 1)
return (1);
if (index < 0)
return (-1);
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/25 17:33:47 by cchauvet #+# #+# */
/* Updated: 2022/07/25 17:35:41 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt(int nb)
{
int i;
i = 1;
while (i <= nb / i)
{
if (i * i == nb)
return (i);
i++;
}
return (0);
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:40:46 by cchauvet #+# #+# */
/* Updated: 2022/07/27 16:51:04 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
while (i <= nb / i)
{
if (nbr % i == 0)
return (0);
i++;
}
return (1);
}

View File

@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 14:31:43 by cchauvet #+# #+# */
/* Updated: 2022/07/26 16:58:24 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int i;
i = 2;
while (i <= nb / i)
{
if (nb % i == 0)
return (0);
i++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
int i;
i = nb;
while (ft_is_prime(i) == 0)
i++;
return (i);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 15:22:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:33:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_ft(int *nbr)
{
*nbr = 42;
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:27:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:53:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:46:50 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:51:16 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:58:15 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:35:36 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:37:49 by cchauvet #+# #+# */
/* Updated: 2022/07/19 19:06:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int c;
int d;
c = *a / *b;
d = *a % *b;
*a = c;
*b = d;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/14 19:18:13 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
while (*str != 0)
{
write(1, str++, 1);
}
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:34:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strlen(char *str)
{
int a;
a = 0;
while (*str != 0)
{
a++;
str++;
}
return (a);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/15 09:31:51 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:54:35 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}
void ft_rev_int_tab(int *tab, int size)
{
int i;
i = 0;
while (i < size / 2)
{
ft_swap(tab + i, tab + size - i - 1);
i++;
}
}

View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sort_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/19 19:08:01 by cchauvet #+# #+# */
/* Updated: 2022/07/19 20:49:46 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
void ft_sort_int_tab(int *tab, int size)
{
int i;
int j;
int tempo;
i = 0;
while (i < size)
{
j = 0;
while (j < size - 1)
{
if (tab[j] > tab[j + 1])
{
tempo = tab[j];
tab[j] = tab[j + 1];
tab[j + 1] = tempo;
}
j++;
}
i++;
}
}
/*
#include <stdio.h>
int main()
{
int tab[] = {6,5,4,3,2,1};
int i = 0;
ft_sort_int_tab(tab, 6);
while (i < 6)
{
printf("%d,", tab[i]);
i++;
}
}
*/

Binary file not shown.

View File

@ -0,0 +1,52 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strdup.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 09:56:34 by cchauvet #+# #+# */
/* Updated: 2022/08/01 17:13:02 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *ft_strcpy(char *dest, char *src)
{
int i;
i = 0;
while (src[i] != 0)
{
dest[i] = src[i];
i++;
}
return (dest);
}
unsigned int ft_strlen(char *str)
{
unsigned int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strdup(char *src)
{
char *dest;
dest = malloc(sizeof(*dest) * ft_strlen(src));
ft_strcpy(dest, src);
return (dest);
}
#include <stdio.h>
int main(void)
{
char str[] = "Bonjour";
printf("%c", ft_strdup(str)[8]);
}

Binary file not shown.

View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 18:54:20 by cchauvet #+# #+# */
/* Updated: 2022/08/01 17:19:30 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int *ft_range(int min, int max)
{
int i;
int *tab;
tab = NULL;
if (max <= min)
return (tab);
tab = malloc(sizeof(*tab) * (max - min + 1));
i = 0;
while (min + i < max)
{
*(tab + i) = min + i;
i++;
}
return (tab);
}
#include <stdio.h>
int main(void)
{
int i;
i = 0;
while (i < 6)
{
printf("%d", ft_range(4, 10)[i]);
i++;
}
}

Binary file not shown.

View File

@ -0,0 +1,50 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_range.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/22 10:33:24 by cchauvet #+# #+# */
/* Updated: 2022/08/01 17:27:36 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_ultimate_range(int **range, int min, int max)
{
int i;
*range = NULL;
if (max <= min)
return (0);
*range = malloc(sizeof(*range) * (max - min + 1));
i = 0;
while (min + i < max)
{
(*range)[i] = min + i;
i++;
}
return (max - min);
}
#include <stdio.h>
int main(void)
{
int temp1;
int *temp2;
int **tab;
temp1 = 0;
temp2 =&temp1;
tab = &temp2;
printf("%d", ft_ultimate_range(tab, 11, 10));
printf("\n");
for (int ind = 0; ind<10; ind++ )
{
printf("%i, ", (*tab)[ind]);
}
return (0);
}

Binary file not shown.

View File

@ -0,0 +1,76 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strjoin.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/24 13:29:37 by cchauvet #+# #+# */
/* Updated: 2022/08/01 17:29:11 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
j = 0;
i = 0;
while (dest[i] != 0)
i++;
while (src[j] != 0)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = 0;
return (dest);
}
char *ft_strjoin(int size, char **strs, char *sep)
{
int i;
int word_counter;
char *out;
if (size == 0)
{
out = malloc(sizeof(*out));
out = "";
return (out);
}
i = -1;
while (++i < size)
{
word_counter += ft_strlen(strs[i]);
word_counter += ft_strlen(sep);
}
out = malloc(sizeof(*out) * word_counter);
i = 0;
while (i < size)
{
ft_strcat(out, strs[i++]);
if (i < size)
ft_strcat(out, sep);
}
return (out);
}
#include <stdio.h>
int main(int argc, char **argv)
{
printf("%s", ft_strjoin(argc, argv, " "));
}

Binary file not shown.

View File

@ -0,0 +1,71 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_split.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/08/01 16:20:17 by cchauvet #+# #+# */
/* Updated: 2022/08/01 16:20:49 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
int ft_strstr(char *str, char *to_find)
{
unsigned int i;
unsigned int j;
i = 0;
while (str[i] != 0)
{
j = 0;
while (str[i + j] == to_find[j])
{
if (to_find[j + 1] == 0)
return (i);
j++;
}
i++;
}
return (i);
}
int ft_strlen(char *str)
{
int i;
i = 0;
while (str[i] != 0)
i++;
return (i);
}
char **ft_split(char *str, char *sep)
{
char **tab;
int i;
int j;
int k;
i = 0;
j = 0;
tab = malloc(sizeof(*str) * ft_strlen(str));
while (str[i] != 0 && ft_strlen(str) > i)
{
k = i;
tab[j] = malloc(sizeof(**tab) * (i - k + ft_strstr(&str[i], sep) + 1));
while (i < k + ft_strstr(&str[k], sep))
{
tab[j][i - k] = str[i];
i++;
}
tab[j][i - k] = '\0';
i = k + ft_strstr(&str[k], sep) + ft_strlen(sep);
j++;
}
tab[j] = malloc(sizeof(char));
tab[j] = "";
return (tab);
}

BIN
Correction/d/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:05:38 by lflandri #+# #+# */
/* Updated: 2022/07/20 13:05:39 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_factorial(int nb)
{
int n;
if (nb < 0)
return (0);
n = 1;
while (nb)
n = n * nb--;
return (n);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_factorial.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:17:09 by lflandri #+# #+# */
/* Updated: 2022/07/20 13:17:10 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_factorial(int nb)
{
if (nb < 0)
return (0);
else if (nb > 1)
return (nb * ft_recursive_factorial(nb - 1));
return (1);
}

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_iterative_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:25:45 by lflandri #+# #+# */
/* Updated: 2022/07/20 13:25:46 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_iterative_power(int nb, int power)
{
int stock;
stock = 1;
if (power < 0)
return (0);
while (power--)
stock = stock * nb;
return (stock);
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_recursive_power.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 16:44:43 by lflandri #+# #+# */
/* Updated: 2022/07/20 16:44:44 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_recursive_power(int nb, int p)
{
if (p > 0)
return (nb * ft_recursive_power(nb, p - 1));
if (p == 0)
return (1);
return (0);
}

View File

@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_fibonacci.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 17:16:27 by lflandri #+# #+# */
/* Updated: 2022/07/20 17:16:27 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_fibonacci(int index)
{
if (!(index))
return (0);
if (index < 0)
return (-1);
if (index == 1)
return (1);
return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2));
}

View File

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_sqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 19:03:04 by lflandri #+# #+# */
/* Updated: 2022/07/24 15:50:32 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_sqrt_bis(long int nb, int max, int min)
{
long int middle;
middle = (max - min) / 2 + min;
if (middle * middle == nb)
return (middle);
else if (min + 1 == max)
return (0);
else if (middle * middle > nb)
return (ft_sqrt_bis(nb, middle, min));
else
return (ft_sqrt_bis(nb, max, middle));
}
int ft_sqrt(int nb)
{
if (nb < 0)
return (0);
return (ft_sqrt_bis(nb, nb, 0));
}
#include <stdio.h>
#include <stdlib.h>
int main(int ac, char **av)
{
if (ac != 2)
return (0);
printf("%d", ft_sqrt(atoi(av[1])));
}

View File

@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_is_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 10:46:05 by lflandri #+# #+# */
/* Updated: 2022/07/21 10:46:06 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int ind;
if (nb <= 1)
return (0);
ind = 2;
while (ind < nb / 2)
{
if (!(nb % ind))
return (0);
ind++;
}
return (1);
}

View File

@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_find_next_prime.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 10:46:05 by lflandri #+# #+# */
/* Updated: 2022/07/21 14:42:31 by lflandri ### ########.fr */
/* */
/* ************************************************************************** */
int ft_is_prime(int nb)
{
int ind;
if (nb <= 1)
return (0);
ind = 2;
while (ind < nb / 2)
{
if (!(nb % ind))
return (0);
ind++;
}
return (1);
}
int ft_find_next_prime(int nb)
{
if (nb <= 2)
return (2);
if (!(nb % 2))
nb++;
while (1)
{
if (ft_is_prime(nb))
return (nb);
nb += 2;
}
}

View File

@ -0,0 +1,102 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ten_queens_puzzle.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lflandri <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 14:43:07 by lflandri #+# #+# */
/* Updated: 2022/07/24 16:26:44 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_recursive(int tab[10][10], char *solution, int rang);
int insert_d(int tab[10][10], char *solution, int rang, int ind)
{
int hauteur;
int rang_tempo;
rang_tempo = rang + 1;
hauteur = 1;
tab[rang][ind] = 2;
while (rang_tempo != 10)
{
tab[rang_tempo][ind] = 1;
if (ind - hauteur >= 0)
tab[rang_tempo][ind - hauteur] = 1;
if (ind + hauteur < 10)
tab[rang_tempo][ind + hauteur] = 1;
rang_tempo++;
hauteur++;
}
return (ft_recursive(tab, solution, rang + 1));
}
int cptab(int tab[10][10], char *solution, int rang, int ind)
{
int x;
int y;
int tab_copy[10][10];
x = 0;
while (x != 10)
{
y = -1;
while (++y != 10)
tab_copy[x][y] = tab[x][y];
x++;
}
return (insert_d(tab_copy, solution, rang, ind));
}
int ft_recursive(int tab[10][10], char *solution, int rang)
{
int ind;
int count;
count = 0;
ind = 0;
if (rang == 10)
{
write(1, solution, 11);
count++;
}
else
{
while (ind != 10)
{
if (!(tab[rang][ind]))
{
*(solution + rang) = ind + 48;
count += cptab(tab, solution, rang, ind);
}
ind++;
}
}
return (count);
}
int ft_ten_queens_puzzle(void)
{
int tab[10][10];
char solution[11];
int x;
int y;
x = 0;
while (x != 10)
{
y = -1;
while (++y != 10)
tab[x][y] = 0;
x++;
}
solution[10] = '\n';
return (ft_recursive(tab, solution, 0));
}
int main()

BIN
Correction/dfdgdf/a.out Executable file

Binary file not shown.

View File

@ -0,0 +1,23 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 13:44:45 by jmendez #+# #+# */
/* Updated: 2022/07/20 14:29:30 by jmendez ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strcmp(char *s1, char *s2)
{
int i;
i = 0;
while (s1[i] == s2[i] && (s1[i] && s2[i]))
i ++;
return (s1[i] - s2[i]);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 14:58:04 by jmendez #+# #+# */
/* Updated: 2022/07/20 15:00:50 by jmendez ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
unsigned int i;
i = 0;
while (i < n)
{
if (s1[i] != s2[i] || s1[i] == '\0' || s2[i] == '\0')
{
return (s1[i] - s2[i]);
}
i++;
}
return (0);
}

View File

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 20:57:39 by jmendez #+# #+# */
/* Updated: 2022/07/20 22:44:31 by jmendez ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
i = 0;
j = 0;
while (dest[i] != '\0')
i++;
while (src[j] != '\0')
{
dest[i] = src[j];
i++;
j++;
}
dest[i] = '\0';
return (dest);
}

View File

@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/20 22:47:28 by jmendez #+# #+# */
/* Updated: 2022/07/25 16:53:34 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncat(char *dest, char *src, unsigned int nb)
{
int i;
unsigned int j;
i = 0;
j = 0;
while (dest[i] != '\0')
i++;
while (j < nb)
{
dest[i] = src[j];
i++;
j++;
}
return (dest);
}
#include <string.h>
#include <stdio.h>
int main()
{
char a[] = "sss";
char b[] = "aaa";
char c[] = "aaa";
printf("%s", strncat(b, a, 5));
printf("\n%s", ft_strncat(c, a, 5));
}

View File

@ -0,0 +1,70 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 12:35:36 by jmendez #+# #+# */
/* Updated: 2022/07/25 16:56:29 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
char *ft_strstr(char *str, char *to_find)
{
int i;
int j;
i = 0;
j = 0;
if (to_find[j] == '\0')
return (str);
while (str[i] != '\0')
{
if (str[i] == to_find[j])
{
while (str[i] == to_find[j])
{
i++;
j++;
if (to_find[j] == '\0')
return (&str[i - j]);
}
i = i - j;
}
j = 0;
i++;
}
return (NULL);
}
#include <stdio.h>
#include <string.h>
int main (void) {
char haystack1[20] = "TutorialsPoint";
char needle1[10] = "Pint";
char *ret1;
ret1 = strstr(haystack1, needle1);
printf("The substring is: %s\n", ret1);
printf("\n");
char haystack2[20] = "TutorialsPoint";
char needle2[10] = "Pint";
char *ret2;
ret2 = ft_strstr(haystack2, needle2);
printf("The substring is: %s\n", ret2);
return(0);
}

View File

@ -0,0 +1,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmendez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/21 17:13:43 by jmendez #+# #+# */
/* Updated: 2022/07/25 17:00:32 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
int howmuch;
howmuch = 0;
while (*str++)
howmuch++;
return (howmuch);
}
unsigned int ft_strlcpy(char *dest, char *src, unsigned int size)
{
unsigned int i;
i = -1;
while (++i < size - 1 && src[i])
dest[i] = src[i];
dest[i + 1] = '\0';
return (i);
}
unsigned int ft_strlcat(char *dest, char *src, unsigned int size)
{
unsigned int length;
length = ft_strlen(dest);
if (length >= size)
length = size;
if (length == size)
return (length + ft_strlen(src));
return (length + ft_strlcpy(dest + length, src, size - length));
}
#include <stdio.h>
int main()
{
char src[] = "hello";
char dest2[10] = "fjff";
int j;
j = ft_strlcat(dest2, src, 7);
printf("%d %s\n", j, dest2);
}

View File

@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 15:22:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:33:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_ft(int *nbr)
{
*nbr = 42;
}

View File

@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_ft.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:27:16 by cchauvet #+# #+# */
/* Updated: 2022/07/14 18:53:31 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_ft(int *********nbr)
{
*********nbr = 42;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_swap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:46:50 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:51:16 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}

View File

@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 18:58:15 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:35:36 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_div_mod(int a, int b, int *div, int *mod)
{
*div = a / b;
*mod = a % b;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_ultimate_div_mod.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 10:37:49 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:38:35 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_ultimate_div_mod(int *a, int *b)
{
int c;
int d;
c = *a / *b;
d = *a % *b;
}

View File

@ -0,0 +1,20 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/14 19:18:13 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
while (*str != 0)
{
write(1, str++, 1);
}
}

View File

@ -0,0 +1,25 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/14 19:06:11 by cchauvet #+# #+# */
/* Updated: 2022/07/18 10:34:56 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
int ft_strlen(char *str)
{
int a;
a = 0;
while (*str != 0)
{
a++;
str++;
}
return (a);
}

View File

@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rev_int_tab.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/15 09:31:51 by cchauvet #+# #+# */
/* Updated: 2022/07/15 10:54:35 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
void ft_swap(int *a, int *b)
{
int tempo;
tempo = *a;
*a = *b;
*b = tempo;
}
void ft_rev_int_tab(int *tab, int size)
{
int i;
i = 0;
while (i < size / 2)
{
ft_swap(tab + i, tab + size - i - 1);
i++;
}
}

View File

@ -0,0 +1,46 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 12:59:45 by cchauvet #+# #+# */
/* Updated: 2022/07/21 16:20:06 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strcmp(char *s1, char *s2)
{
while ((*s1 != 0) && (*s2 != 0) && (*s1 == *s2))
{
s1++;
s2++;
}
return (*s1 - *s2);
}
#include <stdio.h>
#include <string.h>
int main()
{
char src1[] = "dddd";
char dest1[8] = "dddid";
int result1;
result1 = strcmp(dest1, src1);
printf("%d", result1);
printf("\n");
char src2[] = "dddd";
char dest2[8] = "dddid";
int result2;
result2 = ft_strcmp(dest2, src2);
printf("%d", result2);
return 0;
}

View File

@ -0,0 +1,45 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 13:17:50 by cchauvet #+# #+# */
/* Updated: 2022/07/21 12:57:14 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
int i;
i = 0;
while (s1[i] != 0 && s2[i] != 0 && s1[i] == s2[i] && i < n - 1)
i++;
return (s1[i] - s2[i]);
}
#include <stdio.h>
#include <string.h>
int main()
{
char src1[] = "dddd";
char dest1[8] = "ddde";
int result1;
result1 = strncmp(dest1, src1, 5);
printf("%d", result1);
printf("\n");
char src2[] = "dddd";
char dest2[8] = "ddde";
int result2;
result2 = ft_strncmp(dest2, src2, 5);
printf("%d", result2);
return 0;
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 13:43:42 by cchauvet #+# #+# */
/* Updated: 2022/07/21 12:59:50 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcat(char *dest, char *src)
{
int i;
int j;
i = 0;
while (dest[i] != 0)
i++;
j = 0;
while (src[j] != 0)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000;
return (dest);
}

View File

@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 19:02:00 by cchauvet #+# #+# */
/* Updated: 2022/07/21 13:00:52 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncat(char *dest, char *src, unsigned int nb)
{
int i;
int j;
i = 0;
while (dest[i] != 0)
i++;
j = 0;
while (src[j] != 0 && j < nb)
{
dest[i + j] = src[j];
j++;
}
dest[i + j] = 0;
return (dest);
}

View File

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cchauvet <cchauvet@student.42angoulem +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/18 19:04:42 by cchauvet #+# #+# */
/* Updated: 2022/07/21 13:01:47 by cchauvet ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strstr(char *str, char *tofind)
{
int i;
int j;
i = 0;
while (str[i] != 0)
{
j = 0;
while (str[i + j] == tofind[j])
{
if (tofind[j] == 0)
return (&str[i]);
j++;
}
i++;
}
return (0);
}

Some files were not shown because too many files have changed in this diff Show More