init
This commit is contained in:
51
Correction/cc/ex00/ft_strdup.c
Normal file
51
Correction/cc/ex00/ft_strdup.c
Normal 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()
|
||||
}
|
31
Correction/cc/ex01/ft_range.c
Normal file
31
Correction/cc/ex01/ft_range.c
Normal 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);
|
||||
}
|
30
Correction/cc/ex02/ft_ultimate_range.c
Normal file
30
Correction/cc/ex02/ft_ultimate_range.c
Normal 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);
|
||||
}
|
70
Correction/cc/ex03/ft_strjoin.c
Normal file
70
Correction/cc/ex03/ft_strjoin.c
Normal 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);
|
||||
}
|
71
Correction/cc/ex05/ft_split.c
Normal file
71
Correction/cc/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