mirror of
https://github.com/Ladebeze66/Piscine42.git
synced 2026-11-09 13:17:16 +01:00
Piscine42
This commit is contained in:
43
C07/ex00/ft_strdup.c
Executable file
43
C07/ex00/ft_strdup.c
Executable file
@@ -0,0 +1,43 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strdup.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/14 13:53:46 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/18 08:21:14 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strdup(char *src)
|
||||
{
|
||||
char *copy;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
copy = (char *) malloc(sizeof(char) * (ft_strlen(src) + 1));
|
||||
if (copy == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
while (src [i])
|
||||
{
|
||||
copy[i] = src[i];
|
||||
i++;
|
||||
}
|
||||
copy[i] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
36
C07/ex01/ft_range.c
Executable file
36
C07/ex01/ft_range.c
Executable file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/14 16:38:46 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/15 10:05:03 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int *tab;
|
||||
int i;
|
||||
|
||||
if (min >= max)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
tab = (int *) malloc(sizeof(int) * (max - min));
|
||||
if (tab == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i = 0;
|
||||
while (i < max - min)
|
||||
{
|
||||
tab[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
54
C07/ex02/ft_ultimate_range.c
Executable file
54
C07/ex02/ft_ultimate_range.c
Executable file
@@ -0,0 +1,54 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_ultimate_range.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/14 17:31:36 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/15 10:48:55 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int *ft_range(int min, int max)
|
||||
{
|
||||
int *tab;
|
||||
int i;
|
||||
|
||||
if (min >= max)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
tab = (int *) malloc(sizeof(int) * (max - min));
|
||||
if (tab == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
i = 0;
|
||||
while (i < max - min)
|
||||
{
|
||||
tab[i] = min + i;
|
||||
i++;
|
||||
}
|
||||
return (tab);
|
||||
}
|
||||
|
||||
int ft_ultimate_range(int **range, int min, int max)
|
||||
{
|
||||
if (min >= max)
|
||||
{
|
||||
*range = 0;
|
||||
return (0);
|
||||
}
|
||||
else
|
||||
{
|
||||
*range = ft_range(min, max);
|
||||
if (*range == 0)
|
||||
{
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
return (max - min);
|
||||
}
|
||||
88
C07/ex03/ft_strjoin.c
Executable file
88
C07/ex03/ft_strjoin.c
Executable file
@@ -0,0 +1,88 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strjoin.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 10:50:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2022/12/18 11:45:43 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (str[i])
|
||||
i++;
|
||||
return (i);
|
||||
}
|
||||
|
||||
char *ft_strcat(char *dest, char *src)
|
||||
{
|
||||
int i;
|
||||
int dest_len;
|
||||
|
||||
i = 0;
|
||||
dest_len = ft_strlen(dest);
|
||||
while (src[i] != '\0')
|
||||
{
|
||||
dest[dest_len + i] = src[i];
|
||||
i++;
|
||||
}
|
||||
dest[dest_len + i] = '\0';
|
||||
return (dest);
|
||||
}
|
||||
|
||||
int malloc_size(int size, char **strs, char *sep)
|
||||
{
|
||||
int i;
|
||||
int resultat;
|
||||
|
||||
if (size == 0)
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
i = 0;
|
||||
resultat = 0;
|
||||
while (i < size)
|
||||
{
|
||||
resultat += ft_strlen(strs[i]);
|
||||
i++;
|
||||
}
|
||||
resultat += ft_strlen(sep) * (size - 1);
|
||||
return (resultat + 1);
|
||||
}
|
||||
|
||||
char *ft_strjoin(int size, char **strs, char *sep)
|
||||
{
|
||||
char *resultat;
|
||||
int i;
|
||||
|
||||
resultat = malloc((sizeof(char)) * malloc_size(size, strs, sep));
|
||||
if (resultat == 0)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
resultat[0] = 0;
|
||||
if (size == 0)
|
||||
{
|
||||
return (resultat);
|
||||
}
|
||||
i = 0;
|
||||
while (i < size)
|
||||
{
|
||||
ft_strcat(resultat, strs[i]);
|
||||
if (i != size -1)
|
||||
{
|
||||
ft_strcat(resultat, sep);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
resultat[ft_strlen(resultat)] = '\0';
|
||||
return (resultat);
|
||||
}
|
||||
BIN
C07/fr.subject.pdf
Normal file
BIN
C07/fr.subject.pdf
Normal file
Binary file not shown.
Reference in New Issue
Block a user