sync
This commit is contained in:
89
Rush_02/rush-02/ex00/Makefile
Normal file
89
Rush_02/rush-02/ex00/Makefile
Normal file
@@ -0,0 +1,89 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2021/08/21 11:01:00 by gbaconni #+# #+# #
|
||||
# Updated: 2021/08/21 18:07:23 by gbaconni ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
#
|
||||
# make rush-02
|
||||
# make fclean
|
||||
# make
|
||||
#
|
||||
|
||||
NAME = "rush-02"
|
||||
|
||||
DICT = "numbers.dict"
|
||||
|
||||
SRC = rush-02.c
|
||||
|
||||
HDR = ft/ft.h
|
||||
|
||||
CC = cc
|
||||
CFLAGS = -Wall -Wextra -Werror
|
||||
AR = ar
|
||||
ARFLAGS = -cvq
|
||||
|
||||
FTDIR = ft
|
||||
FTLIB = ft
|
||||
|
||||
all: $(NAME)
|
||||
@echo "That's all Forks!"
|
||||
|
||||
$(NAME): compile
|
||||
|
||||
clean:
|
||||
@echo "Cleanning all objects"
|
||||
@/bin/rm -f *.o **/*.o
|
||||
@/bin/rm -f *.a **/*.a
|
||||
|
||||
fclean: clean
|
||||
@echo "Cleanning $(NAME)"
|
||||
@/bin/rm -f "$(NAME)"
|
||||
|
||||
re: fclean all
|
||||
|
||||
norminette:
|
||||
@norminette -R CheckDefine **/*.h
|
||||
@norminette -R CheckForbiddenSourceHeader **/*.c
|
||||
|
||||
macro:
|
||||
@cpp $(SRC)
|
||||
|
||||
compile-ft:
|
||||
@echo "Compiling $(FTLIB)"
|
||||
@cd ft && $(CC) $(CFLAGS) -c *.c
|
||||
@cd ft && $(AR) $(ARFLAGS) lib$(FTLIB).a *.o
|
||||
@cd ft && $(AR) -t lib$(FTLIB).a
|
||||
|
||||
compile: compile-ft
|
||||
@echo "Compiling $(NAME) w/ $(SRC)"
|
||||
$(CC) $(CFLAGS) -o $(NAME) -L$(FTDIR) -l$(FTLIB) $(SRC)
|
||||
@chmod +x $(NAME)
|
||||
|
||||
test:
|
||||
@echo "Running Test Suite"
|
||||
@echo "Expected: forty two"
|
||||
./$(NAME) 42 | cat -e
|
||||
@echo "Expected: zero"
|
||||
./$(NAME) 0 | cat -e
|
||||
@echo "Expected: error"
|
||||
./$(NAME) 10.4 | cat -e
|
||||
@echo "Expected: one hundred thousand"
|
||||
./$(NAME) 100000 | cat -e
|
||||
@echo "Expected: 20 : hey everybody !"
|
||||
grep "20" $(DICT) | cat -e
|
||||
@echo "Expected: hey everybody !"
|
||||
./$(NAME) 20 | cat -e
|
||||
|
||||
git-clone:
|
||||
@git clone git@vogsphere.42lausanne.ch:vogsphere/intra-uuid-43aa272e-0de1-4199-8bd8-51ca85234f84-3736481 .
|
||||
@grep -o 'git@.*' .git/config
|
||||
|
||||
git: git-clone
|
||||
|
||||
30
Rush_02/rush-02/ex00/compute/compute.c
Normal file
30
Rush_02/rush-02/ex00/compute/compute.c
Normal file
@@ -0,0 +1,30 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* compute.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 18:36:54 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 18:58:39 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "../ft/ft.h"
|
||||
|
||||
// cc -Wall -Wextra -Werror -o a.out -L../ft -lft compute.c && ./a.out && rm a.out
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *str;
|
||||
|
||||
if (argc < 2)
|
||||
return (1);
|
||||
|
||||
str = argv[1];
|
||||
ft_putstr(str);
|
||||
ft_putstr("\n");
|
||||
return (0);
|
||||
}
|
||||
9
Rush_02/rush-02/ex00/compute/compute.sh
Executable file
9
Rush_02/rush-02/ex00/compute/compute.sh
Executable file
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
txt=$(basename $0 .sh)".txt"
|
||||
set -e
|
||||
rm -f a.out
|
||||
cc -Wall -Wextra -Werror -o a.out -L../ft -lft *.c
|
||||
cat ${txt} | while read nbr; do
|
||||
./a.out "${nbr}"
|
||||
done
|
||||
rm -f a.out
|
||||
65
Rush_02/rush-02/ex00/compute/compute.txt
Normal file
65
Rush_02/rush-02/ex00/compute/compute.txt
Normal file
@@ -0,0 +1,65 @@
|
||||
0
|
||||
1
|
||||
2
|
||||
3
|
||||
4
|
||||
5
|
||||
6
|
||||
7
|
||||
8
|
||||
9
|
||||
10
|
||||
11
|
||||
12
|
||||
13
|
||||
14
|
||||
15
|
||||
16
|
||||
17
|
||||
18
|
||||
19
|
||||
20
|
||||
21
|
||||
30
|
||||
32
|
||||
40
|
||||
43
|
||||
50
|
||||
54
|
||||
60
|
||||
65
|
||||
70
|
||||
76
|
||||
80
|
||||
87
|
||||
90
|
||||
98
|
||||
100
|
||||
123
|
||||
1000
|
||||
1234
|
||||
12345
|
||||
123456
|
||||
1000000
|
||||
1234567
|
||||
1000000000
|
||||
1234567890
|
||||
1000000000000
|
||||
1234567890123
|
||||
1000000000000000
|
||||
1123456789012345
|
||||
1000000000000000000
|
||||
1234567890123456789
|
||||
1000000000000000000000
|
||||
1123456789012345678901
|
||||
1000000000000000000000000
|
||||
1234567890123456789012345
|
||||
1000000000000000000000000000
|
||||
1234567890123456789012345678
|
||||
1000000000000000000000000000000
|
||||
1234567890123456789012345678901
|
||||
1000000000000000000000000000000000
|
||||
1234567890123456789012345678901234
|
||||
1000000000000000000000000000000000000
|
||||
1234567890123456789012345678901234567
|
||||
deadbeef
|
||||
31
Rush_02/rush-02/ex00/dictionnaries/dictionnaries.c
Normal file
31
Rush_02/rush-02/ex00/dictionnaries/dictionnaries.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include "../ft/ft.h"
|
||||
|
||||
#define BUF_SIZE 4096
|
||||
|
||||
// cc -Wall -Wextra -Werror -o a.out -L../ft -lft dictionnaries.c && ./a.out && rm a.out
|
||||
|
||||
int main()
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
char buf[BUF_SIZE + 1];
|
||||
fd = open ("numbers.dict", O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
ft_putstr("open () error");
|
||||
return (1);
|
||||
}
|
||||
ret = read(fd, buf, BUF_SIZE);
|
||||
buf[ret] = '\0';
|
||||
ft_putnbr(ret);
|
||||
ft_putstr(buf);
|
||||
if (close(fd) == -1)
|
||||
{
|
||||
ft_putstr("Close() error");
|
||||
return(1);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
41
Rush_02/rush-02/ex00/dictionnaries/numbers.dict
Normal file
41
Rush_02/rush-02/ex00/dictionnaries/numbers.dict
Normal file
@@ -0,0 +1,41 @@
|
||||
0: zero
|
||||
1: one
|
||||
2: two
|
||||
3: three
|
||||
4: four
|
||||
5: five
|
||||
6: six
|
||||
7: seven
|
||||
8: eight
|
||||
9: nine
|
||||
10: ten
|
||||
11: eleven
|
||||
12: twelve
|
||||
13: thirteen
|
||||
14: fourteen
|
||||
15: fifteen
|
||||
16: sixteen
|
||||
17: seventeen
|
||||
18: eighteen
|
||||
19: nineteen
|
||||
20: twenty
|
||||
30: thirty
|
||||
40: forty
|
||||
50: fifty
|
||||
60: sixty
|
||||
70: seventy
|
||||
80: eighty
|
||||
90: ninety
|
||||
100: hundred
|
||||
1000: thousand
|
||||
1000000: million
|
||||
1000000000: billion
|
||||
1000000000000: trillion
|
||||
1000000000000000: quadrillion
|
||||
1000000000000000000: quintillion
|
||||
1000000000000000000000: sextillion
|
||||
1000000000000000000000000: septillion
|
||||
1000000000000000000000000000: octillion
|
||||
1000000000000000000000000000000: nonillion
|
||||
1000000000000000000000000000000000: decillion
|
||||
1000000000000000000000000000000000000: undecillion
|
||||
24
Rush_02/rush-02/ex00/ft/ft.h
Normal file
24
Rush_02/rush-02/ex00/ft/ft.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft.h :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:24 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 16:36:21 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FT_H
|
||||
# define FT_H
|
||||
|
||||
int ft_strlen(char *str);
|
||||
int ft_strcmp(char *s1, char *s2);
|
||||
int ft_atoi(char *str);
|
||||
void ft_putnbr(int nb);
|
||||
void ft_putstr(char *str);
|
||||
void ft_putchar(char c);
|
||||
char *ft_strcat(char *dest, char *src);
|
||||
|
||||
#endif
|
||||
38
Rush_02/rush-02/ex00/ft/ft_atoi.c
Normal file
38
Rush_02/rush-02/ex00/ft/ft_atoi.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:34 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 16:15:10 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);
|
||||
}
|
||||
18
Rush_02/rush-02/ex00/ft/ft_putchar.c
Normal file
18
Rush_02/rush-02/ex00/ft/ft_putchar.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putchar.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 15:27:46 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 15:27:47 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
void ft_putchar(char c)
|
||||
{
|
||||
write(1, &c, 1);
|
||||
}
|
||||
39
Rush_02/rush-02/ex00/ft/ft_putnbr.c
Normal file
39
Rush_02/rush-02/ex00/ft/ft_putnbr.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putnbr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 15:32:13 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 18:10:53 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.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);
|
||||
}
|
||||
}
|
||||
22
Rush_02/rush-02/ex00/ft/ft_putstr.c
Normal file
22
Rush_02/rush-02/ex00/ft/ft_putstr.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_putstr.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:45 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:02:48 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);
|
||||
}
|
||||
26
Rush_02/rush-02/ex00/ft/ft_strcat.c
Normal file
26
Rush_02/rush-02/ex00/ft/ft_strcat.c
Normal file
@@ -0,0 +1,26 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcat.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:02:59 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:03: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);
|
||||
}
|
||||
28
Rush_02/rush-02/ex00/ft/ft_strcmp.c
Normal file
28
Rush_02/rush-02/ex00/ft/ft_strcmp.c
Normal file
@@ -0,0 +1,28 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strcmp.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:04:11 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:04:12 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);
|
||||
}
|
||||
23
Rush_02/rush-02/ex00/ft/ft_strlen.c
Normal file
23
Rush_02/rush-02/ex00/ft/ft_strlen.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_strlen.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: gbaconni <gbaconni@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 14:04:24 by gbaconni #+# #+# */
|
||||
/* Updated: 2021/08/21 14:04:25 by gbaconni ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int ft_strlen(char *str)
|
||||
{
|
||||
int size;
|
||||
|
||||
size = 0;
|
||||
while (str[size] != '\0')
|
||||
{
|
||||
size++;
|
||||
}
|
||||
return (size);
|
||||
}
|
||||
BIN
Rush_02/rush-02/ex00/rush-02
Executable file
BIN
Rush_02/rush-02/ex00/rush-02
Executable file
Binary file not shown.
39
Rush_02/rush-02/ex00/rush-02.c
Normal file
39
Rush_02/rush-02/ex00/rush-02.c
Normal file
@@ -0,0 +1,39 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* rush-02.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: jsollett <marvin@42lausanne.ch> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2021/08/21 13:54:54 by jsollett #+# #+# */
|
||||
/* Updated: 2021/08/21 18:33:57 by jsollett ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include "ft/ft.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc == 1)
|
||||
ft_putstr("Enter a number or dictionary + number \n");
|
||||
else if (argc == 2)
|
||||
{
|
||||
ft_putstr("test unsigned +\n");
|
||||
ft_putstr("si oui, ouvrir dico de base\n");
|
||||
ft_putstr(" et compute le nb:\n");
|
||||
ft_putstr(argv[1]);
|
||||
}
|
||||
else if (argc == 3)
|
||||
{
|
||||
ft_putstr("test unsigned +\n");
|
||||
ft_putstr("si oui, ouvrir : ");
|
||||
ft_putstr(argv[1]);
|
||||
ft_putstr(" et compute le nb :\n");
|
||||
ft_putstr(argv[2]);
|
||||
}
|
||||
else
|
||||
ft_putstr("too arguments !");
|
||||
}
|
||||
Reference in New Issue
Block a user