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

21
C_04/git/ex00/ft_strlen.c Normal file
View File

@@ -0,0 +1,21 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_strlen.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:03:26 by gbaconni #+# #+# */
/* Updated: 2021/08/13 09:09:57 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_strlen(char *str)
{
char *p_str;
p_str = str;
while (*p_str != '\0')
p_str++;
return (p_str - str);
}

32
C_04/git/ex00/main.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:02:59 by gbaconni #+# #+# */
/* Updated: 2021/08/13 09:03:17 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_strlen(char *str);
int main(void)
{
char str[32];
int result;
printf("Input String [max 31]: ");
scanf("%s", str);
result = ft_strlen(str);
printf("str=%s result=%d (ft_strlen)\n", str, result);
result = strlen(str);
printf("str=%s result=%d (strlen)\n", str, result);
return (0);
}

8
C_04/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

22
C_04/git/ex01/ft_putstr.c Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putstr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:16:54 by gbaconni #+# #+# */
/* Updated: 2021/08/13 09:21:15 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putstr(char *str)
{
char *p_str;
p_str = str;
while (*p_str != '\0')
write(1, p_str++, 1);
}

30
C_04/git/ex01/main.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:13:32 by gbaconni #+# #+# */
/* Updated: 2021/08/13 09:20:53 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void ft_putstr(char *str);
int main(void)
{
char str[32];
printf("Input String [max 31]: ");
scanf("%s", str);
ft_putstr(str);
write(1, "\n", 1);
printf("str=%s (ft_putstr)\n", str);
return (0);
}

8
C_04/git/ex01/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

40
C_04/git/ex02/ft_putnbr.c Normal file
View File

@@ -0,0 +1,40 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:24:02 by gbaconni #+# #+# */
/* Updated: 2021/08/16 13:26:12 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdio.h>
void ft_putnbr(int nb)
{
char c;
if (nb < 0)
{
nb *= -1;
write(1, "-", 1);
}
if (nb >= 0 && nb <= 9)
{
c = nb + '0';
write(1, &c, 1);
}
else if (nb == -2147483648)
{
ft_putnbr((nb / 10) * -1);
ft_putnbr((nb % 10) * -1);
}
else
{
ft_putnbr(nb / 10);
ft_putnbr(nb % 10);
}
}

30
C_04/git/ex02/main.c Normal file
View File

@@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 09:22:26 by gbaconni #+# #+# */
/* Updated: 2021/08/13 11:18:57 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void ft_putnbr(int nb);
int main(void)
{
int nb;
printf("Input Number: ");
scanf("%d", &nb);
ft_putnbr(nb);
write(1, "\n", 1);
printf("nb=%d (ft_putnbr)\n", nb);
return (0);
}

8
C_04/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

37
C_04/git/ex03/ft_atoi.c Normal file
View File

@@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 12:46:22 by gbaconni #+# #+# */
/* Updated: 2021/08/16 13:49:34 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int nb;
int s;
int i;
nb = 0;
s = 1;
i = 0;
while (str[i] != '\0' && (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
i++;
while (str[i] != '\0')
{
if (str[i] == '+')
s += 0;
else if (str[i] == '-')
s *= -1;
else if (str[i] >= '0' && str[i] <= '9')
nb = nb * 10 + str[i] - '0';
else
break ;
i++;
}
return (nb * s);
}

32
C_04/git/ex03/main.c Normal file
View File

@@ -0,0 +1,32 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/13 12:46:41 by gbaconni #+# #+# */
/* Updated: 2021/08/16 13:44:04 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_atoi(char *str);
int main(void)
{
char str[32];
int result;
printf("Input String [31]: ");
scanf("%s", str);
result = ft_atoi(str);
printf("str=%s result=%d (ft_atoi)\n", str, result);
result = atoi(str);
printf("str=%s result=%d (atoi)\n", str, result);
return (0);
}

8
C_04/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

View File

@@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/16 13:51:16 by gbaconni #+# #+# */
/* Updated: 2021/08/16 14:25:07 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
#include <stdio.h>
void ft_putnbr_base(int nbr, char *base)
{
int size;
size = 0;
while (base[++size] != '\0')
continue ;
if (nbr < 0)
{
nbr *= -1;
write(1, "-", 1);
}
if (nbr >= 0 && nbr < size)
{
write(1, base + nbr, 1);
}
else if (nbr == -2147483648)
{
ft_putnbr_base((nbr / size) * -1, base);
ft_putnbr_base((nbr % size) * -1, base);
}
else
{
ft_putnbr_base(nbr / size, base);
ft_putnbr_base(nbr % size, base);
}
}

33
C_04/git/ex04/main.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/16 13:53:07 by gbaconni #+# #+# */
/* Updated: 2021/08/16 13:55:59 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
void ft_putnbr_base(int nbr, char *base);
int main(void)
{
char base[32];
int nb;
printf("Input Number: ");
scanf("%d", &nb);
printf("Input Base [31]: ");
scanf("%s", base);
ft_putnbr_base(nb, base);
write(1, "\n", 1);
printf("nb=%d base=%s (ft_putnbr_base)\n", nb, base);
return (0);
}

8
C_04/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,57 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_base.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/16 13:53:46 by gbaconni #+# #+# */
/* Updated: 2021/08/16 15:05:08 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
static int ft_strlen(char *str)
{
int size;
size = 0;
while (str[++size] != '\0')
continue ;
return (size);
}
static int ft_nbase(char c, char *base)
{
int n;
n = 0;
while (base[n] != '\0' && base[n] != c)
n++;
return (n);
}
int ft_atoi_base(char *str, char *base)
{
int nb;
int s;
int i;
int size;
size = ft_strlen(base);
nb = 0;
s = 1;
i = 0;
while (str[i] != '\0' && (str[i] == ' ' || (str[i] >= '\t' && str[i] <= '\r')))
i++;
while (str[i] != '\0')
{
if (str[i] == '+')
s += 0;
else if (str[i] == '-')
s *= -1;
else
nb = nb * size + ft_nbase(str[i], base);
i++;
}
return (nb * s);
}

33
C_04/git/ex05/main.c Normal file
View File

@@ -0,0 +1,33 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbaconni <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/16 13:53:58 by gbaconni #+# #+# */
/* Updated: 2021/08/16 13:55:18 by gbaconni ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
int ft_atoi_base(char *str, char *base);
int main(void)
{
char str[32];
char base[32];
int result;
printf("Input String [31]: ");
scanf("%s", str);
printf("Input Base [31]: ");
scanf("%s", base);
result = ft_atoi_base(str, base);
printf("str=%s base=%s result=%d (ft_atoi_base)\n", str, base, result);
return (0);
}

8
C_04/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

12
C_04/git/tests_C04/ex00.c Normal file
View File

@@ -0,0 +1,12 @@
#include <stdio.h>
#include "../ex00/ft_strlen.c"
int main(void)
{
char *a = "12345678";
char b[1];
b[0] = 0;
printf("Test\nexpected : 8 | result : %d\n", ft_strlen(a));
printf("Test\nexpected : 0 | result : %d\n", ft_strlen(b));
}

15
C_04/git/tests_C04/ex01.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include "../ex01/ft_putstr.c"
int main(void)
{
char b[1];
char *a = "12345678";
b[0] = 0;
printf("\nTest\nexpected : %s | result : \n", a);
ft_putstr(a);
printf("\nTest\nexpected : %s | result : \n", b);
ft_putstr(b);
printf("\n");
}

15
C_04/git/tests_C04/ex02.c Normal file
View File

@@ -0,0 +1,15 @@
#include <stdio.h>
#include "../ex02/ft_putnbr.c"
int main(void)
{
printf("\nTest\nexpected : 1230234 | result : \n");
ft_putnbr(1230234);
printf("\nTest\nexpected : 0 | result : \n");
ft_putnbr(0);
printf("\nTest\nexpected : -253 | result : \n");
ft_putnbr(-253);
printf("\nTest\nexpected : -2147483648 | result : \n");
ft_putnbr(-2147483648);
printf("\n");
}

17
C_04/git/tests_C04/ex03.c Normal file
View File

@@ -0,0 +1,17 @@
#include <stdio.h>
#include "../ex03/ft_atoi.c"
int main(void)
{
char a[] = " \n \r \v +---+-+-42";
char b[] = " \n --+37523093";
char c[] = " 0";
char d[] = " \f \t -+2147483648";
char e[] = " \f\f asd345";
printf("Test\nexpected : -42 | result : %d\n", ft_atoi(a));
printf("Test\nexpected : 37523093 | result : %d\n", ft_atoi(b));
printf("Test\nexpected : 0 | result : %d\n", ft_atoi(c));
printf("Test\nexpected : -2147483648 | result : %d\n", ft_atoi(d));
printf("Test\nexpected : 0 | result : %d\n", ft_atoi(e));
}

31
C_04/git/tests_C04/ex04.c Normal file
View File

@@ -0,0 +1,31 @@
#include <stdio.h>
#include "../ex04/ft_putnbr_base.c"
int main(void)
{
char poney[] = "poneyvif";
char deci[] = "0123456789";
char hexa[] = "0123456789abcdef";
char bin[] = "01";
char strange[] = "102310";
char strange2[] = "1234+56";
char strange3[] = "";
printf("\nTest\nexpected : 128 | result : \n");
ft_putnbr_base(128, deci);
printf("\nTest\nexpected : -2b | result : \n");
ft_putnbr_base(-43, hexa);
printf("\nTest\nexpected : -80000000 | result : \n");
ft_putnbr_base(-2147483648, hexa);
printf("\nTest\nexpected : 1101 | result : \n");
ft_putnbr_base(13, bin);
printf("\nTest\nexpected : opoooyyf | result : \n");
ft_putnbr_base(2134823, poney);
printf("\nTest\nexpected : | result : \n");
ft_putnbr_base(2134823, strange);
printf("\nTest\nexpected : | result : \n");
ft_putnbr_base(4325, strange2);
printf("\nTest\nexpected : | result : \n");
ft_putnbr_base(21348, strange3);
printf("\n");
}

43
C_04/git/tests_C04/ex05.c Normal file
View File

@@ -0,0 +1,43 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ex05.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tkondrac <tkondrac@student.42lausan> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/08/11 14:32:06 by tkondrac #+# #+# */
/* Updated: 2021/08/11 17:34:21 by tkondrac ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include "../ex05/ft_atoi_base.c"
int main(void)
{
char a[] = " \n \r \v +---+-+-42";
char b[] = " \n --+2b";
char c[] = " 0";
char d[] = " \f \t -+2147483648";
char e[] = " \f\f asd345";
char f[] = " \f\f poneyvif";
char g[] = " \f\f -0123456789";
char poney[] = "poneyvif";
char deci[] = "0123456789";
char hexa[] = "0123456789abcdef";
char bin[] = "01";
char strange[] = "1b231b";
// char strange2[] = "1234+56";
// char strange3[] = "";
printf("Test\nexpected : -42 | result : %d\n", ft_atoi_base(a, deci));
printf("Test\nexpected : 43 | result : %d\n", ft_atoi_base(b, hexa));
printf("Test\nexpected : 0 | result : %d\n", ft_atoi_base(c, bin));
printf("Test\nexpected : -2147483648 | result : %d\n", ft_atoi_base(d, deci));
printf("Test\nexpected : 0 | result : %d\n", ft_atoi_base(e, deci));
printf("Test\nexpected : 2 | result : %d\n", ft_atoi_base(b, deci));
printf("Test\nexpected : 342391 | result : %d\n", ft_atoi_base(f, poney));
printf("Test\nexpected : -123456789 | result : %d\n", ft_atoi_base(g, deci));
printf("Test\nexpected : 0 | result : %d\n", ft_atoi_base(a, strange));
}

8
C_04/git/tests_C04/main.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
test=$1
set -e
norminette -R CheckForbiddenSourceHeader ../$test/ft_*.c
gcc -Wall -Wextra -Werror -o a.out $test.c
#gcc -o a.out $test.c
./a.out
rm -f a.out