0
0
This commit is contained in:
Guy Baconniere
2021-08-20 10:02:38 +02:00
parent 5aa02c94b5
commit d30270c485
354 changed files with 0 additions and 0 deletions

28
C_03/git/ex00/ft_strcmp.c Normal file
View File

@@ -0,0 +1,28 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 12:14:57 by gbaconni #+# #+# */
/* Updated: 2021/08/12 14:50:37 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strcmp(char *s1, char *s2)
{
char c1;
char c2;
c1 = '\0';
c2 = '\0';
while (c1 == c2)
{
c1 = *s1++;
c2 = *s2++;
if (c1 == '\0')
break ;
}
return (c1 - c2);
}

35
C_03/git/ex00/main.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 12:15:09 by gbaconni #+# #+# */
/* Updated: 2021/08/12 12:28:31 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_strcmp(char *s1, char *s2);
int main(void)
{
char s1[32];
char s2[32];
int result;
printf("Input String #1 [max 31]: ");
scanf("%s", s1);
printf("Input String #2 [max 31]: ");
scanf("%s", s2);
result = ft_strcmp(s1, s2);
printf("s1=%s s2=%s result=%d (ft_strcmp)\n", s1, s2, result);
result = strcmp(s1, s2);
printf("s1=%s s2=%s result=%d (strcmp)\n", s1, s2, result);
return (0);
}

8
C_03/git/ex00/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out

View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncmp.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:16:07 by gbaconni #+# #+# */
/* Updated: 2021/08/18 11:35:55 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strncmp(char *s1, char *s2, unsigned int n)
{
char c1;
char c2;
if (n == 0)
return (0);
c1 = '\0';
c2 = '\0';
while (n > 0)
{
c1 = *s1++;
c2 = *s2++;
if (c1 == '\0' || c1 != c2)
break ;
n--;
}
return (c1 - c2);
}

39
C_03/git/ex01/main.c Normal file
View File

@@ -0,0 +1,39 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:16:20 by gbaconni #+# #+# */
/* Updated: 2021/08/12 15:16:21 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_strncmp(char *s1, char *s2, unsigned int n);
int main(void)
{
char s1[32];
char s2[32];
unsigned int n;
int result;
n = 0;
printf("Input String #1 [max 31]: ");
scanf("%s", s1);
printf("Input String #2 [max 31]: ");
scanf("%s", s2);
printf("Input Number: ");
scanf("%u", &n);
result = ft_strncmp(s1, s2, n);
printf("s1=%s s2=%s n=%d result=%d (ft_strncmp)\n", s1, s2, n, result);
result = strncmp(s1, s2, n);
printf("s1=%s s2=%s n=%d result=%d (strncmp)\n", s1, s2, n, result);
return (0);
}

8
C_03/git/ex01/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader ft_strncmp.c
gcc -Wall -Wextra -Werror -o a.out ft_strncmp.c main.c
echo $(basename $PWD):
./a.out
rm -f a.out

26
C_03/git/ex02/ft_strcat.c Normal file
View File

@@ -0,0 +1,26 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 16:01:50 by gbaconni #+# #+# */
/* Updated: 2021/08/12 16:37:01 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strcat(char *dest, char *src)
{
char *s1;
char *s2;
s1 = dest;
s2 = src;
while (*s1 != '\0')
s1++;
while (*s2 != '\0')
*s1++ = *s2++;
*s1 = '\0';
return (dest);
}

37
C_03/git/ex02/main.c Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:28:30 by gbaconni #+# #+# */
/* Updated: 2021/08/12 15:49:44 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
char *ft_strcat(char *dest, char *src);
int main(void)
{
char src[32];
char dest[32];
char dest2[32];
char *result;
printf("Input String #1 [max 31]: ");
scanf("%s", src);
printf("Input String #2 [max 31]: ");
scanf("%s", dest);
strcpy(dest2, dest);
result = ft_strcat(dest, src);
printf("src=%s dest=%s result=%s (ft_strcat)\n", src, dest, result);
result = strcat(dest2, src);
printf("src=%s dest=%s result=%s (strcat)\n", src, dest2, result);
return (0);
}

8
C_03/git/ex02/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out

View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strncat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 16:43:59 by gbaconni #+# #+# */
/* Updated: 2021/08/12 16:47:35 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
char *ft_strncat(char *dest, char *src, unsigned int nb)
{
char *s1;
char *s2;
s1 = dest;
s2 = src;
while (*s1 != '\0')
s1++;
while (nb > 0 && *s2 != '\0')
{
*s1++ = *s2++;
nb--;
}
*s1 = '\0';
return (dest);
}

41
C_03/git/ex03/main.c Normal file
View File

@@ -0,0 +1,41 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 16:21:11 by gbaconni #+# #+# */
/* Updated: 2021/08/12 16:44:38 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
char *ft_strncat(char *dest, char *src, unsigned int nb);
int main(void)
{
char src[32];
char dest[32];
char dest2[32];
unsigned int nb;
char *r;
nb = 0;
printf("Input String #1 [max 31]: ");
scanf("%s", src);
printf("Input String #2 [max 31]: ");
scanf("%s", dest);
printf("Input Number: ");
scanf("%u", &nb);
strcpy(dest2, dest);
r = ft_strncat(dest, src, nb);
printf("src=%s dest=%s nb=%d result=%s (ft_strncat)\n", src, dest, nb, r);
r = strncat(dest2, src, nb);
printf("src=%s dest=%s nb=%d result=%s (strncat)\n", src, dest2, nb, r);
return (0);
}

8
C_03/git/ex03/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out

31
C_03/git/ex04/ft_strstr.c Normal file
View File

@@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 16:49:31 by gbaconni #+# #+# */
/* Updated: 2021/08/12 17:11:14 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdlib.h>
char *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] != '\0' && str[i + j] == to_find[j])
j++;
if (to_find[j] == '\0')
return (str + i);
i++;
}
return (NULL);
}

35
C_03/git/ex04/main.c Normal file
View File

@@ -0,0 +1,35 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 16:49:41 by gbaconni #+# #+# */
/* Updated: 2021/08/12 17:07:20 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
char *ft_strstr(char *str, char *to_find);
int main(void)
{
char str[32];
char to_find[32];
char *r;
printf("Input String #1 [max 31]: ");
scanf("%s", str);
printf("Input String #2 [max 31]: ");
scanf("%s", to_find);
r = ft_strstr(str, to_find);
printf("str=%s to_find=%s result=%s (ft_strstr)\n", str, to_find, r);
r = strstr(str, to_find);
printf("str=%s to_find=%s result=%s (strstr)\n", str, to_find, r);
return (0);
}

8
C_03/git/ex04/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out

View File

@@ -0,0 +1,36 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlcat.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 17:12:30 by gbaconni #+# #+# */
/* Updated: 2021/08/12 17:48:17 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
unsigned int ft_strlcat(char *dest, char *src, unsigned int size)
{
char *s1;
char *s2;
unsigned int size_dest;
s1 = dest;
s2 = src;
size_dest = 0;
while (*s1 != '\0')
s1++;
size_dest = s1 - dest;
while (*s2 != '\0')
{
if (size != 1)
{
*s1++ = *s2++;
size--;
}
s2++;
}
*s1 = '\0';
return (size_dest + (s2 - src));
}

40
C_03/git/ex05/main.c Normal file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/12 15:28:30 by gbaconni #+# #+# */
/* Updated: 2021/08/12 17:22:10 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
unsigned int ft_strlcat(char *dest, char *src, unsigned int size);
int main(void)
{
char src[32];
char dest[32];
unsigned int size;
unsigned int r;
size = 0;
r = 0;
printf("Input String #1 [max 31]: ");
scanf("%s", src);
printf("Input String #2 [max 31]: ");
scanf("%s", dest);
printf("Input Number: ");
scanf("%u", &size);
r = ft_strlcat(dest, src, size);
printf("src=%s dest=%s size=%d r=%d (ft_strlcat)\n", src, dest, size, r);
r = strlcat(dest, src, size);
printf("src=%s dest=%s size=%d r=%d (strlcat)\n", src, dest, size, r);
return (0);
}

8
C_03/git/ex05/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
set -e
#norminette -R CheckForbiddenSourceHeader ft_*.c
norminette -R CheckForbiddenSourceHeader
gcc -Wall -Wextra -Werror -o a.out *.c
echo $(basename $PWD):
./a.out
rm -f a.out