init
This commit is contained in:
BIN
Correction/C_07ma/a.out
Executable file
BIN
Correction/C_07ma/a.out
Executable file
Binary file not shown.
54
Correction/C_07ma/ex00/ft_strdup.c
Normal file
54
Correction/C_07ma/ex00/ft_strdup.c
Normal 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
BIN
Correction/C_07ma/ex01/a.out
Executable file
Binary file not shown.
55
Correction/C_07ma/ex01/ft_range.c
Normal file
55
Correction/C_07ma/ex01/ft_range.c
Normal 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
BIN
Correction/C_07ma/ex02/a.out
Executable file
Binary file not shown.
50
Correction/C_07ma/ex02/ft_ultimate_range.c
Normal file
50
Correction/C_07ma/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/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
BIN
Correction/C_07ma/ex03/a.out
Executable file
Binary file not shown.
77
Correction/C_07ma/ex03/ft_strjoin.c
Normal file
77
Correction/C_07ma/ex03/ft_strjoin.c
Normal 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);
|
||||
}
|
BIN
Correction/C_07ma/ex04/.ft_split.c.swp
Normal file
BIN
Correction/C_07ma/ex04/.ft_split.c.swp
Normal file
Binary file not shown.
Reference in New Issue
Block a user