init
This commit is contained in:
BIN
Correction/correctionc07/ex00/a.out
Executable file
BIN
Correction/correctionc07/ex00/a.out
Executable file
Binary file not shown.
52
Correction/correctionc07/ex00/ft_strdup.c
Normal file
52
Correction/correctionc07/ex00/ft_strdup.c
Normal 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]);
|
||||
}
|
BIN
Correction/correctionc07/ex01/a.out
Executable file
BIN
Correction/correctionc07/ex01/a.out
Executable file
Binary file not shown.
43
Correction/correctionc07/ex01/ft_range.c
Normal file
43
Correction/correctionc07/ex01/ft_range.c
Normal 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++;
|
||||
}
|
||||
}
|
BIN
Correction/correctionc07/ex02/a.out
Executable file
BIN
Correction/correctionc07/ex02/a.out
Executable file
Binary file not shown.
50
Correction/correctionc07/ex02/ft_ultimate_range.c
Normal file
50
Correction/correctionc07/ex02/ft_ultimate_range.c
Normal 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);
|
||||
}
|
BIN
Correction/correctionc07/ex03/a.out
Executable file
BIN
Correction/correctionc07/ex03/a.out
Executable file
Binary file not shown.
76
Correction/correctionc07/ex03/ft_strjoin.c
Normal file
76
Correction/correctionc07/ex03/ft_strjoin.c
Normal 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, " "));
|
||||
}
|
BIN
Correction/correctionc07/ex04/.ft_split.c.swp
Normal file
BIN
Correction/correctionc07/ex04/.ft_split.c.swp
Normal file
Binary file not shown.
71
Correction/correctionc07/ex05/ft_split.c
Normal file
71
Correction/correctionc07/ex05/ft_split.c
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user