first commit
This commit is contained in:
32
ended/C07/ex00/ft_strdup.c
Normal file
32
ended/C07/ex00/ft_strdup.c
Normal file
@ -0,0 +1,32 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/07/28 18:42:08 by ajoly #+# #+# */
|
||||
/* Updated: 2022/08/04 09:17:22 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strdup(char *src)
|
||||
{
|
||||
int i;
|
||||
char *dest;
|
||||
|
||||
i = 0;
|
||||
while (src[i])
|
||||
i++;
|
||||
dest = malloc(i);
|
||||
i = 0;
|
||||
while (src[i])
|
||||
{
|
||||
dest[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
36
ended/C07/ex01/ft_range.c
Normal file
36
ended/C07/ex01/ft_range.c
Normal file
@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/01 15:14:57 by ajoly #+# #+# */
|
||||
/* Updated: 2022/08/04 12:52:11 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *result;
|
||||
int diff;
|
||||
|
||||
diff = max - min;
|
||||
result = malloc((diff + 1) * sizeof(int));
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
result = NULL;
|
||||
return (result);
|
||||
}
|
||||
while (min < max)
|
||||
{
|
||||
result[i] = min;
|
||||
i++;
|
||||
min++;
|
||||
}
|
||||
return (result);
|
||||
}
|
37
ended/C07/ex02/ft_ultimate_range.c
Normal file
37
ended/C07/ex02/ft_ultimate_range.c
Normal file
@ -0,0 +1,37 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/02 21:00:29 by ajoly #+# #+# */
|
||||
/* Updated: 2022/08/03 14:55:34 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
int i;
|
||||
int *result;
|
||||
int diff;
|
||||
|
||||
diff = max - min;
|
||||
result = malloc((diff + 1) * sizeof(int));
|
||||
i = 0;
|
||||
if (min >= max)
|
||||
{
|
||||
*range = NULL;
|
||||
return (0);
|
||||
}
|
||||
while (min < max)
|
||||
{
|
||||
result[i] = min;
|
||||
i++;
|
||||
min++;
|
||||
}
|
||||
*range = result;
|
||||
return (i);
|
||||
}
|
73
ended/C07/ex03/ft_strjoin.c
Normal file
73
ended/C07/ex03/ft_strjoin.c
Normal file
@ -0,0 +1,73 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: ajoly <ajoly@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/08/03 09:24:30 by ajoly #+# #+# */
|
||||
/* Updated: 2022/08/04 11:16:46 by ajoly ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
int i;
|
||||
int l;
|
||||
|
||||
i = 0;
|
||||
l = 0;
|
||||
while (dest[i] != '\0')
|
||||
i++;
|
||||
while (src[l] != '\0')
|
||||
{
|
||||
dest[i] = src[l];
|
||||
i++;
|
||||
l++;
|
||||
}
|
||||
dest[i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i] != '\0')
|
||||
{
|
||||
i++;
|
||||
}
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strjoin(int size, char **strs, char *sep)
|
||||
{
|
||||
int i;
|
||||
char *result;
|
||||
int len;
|
||||
|
||||
i = -1;
|
||||
len = ft_strlen(sep) * (size - 1);
|
||||
while (++i < size)
|
||||
len = len + ft_strlen(strs[i]);
|
||||
if (size == 0)
|
||||
{
|
||||
result = malloc(sizeof(char));
|
||||
*result = 0;
|
||||
return (result);
|
||||
}
|
||||
i = 0;
|
||||
result = malloc(len);
|
||||
while (i < size)
|
||||
{
|
||||
ft_strcat(result, strs[i]);
|
||||
if (i < size - 1)
|
||||
ft_strcat(result, sep);
|
||||
i++;
|
||||
}
|
||||
result[len] = '\0';
|
||||
return (result);
|
||||
}
|
Reference in New Issue
Block a user