commit e078efd32522539ead3af36d2ea676874e013447 Author: Gregory Date: Sun Nov 20 02:20:23 2016 +0200 init commit diff --git a/brainfuck/Makefile b/brainfuck/Makefile new file mode 100644 index 0000000..a61d6fc --- /dev/null +++ b/brainfuck/Makefile @@ -0,0 +1,32 @@ +# MAkefile +# AUTHOR: foton +# FILE: Makefile +# ROLE: to compile them all +# CREATED: 2016-11-20 00:59:16 +# MODIFIED: 2016-11-20 01:14:41 + +NAME = brainfuck +CC = clang +FLAGS = -Wall -Werror -Wextra +SRC = src/main.c \ + src/output.c \ + src/brainfuck.c +OBJ = $(SRC:.c=.o) +INC = -I inc/ + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(FLAGS) $(OBJ) $(INC) -o $(NAME) + +.c.o: $(SRC) + $(CC) $(FLAGS) $(INC) -c $< -o $@ + +clean: + rm -f $(OBJ) + +fclean: clean + rm -f $(BIN)$(NAME) + +re: + fclean all diff --git a/brainfuck/README b/brainfuck/README new file mode 100644 index 0000000..ebb5bfd --- /dev/null +++ b/brainfuck/README @@ -0,0 +1,11 @@ +# Text File +# AUTHOR: foton +# FILE: README +# ROLE: to rule them all +# CREATED: 2016-11-20 01:18:23 +# MODIFIED: 2016-11-20 01:20:33 + +Simple brainfuck interpreter. + +compile: "make fclean, make" or "make re" +test: "cat hello_world.bf | xargs ./brainfuck" diff --git a/brainfuck/hello_world.bf b/brainfuck/hello_world.bf new file mode 100644 index 0000000..e0a8381 --- /dev/null +++ b/brainfuck/hello_world.bf @@ -0,0 +1 @@ +++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. \ No newline at end of file diff --git a/brainfuck/inc/brnfck.h b/brainfuck/inc/brnfck.h new file mode 100644 index 0000000..0268c73 --- /dev/null +++ b/brainfuck/inc/brnfck.h @@ -0,0 +1,17 @@ +// C/C++ File +// AUTHOR: foton +// FILE: brnfck.h +// ROLE: to rule them all +// CREATED: 2016-11-20 00:52:13 +// MODIFIED: 2016-11-20 00:54:35 + +#ifndef BRNFCK_H +# define BRNFCK_H + +# define SIZE 30000 + +int brainfuck(char *source); +void my_putchar(char c); +void my_putstr(char *str); + +#endif diff --git a/brainfuck/src/brainfuck.c b/brainfuck/src/brainfuck.c new file mode 100644 index 0000000..f9c0704 --- /dev/null +++ b/brainfuck/src/brainfuck.c @@ -0,0 +1,52 @@ +// C/C++ File +// AUTHOR: foton +// FILE: brainfuck.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 01:13:18 +// TODO: nested loops +// read user input +// handle errors (incorrect source) +// read from file and stdin + +#include +#include "brnfck.h" + +int brainfuck(char *source) +{ + char *array; + int i; + int head; + int start_loop; + + i = 0; + array = malloc(sizeof(char) * SIZE); + while (i < SIZE) + array[i++] = 0; + i = 0; + head = 0; + start_loop = 0; + while (source[i]) + { + if (source[i] == '+') + array[head]++; + if (source[i] == '-') + array[head]--; + if (source[i] == '>') + head++; + if (source[i] == '<') + head--; + if (source[i] == '.') + my_putchar(array[head]); + if (source[i] == '[') + start_loop = i; + if (source[i] == ']') + { + if (!(array[head] == 0)) + i = start_loop - 1; + } + i++; + } + free(array); + return (0); +} diff --git a/brainfuck/src/main.c b/brainfuck/src/main.c new file mode 100644 index 0000000..e374629 --- /dev/null +++ b/brainfuck/src/main.c @@ -0,0 +1,23 @@ +// C/C++ File +// AUTHOR: foton +// FILE: main.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 01:15:58 + +#include "brnfck.h" + +int main(int argc, char **argv) +{ + if (argc < 2) + { + my_putstr("Dude, put some source to work with!\n"); + return (0); + } + if (brainfuck(argv[1]) == 1) + { + my_putstr("Something goes wrong :(\n"); + return (1); + } + return (0); +} diff --git a/brainfuck/src/output.c b/brainfuck/src/output.c new file mode 100644 index 0000000..a2fb8fc --- /dev/null +++ b/brainfuck/src/output.c @@ -0,0 +1,19 @@ +// C/C++ File +// AUTHOR: foton +// FILE: output.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 00:51:42 + +#include + +void my_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +void my_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/d00/ex01/testDay00.tar b/d00/ex01/testDay00.tar new file mode 100644 index 0000000..b5e0156 Binary files /dev/null and b/d00/ex01/testDay00.tar differ diff --git a/d00/ex02/exo2.tar b/d00/ex02/exo2.tar new file mode 100644 index 0000000..183d639 Binary files /dev/null and b/d00/ex02/exo2.tar differ diff --git a/d00/ex03/klist.txt b/d00/ex03/klist.txt new file mode 100644 index 0000000..8de2bf7 --- /dev/null +++ b/d00/ex03/klist.txt @@ -0,0 +1,5 @@ +Credentials cache: API:4728 + Principal: gtertysh@UNIT.UA + + Issued Expires Principal +Oct 26 12:13:24 2016 Oct 26 22:13:16 2016 krbtgt/UNIT.UA@UNIT.UA diff --git a/d00/ex04/who_am_i.sh b/d00/ex04/who_am_i.sh new file mode 100644 index 0000000..d39dfcb --- /dev/null +++ b/d00/ex04/who_am_i.sh @@ -0,0 +1 @@ +ldapwhoami -Q | cut -c4- | cut -d , -f1,3- diff --git a/d00/ex05/people.sh b/d00/ex05/people.sh new file mode 100644 index 0000000..3f30bf6 --- /dev/null +++ b/d00/ex05/people.sh @@ -0,0 +1 @@ +ldapsearch -Q -LLL "uid=z*" | grep "^cn" | sort -r diff --git a/d00/ex06/mobile-phone.ldif b/d00/ex06/mobile-phone.ldif new file mode 100644 index 0000000..0ac129d --- /dev/null +++ b/d00/ex06/mobile-phone.ldif @@ -0,0 +1,4 @@ +dn: uid=gtertysh,ou=november,ou=2016,ou=people,dc=unit,dc=ua +changetype: modify +add: mobile +mobile: 0930351607 diff --git a/d00/ex07/midLS b/d00/ex07/midLS new file mode 100644 index 0000000..f5883a8 --- /dev/null +++ b/d00/ex07/midLS @@ -0,0 +1 @@ +ls -mpU diff --git a/d00/ex08/z b/d00/ex08/z new file mode 100644 index 0000000..e900b1c --- /dev/null +++ b/d00/ex08/z @@ -0,0 +1 @@ +Z diff --git a/d00/ex09/b b/d00/ex09/b new file mode 100644 index 0000000..c2dab24 --- /dev/null +++ b/d00/ex09/b @@ -0,0 +1,11 @@ +Episode V, A NEW H0PE It is a period of civil war +Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. +During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet. + + +Pursued by the Empire's sinister agents, +Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie.. + + + + diff --git a/d00/ex10/clean b/d00/ex10/clean new file mode 100644 index 0000000..a38380e --- /dev/null +++ b/d00/ex10/clean @@ -0,0 +1 @@ +find . -type f \( -name '*~' -o -name '#*' -o -name '*#' \) -print -delete diff --git a/d00/ex11/ft_magic b/d00/ex11/ft_magic new file mode 100644 index 0000000..42b581f --- /dev/null +++ b/d00/ex11/ft_magic @@ -0,0 +1 @@ +41 string 42 42 file diff --git a/d01/ex01/print_groups.sh b/d01/ex01/print_groups.sh new file mode 100755 index 0000000..f2606fd --- /dev/null +++ b/d01/ex01/print_groups.sh @@ -0,0 +1 @@ +groups $FT_USER | tr ' ' ',' | tr -d '\n' diff --git a/d01/ex02/find_sh.sh b/d01/ex02/find_sh.sh new file mode 100755 index 0000000..0fc8f6b --- /dev/null +++ b/d01/ex02/find_sh.sh @@ -0,0 +1 @@ +find . -name "*.sh" | rev | cut -d '.' -f 2 | cut -d '/' -f 1 | rev diff --git a/d01/ex03/count_files.sh b/d01/ex03/count_files.sh new file mode 100755 index 0000000..dae8dc2 --- /dev/null +++ b/d01/ex03/count_files.sh @@ -0,0 +1 @@ +find . | wc -l | tr -d " " diff --git a/d01/ex04/MAC.sh b/d01/ex04/MAC.sh new file mode 100755 index 0000000..b5c33a8 --- /dev/null +++ b/d01/ex04/MAC.sh @@ -0,0 +1 @@ +ifconfig | tr -d "\t" | grep "^ether" | cut -d " " -f 2 diff --git "a/d01/ex05/\"?$*KwaMe*$?\\\"" "b/d01/ex05/\"?$*KwaMe*$?\\\"" new file mode 100644 index 0000000..e69de29 diff --git "a/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" "b/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ "b/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/d01/ex06/skip.sh b/d01/ex06/skip.sh new file mode 100755 index 0000000..002c1e5 --- /dev/null +++ b/d01/ex06/skip.sh @@ -0,0 +1 @@ +ls -l | sed -n "p;n" diff --git a/d01/ex07/r_dwssap.sh b/d01/ex07/r_dwssap.sh new file mode 100755 index 0000000..ea1e8ae --- /dev/null +++ b/d01/ex07/r_dwssap.sh @@ -0,0 +1 @@ +cat /etc/passwd | grep -v ^# | sed -n 'n;p' | cut -d ":" -f1 | rev | sort -r | sed -n "$FT_LINE1,$FT_LINE2 p" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/, /g' | tr "\n" "." diff --git a/d01/ex08/bon.sh b/d01/ex08/bon.sh new file mode 100755 index 0000000..5ae96d3 --- /dev/null +++ b/d01/ex08/bon.sh @@ -0,0 +1 @@ +ldapsearch -Q | grep ^givenName | grep -i "bon" | wc -l | tr -d " " diff --git a/d01/ex09/add_chelou.sh b/d01/ex09/add_chelou.sh new file mode 100644 index 0000000..e69de29 diff --git a/d02/ex00/ft_print_alphabet.c b/d02/ex00/ft_print_alphabet.c new file mode 100644 index 0000000..0eebf83 --- /dev/null +++ b/d02/ex00/ft_print_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/26 17:23:25 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 20:23:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_alphabet(void) +{ + char a; + + a = 'a'; + while (a <= 'z') + { + ft_putchar(a); + a = a + 1; + } +} diff --git a/d02/ex01/ft_print_reverse_alphabet.c b/d02/ex01/ft_print_reverse_alphabet.c new file mode 100644 index 0000000..467f1c3 --- /dev/null +++ b/d02/ex01/ft_print_reverse_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_reverse_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:58:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:39:26 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_reverse_alphabet(void) +{ + char z; + + z = 'z'; + while (z >= 'a') + { + ft_putchar(z); + z = z - 1; + } +} diff --git a/d02/ex02/ft_print_numbers.c b/d02/ex02/ft_print_numbers.c new file mode 100644 index 0000000..7417c25 --- /dev/null +++ b/d02/ex02/ft_print_numbers.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_numbers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:59:11 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:40:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_numbers(void) +{ + char z; + + z = '0'; + while (z <= '9') + { + ft_putchar(z); + z = z + 1; + } +} diff --git a/d02/ex03/ft_is_negative.c b/d02/ex03/ft_is_negative.c new file mode 100644 index 0000000..9a484b8 --- /dev/null +++ b/d02/ex03/ft_is_negative.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_negative.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:59:43 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 20:23:36 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_is_negative(int n) +{ + if (n >= 0) + { + ft_putchar('P'); + } + else + { + ft_putchar('N'); + } +} diff --git a/d02/ex04/ft_print_comb.c b/d02/ex04/ft_print_comb.c new file mode 100644 index 0000000..f244c21 --- /dev/null +++ b/d02/ex04/ft_print_comb.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:26:03 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:46:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnumb(char a, char b, char c) +{ + ft_putchar(a); + ft_putchar(b); + ft_putchar(c); + if (!(a == '7' && b == '8' && c == '9')) + { + ft_putchar(','); + ft_putchar(' '); + } +} + +void ft_print_comb(void) +{ + int a; + int b; + int c; + + a = 0; + while (a <= 7) + { + b = a + 1; + while (b <= 8) + { + c = b + 1; + while (c <= 9) + { + ft_putnumb(a + '0', b + '0', c + '0'); + c++; + } + b++; + } + a++; + } +} diff --git a/d02/ex06/ft_putnbr.c b/d02/ex06/ft_putnbr.c new file mode 100644 index 0000000..5d097ac --- /dev/null +++ b/d02/ex06/ft_putnbr.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 17:17:51 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 21:46:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_printnbr(int nb) +{ + int temp; + long div; + + temp = nb; + div = 1; + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } +} diff --git a/d03/ex00/ft_ft.c b/d03/ex00/ft_ft.c new file mode 100644 index 0000000..3306ab7 --- /dev/null +++ b/d03/ex00/ft_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft-ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 12:09:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 12:29:49 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/d03/ex01/ft_ultimate_ft.c b/d03/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..24dfcc6 --- /dev/null +++ b/d03/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 09:49:54 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 19:17:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ultimate_ft(int *********nbr) +{ + *********nbr = 42; +} diff --git a/d03/ex02/ft_swap.c b/d03/ex02/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d03/ex02/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d03/ex03/ft_div_mod b/d03/ex03/ft_div_mod new file mode 100755 index 0000000..1c9d25c Binary files /dev/null and b/d03/ex03/ft_div_mod differ diff --git a/d03/ex03/ft_div_mod.c b/d03/ex03/ft_div_mod.c new file mode 100644 index 0000000..c9de3c1 --- /dev/null +++ b/d03/ex03/ft_div_mod.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_div_mod.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:16:49 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:28:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_div_mod(int a, int b, int *div, int *mod) +{ + *div = a / b; + *mod = a % b; +} diff --git a/d03/ex04/ft_ultimate_div_mod.c b/d03/ex04/ft_ultimate_div_mod.c new file mode 100644 index 0000000..5010329 --- /dev/null +++ b/d03/ex04/ft_ultimate_div_mod.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_div_mode.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:30:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:17:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ultimate_div_mod(int *a, int *b) +{ + int temp; + + temp = *a / *b; + *b = *a % *b; + *a = temp; +} diff --git a/d03/ex05/ft_putstr.c b/d03/ex05/ft_putstr.c new file mode 100644 index 0000000..ddff1c2 --- /dev/null +++ b/d03/ex05/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:45:38 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:09:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d03/ex06/ft_strlen.c b/d03/ex06/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d03/ex06/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d03/ex07/ft_strrev.c b/d03/ex07/ft_strrev.c new file mode 100644 index 0000000..113a0f2 --- /dev/null +++ b/d03/ex07/ft_strrev.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrev.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:30:14 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:01:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strrev(char *str) +{ + int count; + int char_numb; + char *temp_ptr; + char temp; + + count = 0; + char_numb = 0; + temp_ptr = str; + while (*temp_ptr != '\0') + { + char_numb++; + temp_ptr++; + } + while (char_numb > count) + { + temp = *(str + char_numb - 1); + *(str + char_numb - 1) = *(str + count); + *(str + count) = temp; + count++; + char_numb--; + } + return (str); +} diff --git a/d03/ex08/ft_atoi.c b/d03/ex08/ft_atoi.c new file mode 100644 index 0000000..3512f12 --- /dev/null +++ b/d03/ex08/ft_atoi.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 12:27:05 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:02:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *p) +{ + int numb; + + numb = 0; + while (*p != '\0') + { + numb = numb * 10 + (*p) - '0'; + p++; + } + return (numb); +} diff --git a/d03/ex09/ft_sort_integer_table.c b/d03/ex09/ft_sort_integer_table.c new file mode 100644 index 0000000..c8bd2ac --- /dev/null +++ b/d03/ex09/ft_sort_integer_table.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_integer_table.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 10:16:57 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 12:03:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_sort_integer_table(int *tab, int size) +{ + int temp; + int i; + int a; + int swapped; + + i = 0; + a = 0; + while(i < size - 1) + { + swapped = 0; + while(a < size - 1 - i) + { + if (*(tab + a) > *(tab + a + 1)) + { + temp = *(tab + a); + *(tab + a) = *(tab + a + 1); + *(tab + a + 1) = temp; + swapped = 1; + } + a++; + } + i++; + if(!swapped) + break; + } +} diff --git a/d04/ex00/ft_iterative_factorial.c b/d04/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..e6dbe57 --- /dev/null +++ b/d04/ex00/ft_iterative_factorial.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 15:38:54 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 15:38:59 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_factorial(int nb) +{ + int fac; + + fac = 1; + if (nb > 12 || nb < 0) + { + return (0); + } + else + { + while (nb > 0) + { + fac *= nb; + nb--; + } + } + return (fac); +} diff --git a/d04/ex01/ft_recursive_factorial.c b/d04/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..8756682 --- /dev/null +++ b/d04/ex01/ft_recursive_factorial.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 12:29:58 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 14:34:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_factorial(int nb) +{ + if (nb < 0 || nb > 12) + { + return (0); + } + else if (nb >= 1 && nb <= 12) + { + return (nb *= ft_recursive_factorial(nb - 1)); + } + return (1); +} diff --git a/d04/ex02/ft_iterative_power.c b/d04/ex02/ft_iterative_power.c new file mode 100644 index 0000000..7397720 --- /dev/null +++ b/d04/ex02/ft_iterative_power.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 14:35:08 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 14:56:28 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_power(int nb, int power) +{ + int result; + + if (power < 0) + { + return (0); + } + else if (power == 0) + { + return (1); + } + result = nb; + while (power > 1) + { + result *= nb; + power--; + } + return (result); +} diff --git a/d04/ex03/ft_recursive_power.c b/d04/ex03/ft_recursive_power.c new file mode 100644 index 0000000..ef044e4 --- /dev/null +++ b/d04/ex03/ft_recursive_power.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 14:57:08 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 15:46:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_power(int nb, int power) +{ + if (power < 0) + { + return (0); + } + else if (power == 0) + { + return (1); + } + nb = ft_recursive_power(nb, power - 1) * nb; + return (nb); +} diff --git a/d04/ex04/ft_fibonacci.c b/d04/ex04/ft_fibonacci.c new file mode 100644 index 0000000..2f1ba9a --- /dev/null +++ b/d04/ex04/ft_fibonacci.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fibonacci.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 15:51:02 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 17:46:07 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_fibonacci(int index) +{ + if (index < 0) + return (-1); + else if (index == 0) + return (0); + else if (index == 1) + return (1); + else + return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); +} diff --git a/d04/ex05/ft_sqrt.c b/d04/ex05/ft_sqrt.c new file mode 100644 index 0000000..edd6d65 --- /dev/null +++ b/d04/ex05/ft_sqrt.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sqrt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 17:56:37 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 21:53:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_sqrt(int numb) +{ + int i; + + i = 0; + while (i * i < nb) + i++; + if (i * i == nb) + return (i); + else + return (0); +} diff --git a/d04/ex06/ft_is_prime.c b/d04/ex06/ft_is_prime.c new file mode 100644 index 0000000..bc84885 --- /dev/null +++ b/d04/ex06/ft_is_prime.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 20:00:31 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 22:06:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_prime(int nb) +{ + int i; + + i = 2; + if (nb < 0) + return (0); + else if (nb < 3) + return (0); + else + { + while (i < nb / 2) + { + if (nb % i == 0) + return (0); + i++; + } + } + return (1); +} diff --git a/d05/ex00/ft_putstr.c b/d05/ex00/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d05/ex00/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d05/ex01/ft_putnbr.c b/d05/ex01/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/d05/ex01/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/d05/ex02/ft_atoi.c b/d05/ex02/ft_atoi.c new file mode 100644 index 0000000..2e739ad --- /dev/null +++ b/d05/ex02/ft_atoi.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:43:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/d05/ex03/ft_strcpy.c b/d05/ex03/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/d05/ex03/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/d05/ex04/ft_strncpy.c b/d05/ex04/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/d05/ex04/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/d05/ex05/ft_strstr.c b/d05/ex05/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/d05/ex05/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/d05/ex06/ft_strcmp.c b/d05/ex06/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d05/ex06/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d05/ex07/ft_strncmp.c b/d05/ex07/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/d05/ex07/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/d05/ex08/ft_strupcase.c b/d05/ex08/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/d05/ex08/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/d05/ex09/ft_strlowcase.c b/d05/ex09/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/d05/ex09/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/d05/ex10/ft_strcapitalize.c b/d05/ex10/ft_strcapitalize.c new file mode 100644 index 0000000..e4b4f6c --- /dev/null +++ b/d05/ex10/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 16:19:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/d05/ex11/ft_str_is_alpha.c b/d05/ex11/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/d05/ex11/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex12/ft_str_is_numeric.c b/d05/ex12/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/d05/ex12/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex13/ft_str_is_lowercase.c b/d05/ex13/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/d05/ex13/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex14/ft_str_is_uppercase.c b/d05/ex14/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/d05/ex14/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex15/ft_str_is_printable.c b/d05/ex15/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/d05/ex15/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex16/ft_strcat.c b/d05/ex16/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/d05/ex16/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/d06/ex00/ft_putchar.c b/d06/ex00/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d06/ex00/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d06/ex00/ft_putstr.c b/d06/ex00/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d06/ex00/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d06/ex00/ft_strcmp.c b/d06/ex00/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d06/ex00/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d06/ex00/ft_strlen.c b/d06/ex00/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d06/ex00/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d06/ex00/ft_swap.c b/d06/ex00/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d06/ex00/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d06/ex00/libft_creator.sh b/d06/ex00/libft_creator.sh new file mode 100755 index 0000000..d7f4c12 --- /dev/null +++ b/d06/ex00/libft_creator.sh @@ -0,0 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# libft_creator.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/02 12:08:36 by gtertysh #+# #+# # +# Updated: 2016/11/02 19:05:47 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +gcc -c ./*.c +ar cr libft.a ./*.o +rm ./*.o diff --git a/d06/ex01/ft_print_program_name.c b/d06/ex01/ft_print_program_name.c new file mode 100644 index 0000000..ae8bba3 --- /dev/null +++ b/d06/ex01/ft_print_program_name.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 12:58:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:06:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + argc = -argc; + ft_putstr(argv[0]); + ft_putchar('\n'); + return (0); +} diff --git a/d06/ex02/ft_print_params.c b/d06/ex02/ft_print_params.c new file mode 100644 index 0000000..632651b --- /dev/null +++ b/d06/ex02/ft_print_params.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 15:59:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:07:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + ft_putstr(argv[i]); + ft_putchar('\n'); + i++; + } + return (0); +} diff --git a/d06/ex03/ft_rev_params.c b/d06/ex03/ft_rev_params.c new file mode 100644 index 0000000..184a79b --- /dev/null +++ b/d06/ex03/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 16:16:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:08:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + while (argc-- > 1) + { + ft_putstr(argv[argc]); + ft_putchar('\n'); + } + return (0); +} diff --git a/d06/ex04/ft_sort_params.c b/d06/ex04/ft_sort_params.c new file mode 100644 index 0000000..901291b --- /dev/null +++ b/d06/ex04/ft_sort_params.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 16:33:17 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:02:25 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +void print_argv(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + ft_putstr(argv[i]); + ft_putchar('\n'); + i++; + } +} + +int cmp(char *s1, char *s2) +{ + while (*s1 && s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (!*s1) + return (0); + return (*s1 - *s2); +} + +int main(int argc, char **argv) +{ + int i; + int j; + char *temp; + + i = 1; + j = 1; + while (i < argc) + { + j = 1; + while (j < argc - 1) + { + if (cmp(argv[j], argv[j + 1]) > 0) + { + temp = argv[j]; + argv[j] = argv[j + 1]; + argv[j + 1] = temp; + } + j++; + } + i++; + } + print_argv(argc, argv); + return (0); +} diff --git a/d07/ex00/ft_strdup.c b/d07/ex00/ft_strdup.c new file mode 100644 index 0000000..0d0e257 --- /dev/null +++ b/d07/ex00/ft_strdup.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 20:38:00 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:41:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strdup(char *src) +{ + int size; + int i; + char *new_str; + char *begin; + + begin = src; + size = 0; + while (*src != '\0') + { + src++; + size++; + } + new_str = (char*)malloc(sizeof(*new_str) * (size + 1)); + i = 0; + while (i <= size) + { + new_str[i] = begin[i]; + i++; + } + new_str[i] = '\0'; + return (new_str); +} diff --git a/d07/ex01/ft_range.c b/d07/ex01/ft_range.c new file mode 100644 index 0000000..97bd9d2 --- /dev/null +++ b/d07/ex01/ft_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 10:45:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 18:58:22 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *ft_range(int min, int max) +{ + int *array; + int i; + + if (min >= max) + return (0); + array = (int*)malloc(sizeof(int*) * (max - min)); + i = 0; + while (i < max - min) + { + array[i] = min + i; + i++; + } + return (array); +} diff --git a/d07/ex02/ft_ultimate_range.c b/d07/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..4082818 --- /dev/null +++ b/d07/ex02/ft_ultimate_range.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 11:21:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 21:53:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + int *new_array; + + i = 0; + if (min >= max) + { + *range = 0; + return (0); + } + new_array = (int*)malloc(sizeof(int) * (max - min)); + while (i < max - min) + { + new_array[i] = min + i; + i++; + } + *range = new_array; + return (max - min); +} diff --git a/d07/ex03/ft_concat_params.c b/d07/ex03/ft_concat_params.c new file mode 100644 index 0000000..65b4137 --- /dev/null +++ b/d07/ex03/ft_concat_params.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_concat_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 15:34:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 19:20:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int count_chars(int argc, char **argv) +{ + int i; + int j; + int chars; + + i = 1; + j = 0; + chars = 0; + while (i < argc) + { + j = 0; + while (argv[i][j]) + { + j++; + chars++; + } + i++; + } + return (chars); +} + +void fill_string(int argc, char **argv, char *concat) +{ + int i; + int j; + int c; + + i = 1; + j = 0; + c = 0; + while (i < argc) + { + j = 0; + while (argv[i][j] != '\0') + { + concat[c] = argv[i][j]; + j++; + c++; + } + concat[c] = '\n'; + c++; + i++; + } + concat[--c] = '\0'; +} + +char *ft_concat_params(int argc, char **argv) +{ + char *concat; + int chars; + + chars = count_chars(argc, argv); + concat = (char*)malloc(sizeof(char) * (chars + argc)); + fill_string(argc, argv, concat); + return (concat); +} diff --git a/d07/ex04/ft_split_whitespaces.c b/d07/ex04/ft_split_whitespaces.c new file mode 100644 index 0000000..45f0deb --- /dev/null +++ b/d07/ex04/ft_split_whitespaces.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 12:01:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +char **ft_split_whitespaces(char *str) +{ + char **table; + char *str_begin; + int words; + int word_exist; + int chars_in_word; + int word_position; + int char_position; + + // count words in string + str_begin = str; + words = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + word_exist = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + word_exist = 1; + } + if (word_exist) + words++; + } + + // allocate memory for word pointers + table = (char **)malloc(sizeof(char *) * (words + 1)); + + // count chars in word, allocate memory for current word + // and fill allocated memory + str = str_begin; + word_position = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + chars_in_word = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + chars_in_word++; + } + table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1)); + if (!chars_in_word) + break; + char_position = 0; + while (chars_in_word) + { + table[word_position][char_position] = *(str - chars_in_word); + chars_in_word--; + char_position++; + } + table[word_position][char_position] = '\0'; + word_position++; + } + printf("%d\n", word_position); + table[word_position] = 0; + return (table); +} + +int main(int argc, char **argv) +{ + char **a; + int i; + + i = 0; + //a = ft_split_whitespaces(argv[1]); + a = ft_split_whitespaces("a1 234 "); + while (a[i]) + { + printf("%s\n", a[i++]); + } + return(0); +} diff --git a/d08/ex00/ft_split_whitespaces.c b/d08/ex00/ft_split_whitespaces.c new file mode 100644 index 0000000..b482d1c --- /dev/null +++ b/d08/ex00/ft_split_whitespaces.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/06 17:47:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +char **ft_split_whitespaces(char *str) +{ + char **table; + char *str_begin; + int words; + int word_exist; + int chars_in_word; + int word_position; + + // count words in string + str_begin = str; + words = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + word_exist = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + word_exist = 1; + } + if (word_exist) + words++; + } + + // allocate memory for word pointers + table = (char **)malloc(sizeof(char *) * (words + 1)); + + // count chars in word, allocate memory for current word + // and fill allocated memory + str = str_begin; + while (*str) + { + word_position = 0; + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + chars_in_word = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + chars_in_word++; + } + table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1)); + while(chars_in_word) + {} + printf("%d\n", chars_in_word); + } + printf("%d\n", words); + return (table); +} + +int main(void) +{ + char **a; + + a = ft_split_whitespaces(" asfa asfa saf af "); + return(0); +} diff --git a/d08/ex00/ft_split_whitespaces_partialy_working.c b/d08/ex00/ft_split_whitespaces_partialy_working.c new file mode 100644 index 0000000..2f5a239 --- /dev/null +++ b/d08/ex00/ft_split_whitespaces_partialy_working.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/06 13:40:45 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void table_mem(char *string, char ***table) +{ + int word_exist; + int words; + + words = 0; + while (*string) + { + while (*string == ' ' || *string == '\t' || *string == '\n') + string++; + word_exist = 0; + while (*string != ' ' && *string != '\t' && *string != '\n' && *string) + { + string++; + word_exist = 1; + } + if (word_exist) + words++; + } + *table = (char **)malloc(sizeof(char *) * (words + 1)); +} + +int word_mem(char **table, int word_index, int char_in_word) +{ + table[word_index] = (char *)malloc(sizeof(char) * (char_in_word + 1)); + if (char_in_word != 0) + { + return (1); + } + else + { + table[word_index] = 0; + return (0); + } +} + +int count_chars(char **begin, char **word_begin) +{ + int char_in_word; + + while (**begin == ' ' || **begin == '\t' || **begin == '\n') + (*begin)++; + char_in_word = 0; + *word_begin = *begin; + while (**begin != ' ' && **begin != '\t' && **begin != '\n' && **begin) + { + (*begin)++; + char_in_word++; + } + return (char_in_word); +} + +char **ft_split_whitespaces(char *str) +{ + char **table; + int char_in_word; + int word_index; + int char_index; + char *word_begin; + + word_index = 0; + char_index = 0; + table_mem(str, &table); + while (*str) + { + char_in_word = count_chars(&str, &word_begin); + word_mem(table, word_index, char_in_word); + char_index = 0; + while (char_in_word--) + { + table[word_index][char_index++] = *word_begin; + word_begin++; + } + table[word_index][char_index] = '\0'; + word_index++; + } + return (table); +} + +int main(void) +{ + char **a; + int i; + + i = 0; + a = ft_split_whitespaces(" asfa asfa saf af "); + printf("%s\n", a[2]); + return(0); +} diff --git a/d08/ex01/ft.h b/d08/ex01/ft.h new file mode 100644 index 0000000..09fcd1e --- /dev/null +++ b/d08/ex01/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/d08/ex02/ft_boolean.h b/d08/ex02/ft_boolean.h new file mode 100644 index 0000000..c3a180d --- /dev/null +++ b/d08/ex02/ft_boolean.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_boolean.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:04:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BOOLEAN_H +# define FT_BOOLEAN_H + +# include +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" +# define EVEN(x) (!(x % 2)) + +typedef int t_bool; + +#endif diff --git a/d08/ex03/ft_abs.h b/d08/ex03/ft_abs.h new file mode 100644 index 0000000..0b3d697 --- /dev/null +++ b/d08/ex03/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:32:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:34:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_ABS_H +# define FT_ABS_H + +# define ABS(Value) ((Value < 0) ? -Value : Value) + +#endif diff --git a/d08/ex04/ft_point.h b/d08/ex04/ft_point.h new file mode 100644 index 0000000..941dc27 --- /dev/null +++ b/d08/ex04/ft_point.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:35:46 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_POINT_H +# define FT_POINT_H + +typedef struct s_point +{ + int x; + int y; +} t_point; + +#endif diff --git a/d09/ex00/ft_generic.c b/d09/ex00/ft_generic.c new file mode 100644 index 0000000..4b3ddae --- /dev/null +++ b/d09/ex00/ft_generic.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_generic.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 17:52:10 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:17:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_generic(void) +{ + write(1, "Tu tu tu tu ; Tu tu tu tu\n", 26); +} diff --git a/d09/ex01/ft_takes_place.c b/d09/ex01/ft_takes_place.c new file mode 100644 index 0000000..253e889 --- /dev/null +++ b/d09/ex01/ft_takes_place.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_takes_place.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 19:21:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:01:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_take_place(int hour) +{ + char *a; + + a = "THE FOLLOWING TAKES PLACE BETWEEN "; + if (hour == 0) + printf("%s12.00 A.M. AND 1.00 A.M\n", a); + else if (hour == 23) + printf("%s11.00 P.M. AND 12.00 A.M\n", a); + else if (hour == 11) + printf("%s11.00 A.M. AND 12.00 P.M\n", a); + else if (hour == 12) + printf("%s12.00 P.M. AND 1.00 P.M\n", a); + else if (hour > 12) + printf("%s%d.00 P.M. AND %d.00 P.M\n", a, hour - 12, hour - 12 + 1); + else + printf("%s%d.00 A.M. AND %d.00 A.M\n", a, hour, hour + 1); +} diff --git a/d09/ex02/find_nicolas_bomber.sh b/d09/ex02/find_nicolas_bomber.sh new file mode 100755 index 0000000..75aa511 --- /dev/null +++ b/d09/ex02/find_nicolas_bomber.sh @@ -0,0 +1,13 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# find_nicolas_bomber.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/03 20:27:43 by gtertysh #+# #+# # +# Updated: 2016/11/04 02:01:26 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +cat $1 | grep -i ^nicolas | cut -d $'\t' -f2- | grep -i ^bomber | cut -d$'\t' -f2 | grep [0-9] diff --git a/d09/ex03/defuse.sh b/d09/ex03/defuse.sh new file mode 100755 index 0000000..48dfaab --- /dev/null +++ b/d09/ex03/defuse.sh @@ -0,0 +1,14 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# defuse.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/03 21:41:01 by gtertysh #+# #+# # +# Updated: 2016/11/04 02:01:19 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +LAST_ACCESS_TIME=$(stat -f %a bomb.txt) +echo "$LAST_ACCESS_TIME - 1" | bc diff --git a/d09/ex04/ft_rot42.c b/d09/ex04/ft_rot42.c new file mode 100644 index 0000000..69cecd3 --- /dev/null +++ b/d09/ex04/ft_rot42.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rot42.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 21:58:10 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:01:11 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_rot42(char *str) +{ + char *begin; + + begin = str; + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + *str = (*str - 65 + 42) % 26 + 65; + else if (*str >= 'a' && *str <= 'z') + *str = (*str - 97 + 42) % 26 + 97; + str++; + } + return (begin); +} diff --git a/d09/ex05/ft_button.c b/d09/ex05/ft_button.c new file mode 100644 index 0000000..29d92df --- /dev/null +++ b/d09/ex05/ft_button.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_button.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 22:46:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 23:15:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_button(int i, int j, int k) +{ + int temp[3]; + int x; + int swap; + + x = 0; + temp[0] = i; + temp[1] = j; + temp[2] = k; + while (x < 3) + { + j = 0; + while (j < 2) + { + if (temp[j] > temp[j + 1]) + { + swap = temp[j]; + temp[j] = temp[j + 1]; + temp[j + 1] = swap; + } + j++; + } + x++; + } + return (temp[1]); +} diff --git a/d09/ex06/ft_destroy.c b/d09/ex06/ft_destroy.c new file mode 100644 index 0000000..ee47bc0 --- /dev/null +++ b/d09/ex06/ft_destroy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 23:41:05 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:33 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_ultimator.h" + +void ft_destroy(char ***factory) +{ + while (*factory != 0) + { + while (**factory != 0) + { + free(**factory); + **factory++; + } + free(*factory); + *factory++; + } +} diff --git a/d09/ex07/ft_collatz_conjecture.c b/d09/ex07/ft_collatz_conjecture.c new file mode 100644 index 0000000..3288eab --- /dev/null +++ b/d09/ex07/ft_collatz_conjecture.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_collatz_conjecture.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 01:39:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:26 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_collatz_conjecture(unsigned int base) +{ + static unsigned int i = 0; + + i++; + if (base == 1) + return (i); + else if (base % 2 == 0) + return (ft_collatz_conjecture(base / 2)); + else + return (ft_collatz_conjecture(base * 3 + 1)); +} diff --git a/d09/ex08/ft_spy.c b/d09/ex08/ft_spy.c new file mode 100644 index 0000000..a0d91e9 --- /dev/null +++ b/d09/ex08/ft_spy.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_spy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 01:58:29 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putstr(char *str) +{ + while (*str) + { + write(1, str, 1); + str++; + } +} + +void low(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + { + *str += 32; + } + str++; + } +} + +int is_alert(char *str, char *find) +{ + while (*str == ' ' || *str == '\t') + str++; + while (*str && *find && *str == *find) + { + str++; + find++; + } + if (*find == '\0' && (*str == '\0' || *str < 33)) + { + return (1); + } + else + return (0); +} + +void ft_spy(int argc, char **argv) +{ + int i; + int j; + char *a; + char *b; + char *c; + + a = "president"; + b = "attack"; + c = "powers"; + i = 1; + j = 0; + while (i < argc) + { + low(argv[i]); + if (is_alert(argv[i], a) || + is_alert(argv[i], b) || + is_alert(argv[i], c)) + ft_putstr("Alert!!!\n"); + i++; + } +} + +int main(int argc, char **argv) +{ + ft_spy(argc, argv); + return (0); +} diff --git a/d09/ex09/where_am_i.sh b/d09/ex09/where_am_i.sh new file mode 100644 index 0000000..5bcdc33 --- /dev/null +++ b/d09/ex09/where_am_i.sh @@ -0,0 +1,21 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# where_am_i.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/04 03:35:14 by gtertysh #+# #+# # +# Updated: 2016/11/04 04:01:02 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + + +IPS=$(ifconfig | grep "inet " | cut -d " " -f2) + +if [ -z "$IPS" ] +then + echo "Je suis perdu!" +else + echo $IPS | tr " " "\n" +fi diff --git a/d09/ex10/ft_scrambler.c b/d09/ex10/ft_scrambler.c new file mode 100644 index 0000000..80e6f15 --- /dev/null +++ b/d09/ex10/ft_scrambler.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_scrambler.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 04:05:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 17:14:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_scrambler(int ***a, int *b, int *******c, int ****d) +{ + int tempa; + int tempb; + int tempc; + int tempd; + + tempa = ***a; + tempb = *b; + tempc = *******c; + tempd = ****d; + *******c = tempa; + ****d = tempc; + *b = tempd; + ***a = tempb; +} diff --git a/d09/ex11/ft_perso.h b/d09/ex11/ft_perso.h new file mode 100644 index 0000000..8ed7417 --- /dev/null +++ b/d09/ex11/ft_perso.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_perso.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 04:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 05:13:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PERSO_H +# define FT_PERSO_H + +typedef struct s_perso +{ + char *name; + float life; + int age; + char *profession; + +} t_perso; + +#endif diff --git a/d09/ex12/ft_door.c b/d09/ex12/ft_door.c new file mode 100644 index 0000000..522f9f7 --- /dev/null +++ b/d09/ex12/ft_door.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_door.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 05:24:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:11:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_door.h" + +void ft_putstr(char *str) +{ + while (*str) + { + write(1, str, 1); + str++; + } + write(1, "\n", 1); +} + +t_bool close_door(t_door *door) +{ + ft_putstr("Door closing..."); + door->state = CLOSE; + return (TRUE); +} + +t_bool is_door_open(t_door *door) +{ + ft_putstr("Door is open ?"); + if (door->state == OPEN) + return (TRUE); + else + return (FALSE); +} + +t_bool is_door_close(t_door *door) +{ + ft_putstr("Door is close ?"); + if (door->state == CLOSE) + return (TRUE); + else + return (FALSE); +} + +t_bool open_door(t_door *door) +{ + ft_putstr("Door opening..."); + door->state = OPEN; + return (TRUE); +} diff --git a/d09/ex12/ft_door.h b/d09/ex12/ft_door.h new file mode 100644 index 0000000..4ba9955 --- /dev/null +++ b/d09/ex12/ft_door.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_door.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 05:14:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:16:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_DOOR_H +# define FT_DOOR_H +# define EXIT_SUCCESS 0 +# define OPEN 1 +# define CLOSE 0 +# define TRUE 1 +# define FALSE 0 + +typedef int t_bool; + +typedef struct s_door +{ + int state; +} t_door; + +void ft_putstr(char *str); +t_bool close_door(t_door *door); +t_bool is_door_open(t_door *door); +t_bool is_door_close(t_door *door); +t_bool open_door(t_door *door); + +#endif diff --git a/d09/ex12/main.c b/d09/ex12/main.c new file mode 100644 index 0000000..fa46d70 --- /dev/null +++ b/d09/ex12/main.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 06:08:21 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:08:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_door.h" + +int main() +{ + t_door door; + open_door(&door); + if (is_door_close(&door)) + open_door(&door); + if (is_door_open(&door)) + close_door(&door); + if (door.state == OPEN) + close_door(&door); + return (EXIT_SUCCESS); +} diff --git a/d09/ex13/ft_compact.c b/d09/ex13/ft_compact.c new file mode 100644 index 0000000..745e145 --- /dev/null +++ b/d09/ex13/ft_compact.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_compact.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 06:46:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 07:21:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_compact(char **tab, int length) +{ + int i; + int j; + + i = 0; + while (i < length) + { + if (tab[i] == 0) + { + while (i + 1 < length) + { + tab[i] = tab[i + 1]; + i++; + } + length--; + tab[i] = 0; + i = -1; + } + i++; + } + return (length); +} diff --git a/d09/ex16/ft_active_bits.c b/d09/ex16/ft_active_bits.c new file mode 100644 index 0000000..dfd6cb2 --- /dev/null +++ b/d09/ex16/ft_active_bits.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_active_bits.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 10:20:14 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 11:40:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_active_bits(int value) +{ + unsigned int bits; + + bits = 0; + if (value < 0) + bits++; + value = value & 0x7FFFFFFF; + while (value) + { + bits += value & 1; + value = value >> 1; + } + return (bits); +} diff --git a/d09/ex17/ft_max.c b/d09/ex17/ft_max.c new file mode 100644 index 0000000..c86a714 --- /dev/null +++ b/d09/ex17/ft_max.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 10:45:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 11:04:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_max(int *tab, int length) +{ + int i; + int max; + + i = 1; + if (length == 0) + return (0); + max = tab[0]; + while (i < length) + { + if (tab[i] > max) + max = tab[i]; + i++; + } + return (max); +} diff --git a/d09/ex18/ft_join.c b/d09/ex18/ft_join.c new file mode 100644 index 0000000..f6d5a1e --- /dev/null +++ b/d09/ex18/ft_join.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_join.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 11:08:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 13:32:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void fill(char *str, char **tab, char *sep) +{ + int i; + int j; + int c; + + i = 0; + j = 0; + c = 0; + while (tab[i]) + { + j = 0; + while (tab[i][j]) + { + str[c++] = tab[i][j++]; + } + j = 0; + while (sep[j] && tab[i + 1]) + { + str[c++] = sep[j++]; + } + i++; + } + str[c] = '\0'; +} + +char *ft_join(char **tab, char *sep) +{ + int i; + int j; + int chars; + char *str; + + i = 0; + chars = 0; + if (tab[i] == 0) + return (0); + while (tab[i]) + { + j = 0; + while (tab[i][j++]) + chars++; + i++; + } + j = 0; + while (sep[j]) + j++; + str = (char *)malloc(sizeof(char) * (chars + j * (i - 1) + 1)); + fill(str, tab, sep); + return (str); +} diff --git a/d09/ex20/cold_shower.sh b/d09/ex20/cold_shower.sh new file mode 100644 index 0000000..e69de29 diff --git a/d09/ex22/save_donnie.sh b/d09/ex22/save_donnie.sh new file mode 100755 index 0000000..aa9f958 --- /dev/null +++ b/d09/ex22/save_donnie.sh @@ -0,0 +1,13 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# save_donnie.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/04 15:13:54 by gtertysh #+# #+# # +# Updated: 2016/11/04 17:02:14 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +chmod a-w . diff --git a/d09/ex23/ft_generic.c b/d09/ex23/ft_generic.c new file mode 100644 index 0000000..5ce2a1d --- /dev/null +++ b/d09/ex23/ft_generic.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_generic.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 15:45:40 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 15:50:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_generic(void) +{ + write(1, "Tu tu tu tu ; Tu tu tu tu\n", 26); +} diff --git a/d10/d10.tar b/d10/d10.tar new file mode 100644 index 0000000..9bf2d72 Binary files /dev/null and b/d10/d10.tar differ diff --git a/d10/ex00/Makefile b/d10/ex00/Makefile new file mode 100644 index 0000000..7a7d985 --- /dev/null +++ b/d10/ex00/Makefile @@ -0,0 +1,38 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/07 13:45:08 by gtertysh #+# #+# # +# Updated: 2016/11/07 16:09:06 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = libft.a +SRCS = ./srcs +OBJ = ./objs +INC = ./includes +all: $(NAME) + +$(NAME): + @gcc -c ./srcs/ft_putchar.c \ + ./srcs/ft_putstr.c \ + ./srcs/ft_swap.c \ + ./srcs/ft_strlen.c \ + ./srcs/ft_strcmp.c \ + -I $(INC) + @ar cr $(NAME) ./ft_putchar.o \ + ./ft_putstr.o \ + ./ft_strcmp.o \ + ./ft_swap.o \ + ./ft_strlen.o + +clean: + @/bin/rm -f ./*.o + +fclean: clean + @/bin/rm -f $(NAME) + +re: fclean all diff --git a/d10/ex00/includes/ft.h b/d10/ex00/includes/ft.h new file mode 100644 index 0000000..12cf6e7 --- /dev/null +++ b/d10/ex00/includes/ft.h @@ -0,0 +1,2 @@ +void ft_putstr(char *str); +int ft_putchar(char c); diff --git a/d10/ex00/srcs/ft_putchar.c b/d10/ex00/srcs/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d10/ex00/srcs/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d10/ex00/srcs/ft_putstr.c b/d10/ex00/srcs/ft_putstr.c new file mode 100644 index 0000000..35f2c5c --- /dev/null +++ b/d10/ex00/srcs/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 15:03:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d10/ex00/srcs/ft_strcmp.c b/d10/ex00/srcs/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d10/ex00/srcs/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d10/ex00/srcs/ft_strlen.c b/d10/ex00/srcs/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d10/ex00/srcs/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d10/ex00/srcs/ft_swap.c b/d10/ex00/srcs/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d10/ex00/srcs/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d10/ex01/ft_foreach.c b/d10/ex01/ft_foreach.c new file mode 100644 index 0000000..1a457e6 --- /dev/null +++ b/d10/ex01/ft_foreach.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:24:51 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 16:51:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_foreach(int *tab, int length, void (*f)(int)) +{ + int i; + + i = 0; + while (i < length) + { + f(tab[i++]); + } +} diff --git a/d10/ex02/ft_map.c b/d10/ex02/ft_map.c new file mode 100644 index 0000000..c191899 --- /dev/null +++ b/d10/ex02/ft_map.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:54:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 17:25:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *ft_map(int *tab, int length, int (*f)(int)) +{ + int *arr; + int i; + + i = 0; + arr = (int *)malloc(sizeof(int) * (length)); + while (i < length) + { + arr[i] = f(tab[i]); + i++; + } + return (arr); +} diff --git a/d10/ex03/ft_any.c b/d10/ex03/ft_any.c new file mode 100644 index 0000000..3c8f0d6 --- /dev/null +++ b/d10/ex03/ft_any.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_any.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 17:28:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 18:17:41 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_any(char **tab, int (*f)(char *)) +{ + int i; + + i = 0; + while (tab[i]) + { + if (f(tab[i++])) + return (1); + } + return (0); +} diff --git a/d10/ex04/ft_count_if.c b/d10/ex04/ft_count_if.c new file mode 100644 index 0000000..280b186 --- /dev/null +++ b/d10/ex04/ft_count_if.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 17:54:32 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 18:17:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_count_if(char **tab, int (*f)(char *)) +{ + int count; + + count = 0; + while(*tab) + { + if(f(*tab)) + { + count++; + (*tab)++; + } + tab++; + } + return (count); +} diff --git a/d10/ex05/ft_is_sort.c b/d10/ex05/ft_is_sort.c new file mode 100644 index 0000000..e6e1147 --- /dev/null +++ b/d10/ex05/ft_is_sort.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 18:18:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 19:37:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_sort(int *tab, int length, int (*f)(int, int)) +{ + int i; + + i = 0; + while (i < length - 1) + { + if (f(tab[i], tab[i + 1]) == -1 || f(tab[i], tab[i + 1]) == 0) + i++; + else + { + i = 0; + while (i < length - 1) + { + if (f(tab[i], tab[i + 1]) == 1 || f(tab[i], tab[i + 1]) == 0) + i++; + else + return (0); + } + } + } + return (1); +} diff --git a/d10/ex06/ft_atoi.c b/d10/ex06/ft_atoi.c new file mode 100644 index 0000000..f8e0b24 --- /dev/null +++ b/d10/ex06/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 20:27:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/d10/ex06/ft_putchar.c b/d10/ex06/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d10/ex06/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d10/ex06/ft_putnbr.c b/d10/ex06/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/d10/ex06/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/d10/ex06/ft_putstr.c b/d10/ex06/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d10/ex06/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d10/ex06/main.c b/d10/ex06/main.c new file mode 100644 index 0000000..b459d8e --- /dev/null +++ b/d10/ex06/main.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 19:46:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 21:41:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str); +void ft_putnbr(int nb); +int ft_putchar(char c); +void ft_putstr(char *str); + +typedef int (*operations)(int, int); + +int add(int a, int b) +{ + return (a + b); +} + +int sub(int a, int b) +{ + return (a - b); +} + +int div(int a, int b) +{ + return (a / b); +} + +int mul(int a, int b) +{ + return (a * b); +} + +int mod(int a, int b) +{ + return (a % b); +} + +int calculator(int a, int b, operations o) +{ + return (o(a, b)); +} + +int main(int argc, char **argv) +{ + operations a[5]; + char *op = "+-/*%"; + int i; + + i = 0; + a[0] = &add; + a[1] = ⊂ + a[2] = ÷ + a[3] = &mul; + a[4] = &mod; + + if (argc != 4) + return (0); + while (i < 5) + { + if (argv[2][0] == op[i] && argv[2][1] == 0) + { + if (argv[2][0] == '/' && ft_atoi(argv[3]) == 0) + ft_putstr("Stop : division by zero"); + else if (argv[2][0] == '%' && ft_atoi(argv[3]) == 0) + ft_putstr("Stop : modulus by zero"); + else + ft_putnbr(calculator(ft_atoi(argv[1]), ft_atoi(argv[3]), a[i])); + ft_putchar('\n'); + break; + } + i++; + if (i == 5) + ft_putstr("0\n"); + } + return (0); +} diff --git a/d10/test/Makefile b/d10/test/Makefile new file mode 100644 index 0000000..d0a460b --- /dev/null +++ b/d10/test/Makefile @@ -0,0 +1,30 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/07 12:38:53 by gtertysh #+# #+# # +# Updated: 2016/11/07 13:10:27 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = prog +SRC = main.c + +all: compile + +compile: + @gcc -o $(NAME) $(SRC) + +clean: + @/bin/rm -f *.o + +fclean: clean + @/bin/rm -f $(NAME) + +re: fclean all + +test: fclean all + @./$(NAME) diff --git a/d10/test/main.c b/d10/test/main.c new file mode 100644 index 0000000..b88dbfa --- /dev/null +++ b/d10/test/main.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 12:53:44 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 14:13:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int main(void) +{ + int a; + printf("Hello!"); + return (0); +} diff --git a/d11/ex00/ft_create_elem.c b/d11/ex00/ft_create_elem.c new file mode 100644 index 0000000..3f96364 --- /dev/null +++ b/d11/ex00/ft_create_elem.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_create_elem.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 14:02:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:35:30 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +t_list *ft_create_elem(void *data) +{ + t_list *new; + + new = NULL; + if ((new = malloc(sizeof(t_list)))) + { + new->data = data; + new->next = NULL; + } + return (new); +} diff --git a/d11/ex00/ft_list.h b/d11/ex00/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex00/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex01/ft_list.h b/d11/ex01/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex01/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex01/ft_list_push_back.c b/d11/ex01/ft_list_push_back.c new file mode 100644 index 0000000..c4492d0 --- /dev/null +++ b/d11/ex01/ft_list_push_back.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:19:18 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:13:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_push_back(t_list **begin_list, void *data) +{ + if (*begin_list == NULL) + (*begin_list) = ft_create_elem(data); + else + { + while ((*begin_list)->next) + begin_list = &(*begin_list)->next; + (*begin_list)->next = ft_create_elem(data); + } +} diff --git a/d11/ex02/ft_list.h b/d11/ex02/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex02/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex02/ft_list_push_front.c b/d11/ex02/ft_list_push_front.c new file mode 100644 index 0000000..9eb73b1 --- /dev/null +++ b/d11/ex02/ft_list_push_front.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 17:31:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 12:05:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_push_front(t_list **begin_list, void *data) +{ + t_list *first; + + first = ft_create_elem(data); + first->next = *begin_list; + *begin_list = first; +} diff --git a/d11/ex03/ft_list.h b/d11/ex03/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex03/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex03/ft_list_size.c b/d11/ex03/ft_list_size.c new file mode 100644 index 0000000..c23551d --- /dev/null +++ b/d11/ex03/ft_list_size.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 19:16:58 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:31:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +int ft_list_size(t_list *begin_list) +{ + int size; + + size = 0; + while (begin_list) + { + size++; + begin_list = begin_list->next; + } + return (size); +} diff --git a/d11/ex04/ft_list.h b/d11/ex04/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex04/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex04/ft_list_last.c b/d11/ex04/ft_list_last.c new file mode 100644 index 0000000..6e015de --- /dev/null +++ b/d11/ex04/ft_list_last.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_last.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 20:12:36 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 20:44:33 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +t_list *ft_list_last(t_list *begin_list) +{ + while (begin_list && begin_list->next) + { + begin_list = begin_list->next; + } + return (begin_list); +} diff --git a/d11/ex05/ft_list.h b/d11/ex05/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex05/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex05/ft_list_push_params.c b/d11/ex05/ft_list_push_params.c new file mode 100644 index 0000000..4a49a55 --- /dev/null +++ b/d11/ex05/ft_list_push_params.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 21:02:05 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:30:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +t_list *ft_list_push_params(int ac, char **av) +{ + t_list *begin; + t_list *temp; + int i; + + i = 1; + begin = NULL; + temp = NULL; + while (i < ac) + { + temp = ft_create_elem(av[i]); + temp->next = begin; + begin = temp; + i++; + } + return (begin); +} diff --git a/d11/ex06/ft_list.h b/d11/ex06/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex06/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex06/ft_list_clear.c b/d11/ex06/ft_list_clear.c new file mode 100644 index 0000000..e4684f3 --- /dev/null +++ b/d11/ex06/ft_list_clear.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_clear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 15:09:41 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 15:21:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_clear(t_list **begin_list) +{ + t_list *temp; + + while (*begin_list) + { + temp = (*begin_list)->next; + free(*begin_list); + *begin_list = temp; + } +} diff --git a/d11/ex07/ft_list.h b/d11/ex07/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex07/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex07/ft_list_at.c b/d11/ex07/ft_list_at.c new file mode 100644 index 0000000..f44a20a --- /dev/null +++ b/d11/ex07/ft_list_at.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_at.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 15:31:04 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 16:27:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +t_list *ft_list_at(t_list *begin_list, unsigned int nbr) +{ + unsigned int i; + t_list *temp; + + i = 0; + temp = begin_list; + while (i < nbr && begin_list != NULL) + { + temp = begin_list->next; + begin_list = temp; + i++; + } + return (temp); +} diff --git a/d11/ex08/ft_list.h b/d11/ex08/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex08/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex08/ft_list_reverse.c b/d11/ex08/ft_list_reverse.c new file mode 100644 index 0000000..b0ffaf0 --- /dev/null +++ b/d11/ex08/ft_list_reverse.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_reverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 16:28:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:06:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_reverse(t_list **begin_list) +{ + t_list *prev; + t_list *next; + t_list *curr; + + prev = NULL; + curr = *begin_list; + while (curr) + { + next = curr->next; + curr->next = prev; + prev = curr; + curr = next; + } + *begin_list = prev; +} diff --git a/d11/ex09/ft_list.h b/d11/ex09/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex09/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex09/ft_list_foreach.c b/d11/ex09/ft_list_foreach.c new file mode 100644 index 0000000..b3ff00e --- /dev/null +++ b/d11/ex09/ft_list_foreach.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 17:51:36 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:19:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_foreach(t_list *begin_list, void (*f)(void *)) +{ + while (begin_list) + { + f(begin_list->data); + begin_list = begin_list->next; + } +} diff --git a/d11/ex10/ft_list.h b/d11/ex10/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11/ex10/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex10/ft_list_foreach_if.c b/d11/ex10/ft_list_foreach_if.c new file mode 100644 index 0000000..ac0b1a8 --- /dev/null +++ b/d11/ex10/ft_list_foreach_if.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_foreach_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 18:46:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:22:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()) +{ + while (begin_list) + { + if ((cmp(begin_list->data, data_ref) == 0)) + f(begin_list->data); + begin_list = begin_list->next; + } +} diff --git a/d11/ex11/ft_list.h b/d11/ex11/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11/ex11/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex11/ft_list_find.c b/d11/ex11/ft_list_find.c new file mode 100644 index 0000000..0928341 --- /dev/null +++ b/d11/ex11/ft_list_find.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_find.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 21:18:19 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:46:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) +{ + while (begin_list) + { + if ((cmp(begin_list->data, data_ref) == 0)) + return (begin_list); + begin_list = begin_list->next; + } + return (0); +} diff --git a/d11_test/Makefile b/d11_test/Makefile new file mode 100644 index 0000000..fd87be9 --- /dev/null +++ b/d11_test/Makefile @@ -0,0 +1,26 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/09 11:55:54 by gtertysh #+# #+# # +# Updated: 2016/11/09 18:40:42 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = list +SRC = ../d11/*/*.c +INC = . +FLAGS = -Wall -Wextra + +all: compile + +compile: + @gcc $(FLAGS) main.c ft_list_print.c $(SRC) -I $(INC) -o $(NAME) + +clean: + rm -f $(NAME) + +re: clean compile diff --git a/d11_test/ft_list.h b/d11_test/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11_test/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11_test/ft_list_print.c b/d11_test/ft_list_print.c new file mode 100644 index 0000000..6497e44 --- /dev/null +++ b/d11_test/ft_list_print.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 17:52:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 19:00:56 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +void ft_list_print(t_list *list) +{ + while (list) + { + printf("%s\n", list->data); + list = list->next; + } +} diff --git a/d11_test/main.c b/d11_test/main.c new file mode 100644 index 0000000..9e71e17 --- /dev/null +++ b/d11_test/main.c @@ -0,0 +1,92 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 18:35:38 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 18:07:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft_list.h" +#include + +void print_data(void *data) +{ + printf("%s\n", data); +} + +void find(void *data) +{ + + printf("find: %s!\n", data); +} + +int main(int argc, char **argv) +{ + t_list *new_list; + + new_list = NULL; + + //push_back + ft_list_push_back(&new_list, "ads"); + ft_list_push_back(&new_list, "addsd"); + + //push_front + ft_list_push_front(&new_list, "a"); + ft_list_push_front(&new_list, "b"); + ft_list_push_front(&new_list, "c"); + ft_list_push_front(&new_list, "d"); + printf("\nFirst list: \n"); + + ////print_list + ft_list_print(new_list); + + //////list_size + printf("Number of elements: %d\n", ft_list_size(new_list)); + + ////list_last + printf("last elemet: %s\n\n", (ft_list_last(new_list))->data); + + //push_params + printf("\nList with program arguments:\n"); + ft_list_print(ft_list_push_params(argc, argv)); + + //clear list + printf("\nFirst list after free: \n"); + ft_list_clear(&new_list); + ft_list_print(new_list); + + //list_at + ft_list_push_back(&new_list, "asd"); + ft_list_push_back(&new_list, "dsa"); + printf("Element of new_list at 0: %s\n", ft_list_at(new_list, 0)->data); + + //reverse_list + ft_list_clear(&new_list); + ft_list_push_back(&new_list, "1"); + ft_list_push_back(&new_list, "2"); + ft_list_push_back(&new_list, "3"); + ft_list_push_back(&new_list, "4"); + printf("new_list before reverse: \n"); + ft_list_print(new_list); + ft_list_reverse(&new_list); + printf("new_list after reverse: \n"); + ft_list_print(new_list); + + //list_foreach + printf("new_list print foreach: \n"); + ft_list_foreach(new_list, print_data); + ft_list_push_front(&new_list, "asd"); + ft_list_push_front(&new_list, "asd"); + ft_list_foreach(new_list, print_data); + + //list_foreach_if + ft_list_foreach_if(new_list, find, "", strcmp); + printf(" find data: %s\n", (ft_list_find(new_list, "4", strcmp)->data)); + return (0); +} diff --git a/d12/ex00/Makefile b/d12/ex00/Makefile new file mode 100644 index 0000000..4c1390a --- /dev/null +++ b/d12/ex00/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/10 16:39:11 by gtertysh #+# #+# # +# Updated: 2016/11/10 18:24:50 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = ft_display_file +SRC = src/ +INC = headers/ +MAIN = main/ +FLAGS = -Wall -Wextra -Werror +LIB = libft.a + + +all: $(NAME) + +lib: + gcc -c $(SRC)*.c -I $(INC) + ar cr $(LIB) *.o + +$(NAME): lib + gcc $(FLAGS) $(MAIN)*.c -L . -lft -I $(INC) -o $(NAME) + +clean: + rm -f *.o + +fclean: clean + rm -f $(LIB) + rm -f $(NAME) + diff --git a/d12/ex00/headers/ft.h b/d12/ex00/headers/ft.h new file mode 100644 index 0000000..59ca30c --- /dev/null +++ b/d12/ex00/headers/ft.h @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 20:23:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +# define BUF_SIZE 10000 + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/d12/ex00/main/display_file.c b/d12/ex00/main/display_file.c new file mode 100644 index 0000000..0789605 --- /dev/null +++ b/d12/ex00/main/display_file.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* display_file.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 16:40:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 20:42:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +int main(int argc, char **argv) +{ + int fd; + int readed; + char buf[BUF_SIZE + 1]; + + if (argc < 2) + { + ft_putstr("File name missing.\n"); + return (1); + } + else if (argc > 2) + { + ft_putstr("Too many arguments.\n"); + return (1); + } + fd = open(argv[1], O_RDONLY); + if (fd == -1) + return (1); + while ((readed = read(fd, buf, BUF_SIZE))) + { + buf[readed] = '\0'; + ft_putstr(buf); + } + if ((close(fd) == -1)) + return (1); + return (0); +} diff --git a/d12/ex00/src/ft_putchar.c b/d12/ex00/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d12/ex00/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d12/ex00/src/ft_putstr.c b/d12/ex00/src/ft_putstr.c new file mode 100644 index 0000000..83bf980 --- /dev/null +++ b/d12/ex00/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 18:23:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d12/ex01/Makefile b/d12/ex01/Makefile new file mode 100644 index 0000000..f502e55 --- /dev/null +++ b/d12/ex01/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/10 16:39:11 by gtertysh #+# #+# # +# Updated: 2016/11/10 21:44:18 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = ft_cat +SRC = src/ +INC = headers/ +MAIN = main/ +FLAGS = -Wall -Wextra -Werror +LIB = libft.a + + +all: $(NAME) + +lib: + gcc -c $(SRC)*.c -I $(INC) + ar cr $(LIB) *.o + +$(NAME): lib + gcc $(FLAGS) $(MAIN)*.c -L . -lft -I $(INC) -o $(NAME) + +clean: + rm -f *.o + +fclean: clean + rm -f $(LIB) + rm -f $(NAME) + diff --git a/d12/ex01/headers/ft.h b/d12/ex01/headers/ft.h new file mode 100644 index 0000000..a34b774 --- /dev/null +++ b/d12/ex01/headers/ft.h @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:39:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +# define BUF_SIZE 10 + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); +int print_err(char *argvstr); +void loop(int argc, char **argv, char *buf); + +#endif diff --git a/d12/ex01/main/ft_cat.c b/d12/ex01/main/ft_cat.c new file mode 100644 index 0000000..13c8853 --- /dev/null +++ b/d12/ex01/main/ft_cat.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_cat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 18:36:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:40:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +int main(int argc, char **argv) +{ + int readed; + char buf[BUF_SIZE + 1]; + + if (argc == 1) + { + while ((readed = read(0, buf, BUF_SIZE))) + { + buf[readed] = '\0'; + ft_putstr(buf); + } + } + else + { + loop(argc, argv, buf); + } + return (0); +} diff --git a/d12/ex01/src/ft_putchar.c b/d12/ex01/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d12/ex01/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d12/ex01/src/ft_putstr.c b/d12/ex01/src/ft_putstr.c new file mode 100644 index 0000000..5dab2f3 --- /dev/null +++ b/d12/ex01/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:20:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d12/ex01/src/loop.c b/d12/ex01/src/loop.c new file mode 100644 index 0000000..b9db132 --- /dev/null +++ b/d12/ex01/src/loop.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 21:31:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:43:30 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include +#include + +void loop(int argc, char **argv, char *buf) +{ + int i; + int fd; + int readed; + + i = 1; + while (i < argc) + { + if (argv[i][0] == '-' && argv[i][1] == 0) + fd = 0; + else + fd = open(argv[i], O_RDONLY); + print_err(argv[i]); + while ((readed = read(fd, buf, BUF_SIZE)) && fd != -1) + { + if (print_err(argv[i])) + break ; + buf[readed] = '\0'; + ft_putstr(buf); + } + close(fd); + i++; + } +} diff --git a/d12/ex01/src/print_err.c b/d12/ex01/src/print_err.c new file mode 100644 index 0000000..c666345 --- /dev/null +++ b/d12/ex01/src/print_err.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_err.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 21:35:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:43:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include + +int print_err(char *argvstr) +{ + if (errno == 2) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": No such file or directory\n"); + } + else if (errno == 13) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": Permission denied\n"); + } + else if (errno == 21) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": Is a directory\n"); + return (1); + } + return (0); +} diff --git a/d12_test/open.c b/d12_test/open.c new file mode 100644 index 0000000..c794dc2 --- /dev/null +++ b/d12_test/open.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* open.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 12:22:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 16:37:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +#define BUF_SIZE 100 + +int main(int argc, char **argv) +{ + int fd; + int ret; + char buffer[BUF_SIZE + 1]; + + if (argc < 2) + { + ft_putstr("File name missing.\n"); + return (1); + } + else if (argc > 2) + { + ft_putstr("Too many arguments.\n"); + return (1); + } + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + return (1); + } + while((ret = read(fd, buffer, BUF_SIZE))) + { + buffer[ret] = '\0'; + ft_putstr(buffer); + } + if (close(fd) == -1) + { + return (1); + } + return (0); +} diff --git a/d13/ex00/btree_create_node.c b/d13/ex00/btree_create_node.c new file mode 100644 index 0000000..14b0154 --- /dev/null +++ b/d13/ex00/btree_create_node.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:24:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 14:54:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +t_btree *btree_create_node(void *item) +{ + t_btree *new_node; + + new_node = NULL; + if ((new_node = malloc(sizeof(t_btree)))) + { + new_node->left = NULL; + new_node->right = NULL; + new_node->item = item; + } + return (new_node); +} diff --git a/d13/ex00/ft_btree.h b/d13/ex00/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex00/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex01/btree_apply_prefix.c b/d13/ex01/btree_apply_prefix.c new file mode 100644 index 0000000..ea24c4d --- /dev/null +++ b/d13/ex01/btree_apply_prefix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_prefix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:50:38 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 19:57:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) +{ + if (!root) + return ; + applyf(root->item); + btree_apply_prefix(root->left, applyf); + btree_apply_prefix(root->right, applyf); +} diff --git a/d13/ex01/ft_btree.h b/d13/ex01/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex01/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex02/btree_apply_infix.c b/d13/ex02/btree_apply_infix.c new file mode 100644 index 0000000..235e551 --- /dev/null +++ b/d13/ex02/btree_apply_infix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_infix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 13:21:21 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 18:49:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_infix(t_btree *root, void (*applyf)(void *)) +{ + if (!root) + return ; + btree_apply_infix(root->left, applyf); + applyf(root->item); + btree_apply_infix(root->right, applyf); +} diff --git a/d13/ex02/ft_btree.h b/d13/ex02/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex02/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex03/btree_apply_suffix.c b/d13/ex03/btree_apply_suffix.c new file mode 100644 index 0000000..965fb2b --- /dev/null +++ b/d13/ex03/btree_apply_suffix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_suffix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 18:59:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:21:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_suffix(t_btree *root, void (*apply)(void *)) +{ + if (!root) + return ; + btree_apply_suffix(root->left, apply); + btree_apply_suffix(root->right, apply); + apply(root->item); +} diff --git a/d13/ex03/ft_btree.h b/d13/ex03/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex03/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex04/btree_insert_data.c b/d13/ex04/btree_insert_data.c new file mode 100644 index 0000000..a22e388 --- /dev/null +++ b/d13/ex04/btree_insert_data.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_insert_data.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 19:17:19 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:21:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_btree.h" + +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)) +{ + if (*root == NULL) + { + *root = btree_create_node(item); + return ; + } + if (cmpf(item, (*root)->item) >= 0) + btree_insert_data(&(*root)->right, item, cmpf); + else if (cmpf(item, (*root)->item) < 0) + btree_insert_data(&(*root)->left, item, cmpf); +} diff --git a/d13/ex04/ft_btree.h b/d13/ex04/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex04/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex05/btree_search_item.c b/d13/ex05/btree_search_item.c new file mode 100644 index 0000000..5741d21 --- /dev/null +++ b/d13/ex05/btree_search_item.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_search_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 21:22:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:24:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)) +{ + void *ret; + + ret = NULL; + if (!root) + return (0); + { + ret = btree_search_item(root->left, data_ref, cmpf); + if (ret) + return (ret); + if (cmpf(data_ref, root->item) == 0) + return (root->item); + return (btree_search_item(root->right, data_ref, cmpf)); + } +} diff --git a/d13/ex05/ft_btree.h b/d13/ex05/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex05/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13_test/Makefile b/d13_test/Makefile new file mode 100644 index 0000000..36465f5 --- /dev/null +++ b/d13_test/Makefile @@ -0,0 +1,26 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/09 11:55:54 by gtertysh #+# #+# # +# Updated: 2016/11/11 21:12:34 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = btree +SRC = ../d13/*/*.c +INC = . +FLAGS = -Wall -Werror -Wextra + +all: compile + +compile: + @clang main.c btree_print.c $(SRC) -I $(INC) -o $(NAME) + +clean: + rm -f $(NAME) + +re: clean compile diff --git a/d13_test/btree_print.c b/d13_test/btree_print.c new file mode 100644 index 0000000..7fb05d7 --- /dev/null +++ b/d13_test/btree_print.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:06:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 12:43:25 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +void btree_print(t_btree *tree) +{ + if(!tree) + return ; + printf("%s\n", tree->item); + btree_print(tree->left); + btree_print(tree->right); +} diff --git a/d13_test/ft_btree.h b/d13_test/ft_btree.h new file mode 100644 index 0000000..507f7c9 --- /dev/null +++ b/d13_test/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:45:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13_test/main.c b/d13_test/main.c new file mode 100644 index 0000000..dec42c9 --- /dev/null +++ b/d13_test/main.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:24:31 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 14:46:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include +#include +#include + +void print_item(void *item) +{ + printf("%s\n", (char *)item); +} + +int void_strcmp(void *s1, void *s2) +{ + while (*((char *)s1) && *((char *)s2) && *((char *)s1) == *((char *)s2)) + { + s1++; + s2++; + } + if (*((char *)s1) > *((char *)s2)) + return (*((char *)s1) - *((char *)s2)); + if (*((char *)s1) < *((char *)s2)) + return (*((char *)s1) - *((char *)s2)); + return (0); +} + +int main(void) +{ + t_btree *tree; + t_btree *new_tree; + + tree = NULL; + new_tree = NULL; + + //create nodes + tree = btree_create_node("F"); + tree->left = btree_create_node("B"); + tree->left->left = btree_create_node("A"); + tree->left->right = btree_create_node("D"); + tree->left->right->left = btree_create_node("C"); + tree->left->right->right = btree_create_node("E"); + tree->right = btree_create_node("G"); + tree->right->right = btree_create_node("I"); + tree->right->right->left = btree_create_node("H"); + + //prefix traersal + printf("prefix\n"); + btree_apply_prefix(tree, print_item); + + //infix traversal + printf("infix\n"); + btree_apply_infix(tree, print_item); + + //suffix traversal + printf("suffix\n"); + btree_apply_suffix(tree, print_item); + + //inserting item + btree_insert_data(&new_tree, "1", void_strcmp); + btree_insert_data(&new_tree, "2", void_strcmp); + btree_insert_data(&new_tree, "3", void_strcmp); + btree_insert_data(&new_tree, "4", void_strcmp); + printf("inserting item. prefix output:\n"); + btree_apply_prefix(new_tree, print_item); + + //searching with infix traversal + printf("searching with infix traversal: \n"); + printf("%s\n", btree_search_item(new_tree, "2", void_strcmp)); + + return (0); +} diff --git a/ft_lib/lib/ft.h b/ft_lib/lib/ft.h new file mode 100644 index 0000000..b55a9d2 --- /dev/null +++ b/ft_lib/lib/ft.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 12:02:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); diff --git a/ft_lib/lib/libft.a b/ft_lib/lib/libft.a new file mode 100644 index 0000000..e14cca6 Binary files /dev/null and b/ft_lib/lib/libft.a differ diff --git a/ft_lib/libft.a b/ft_lib/libft.a new file mode 100644 index 0000000..8b277f0 --- /dev/null +++ b/ft_lib/libft.a @@ -0,0 +1 @@ +! diff --git a/ft_lib/libft_creator.sh b/ft_lib/libft_creator.sh new file mode 100755 index 0000000..7d56adf --- /dev/null +++ b/ft_lib/libft_creator.sh @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# libft_creator.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/02 12:08:36 by gtertysh #+# #+# # +# Updated: 2016/11/12 15:04:26 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +ROOT=~/42/ft_lib +SRC=~/42/ft_lib/src +OBJ=~/42/ft_lib/obj +LIB=~/42/ft_lib/lib + +cd $OBJ + +for f in "$SRC"/*.c +do + gcc -c "${f}" +done + +cd $LIB + +for f in "$OBJ"/*.o +do + ar r libft.a "${f}" +done + +for f in "$OBJ"/*.o +do + rm "${f}" +done diff --git a/ft_lib/src/ft_atoi.c b/ft_lib/src/ft_atoi.c new file mode 100644 index 0000000..28b53be --- /dev/null +++ b/ft_lib/src/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:02:46 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/ft_lib/src/ft_putchar.c b/ft_lib/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/ft_lib/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/ft_lib/src/ft_putnbr.c b/ft_lib/src/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/ft_lib/src/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/ft_lib/src/ft_putstr.c b/ft_lib/src/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/ft_lib/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/ft_lib/src/ft_str_is_alpha.c b/ft_lib/src/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/ft_lib/src/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_lowercase.c b/ft_lib/src/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/ft_lib/src/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_numeric.c b/ft_lib/src/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/ft_lib/src/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_printable.c b/ft_lib/src/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/ft_lib/src/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_uppercase.c b/ft_lib/src/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/ft_lib/src/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_strcapitalize.c b/ft_lib/src/ft_strcapitalize.c new file mode 100644 index 0000000..83fbea2 --- /dev/null +++ b/ft_lib/src/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 16:18:12 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/ft_lib/src/ft_strcat.c b/ft_lib/src/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/ft_lib/src/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/ft_lib/src/ft_strcmp.c b/ft_lib/src/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/ft_lib/src/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/ft_lib/src/ft_strcpy.c b/ft_lib/src/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/ft_lib/src/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/ft_lib/src/ft_strlen.c b/ft_lib/src/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/ft_lib/src/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/ft_lib/src/ft_strlowcase.c b/ft_lib/src/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/ft_lib/src/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/ft_lib/src/ft_strncmp.c b/ft_lib/src/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/ft_lib/src/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/ft_lib/src/ft_strncpy.c b/ft_lib/src/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/ft_lib/src/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/ft_lib/src/ft_strstr.c b/ft_lib/src/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/ft_lib/src/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/ft_lib/src/ft_strupcase.c b/ft_lib/src/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/ft_lib/src/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/ft_lib/src/ft_swap.c b/ft_lib/src/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/ft_lib/src/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/ft_lib/test/main.c b/ft_lib/test/main.c new file mode 100644 index 0000000..f8e1da3 --- /dev/null +++ b/ft_lib/test/main.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 13:00:54 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 20:24:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../lib/ft.h" + +int main(void) +{ + ft_putstr("Hello\n"); + return (0); +} diff --git a/group_BSQ/Makefile b/group_BSQ/Makefile new file mode 100644 index 0000000..1dddc00 --- /dev/null +++ b/group_BSQ/Makefile @@ -0,0 +1,40 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/16 20:23:31 by gtertysh #+# #+# # +# Updated: 2016/11/16 20:57:41 by ykolomie ### ########.fr # +# # +# **************************************************************************** # + +CC = gcc +FLAGS = -Wall -Wextra -Werror +SRC = ./srcs/main.c \ + ./srcs/read.c \ + ./srcs/bsq.c \ + ./srcs/find_max.c \ + ./srcs/output.c \ + ./srcs/corr_map.c +OBJ = $(SRC:.c=.o) +INC = -I ./includes +NAME = bsq + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(FLAGS) $(INC) $(OBJ) -o $(NAME) + +.c.o: + $(CC) $(FLAGS) $(INC) -c $< -o $@ + +clean: + rm -f $(OBJ) + +fclean: clean + rm -f $(NAME) + +re: fclean all + diff --git a/group_BSQ/auteur b/group_BSQ/auteur new file mode 100644 index 0000000..61f51c1 --- /dev/null +++ b/group_BSQ/auteur @@ -0,0 +1 @@ +ykolomie:gtertysh diff --git a/group_BSQ/includes/bsq.h b/group_BSQ/includes/bsq.h new file mode 100644 index 0000000..fbed142 --- /dev/null +++ b/group_BSQ/includes/bsq.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bsq.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 19:17:51 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:18:37 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BSQ_H +# define BSQ_H + +void bsq(char *buf); + +#endif diff --git a/group_BSQ/includes/corr_map.h b/group_BSQ/includes/corr_map.h new file mode 100644 index 0000000..11f20fa --- /dev/null +++ b/group_BSQ/includes/corr_map.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* corr_map.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:21:29 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:13:51 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CORR_MAP_H +# define CORR_MAP_H + +# include "find_max.h" + +void corr_map(char **map, t_coord max, char full); + +#endif diff --git a/group_BSQ/includes/find_max.h b/group_BSQ/includes/find_max.h new file mode 100755 index 0000000..aea6937 --- /dev/null +++ b/group_BSQ/includes/find_max.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_max.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:13:45 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 18:57:41 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FIND_MAX_H +# define FIND_MAX_H + +typedef struct s_coord +{ + int x; + int y; + int size; +} t_coord; + +int *create_matrix(char **buf, int rows, int cols, char empty); +t_coord find_max_square(int *m, int rows, int cols); + +#endif diff --git a/group_BSQ/includes/output.h b/group_BSQ/includes/output.h new file mode 100755 index 0000000..045ea47 --- /dev/null +++ b/group_BSQ/includes/output.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* output.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:42:08 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 18:58:39 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef OUTPUT_H +# define OUTPUT_H + +void ft_putchar(char c); +void ft_putstr(char *str); +void ft_puterror(char *str); +void print_map(char **map); +int ft_strlen(char *str); + +#endif diff --git a/group_BSQ/includes/read.h b/group_BSQ/includes/read.h new file mode 100755 index 0000000..2d41412 --- /dev/null +++ b/group_BSQ/includes/read.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:09:31 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:22:47 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef READ_H +# define READ_H + +char *expand_buf(char *buf, unsigned int *size); +char *read_file(int fd); +int ft_atoi(char *str); +char **ft_split_linebreak(char *buf); + +#endif diff --git a/group_BSQ/map_gen.pl b/group_BSQ/map_gen.pl new file mode 100755 index 0000000..a72422f --- /dev/null +++ b/group_BSQ/map_gen.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; + +die "program x y density" unless (scalar(@ARGV) == 3); +my ($x, $y, $density) = @ARGV; +print "$y.ox\n"; +for (my $i = 0; $i < $y; $i++) { + for (my $j = 0; $j < $x; $j++) { + if (int(rand($y) * 2) < $density) { + print "o"; + } + else { + print "."; + } + } + print "\n"; +} diff --git a/group_BSQ/srcs/bsq.c b/group_BSQ/srcs/bsq.c new file mode 100644 index 0000000..eb02656 --- /dev/null +++ b/group_BSQ/srcs/bsq.c @@ -0,0 +1,121 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:00:48 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 22:00:13 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "corr_map.h" +#include "read.h" +#include "output.h" +#include "find_max.h" + +int check_one(char *str, char *chset) +{ + int len; + + len = 0; + while (str[len] != '\0') + len++; + chset[2] = str[len - 1]; + chset[1] = str[len - 2]; + chset[0] = str[len - 3]; + if (chset[0] == chset[1] || chset[0] == chset[2] || chset[1] == chset[2]) + return (0); + str[len - 3] = '\0'; + return (1); +} + +int check_two(char **start, int *rows, int *cols, char *chset) +{ + int columns_count; + + if ((*cols = ft_strlen(*start)) < 1) + return (0); + *rows = 0; + while (*start) + { + columns_count = 0; + while ((*start)[columns_count] != '\0') + { + if (((*start)[columns_count] != chset[0]) + && ((*start)[columns_count] != chset[1])) + return (0); + columns_count++; + } + if (columns_count != *cols) + return (0); + start++; + (*rows)++; + } + return (1); +} + +char **check(char *buf, int *rows, int *cols, char *chset) +{ + char **table; + int first_line_rows; + + if ((table = ft_split_linebreak(buf))) + { + if (ft_strlen(table[0]) <= 3) + return (0); + if (!(check_one(*table, chset))) + return (0); + if ((first_line_rows = ft_atoi(*table)) < 0) + return (0); + table++; + if (!(*table)) + return (0); + if (!(check_two(table, rows, cols, chset))) + return (0); + if (*rows != first_line_rows) + return (0); + return (table); + } + return (0); +} + +void bsq_work(char **table, int rows, int cols, char *charset) +{ + int *matrix; + t_coord max; + int i; + + matrix = create_matrix(table, rows, cols, charset[0]); + max = find_max_square(matrix, rows, cols); + matrix = 0; + corr_map(table, max, charset[2]); + print_map(table); + i = 0; + --table; + while (table[i]) + { + free(table[i]); + i++; + } + free(table); +} + +void bsq(char *buf) +{ + char **table; + int cols; + int rows; + char charset[3]; + + if ((table = check(buf, &rows, &cols, charset))) + { + bsq_work(table, rows, cols, charset); + table = 0; + } + else + ft_puterror("map error\n"); +} diff --git a/group_BSQ/srcs/corr_map.c b/group_BSQ/srcs/corr_map.c new file mode 100644 index 0000000..38b49f8 --- /dev/null +++ b/group_BSQ/srcs/corr_map.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* corr_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 16:46:45 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:33:45 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "find_max.h" + +char **corr_map(char **map, t_coord max, char full) +{ + int i; + int j; + + i = 0; + while (i < max.size) + { + j = 0; + while (j < max.size) + { + map[max.y - i][max.x - j] = full; + j++; + } + i++; + } + return (map); +} diff --git a/group_BSQ/srcs/find_max.c b/group_BSQ/srcs/find_max.c new file mode 100755 index 0000000..6a67042 --- /dev/null +++ b/group_BSQ/srcs/find_max.c @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:57:16 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 20:28:27 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "find_max.h" +#include + +int *create_matrix(char **buf, int rows, int cols, char empty) +{ + int *matrix; + int i; + int j; + + matrix = malloc(sizeof(int) * rows * cols); + i = 0; + while (i < rows) + { + j = 0; + while (j < cols) + { + if (buf[i][j] == empty) + matrix[i * cols + j] = 1; + else + matrix[i * cols + j] = 0; + j++; + } + i++; + } + return (matrix); +} + +int min(int a, int b, int c) +{ + if (a <= b && a <= c) + return (a); + if (b <= a && b <= c) + return (b); + if (c <= a && c <= b) + return (c); + return (0); +} + +void find_all_square(int *m, int rows, int cols) +{ + int i; + int j; + + i = 1; + while (i < rows) + { + j = 1; + while (j < cols) + { + if (m[i * cols + j] == 1) + m[i * cols + j] = min(m[(i - 1) * cols + j], + m[i * cols + j - 1], + m[(i - 1) * cols + j - 1]) + 1; + j++; + } + i++; + } +} + +t_coord find_max_square(int *m, int rows, int cols) +{ + int i; + int j; + t_coord max; + + find_all_square(m, rows, cols); + max.x = 0; + max.y = 0; + max.size = m[0]; + i = -1; + while (++i < rows) + { + j = -1; + while (++j < cols) + if (max.size < m[i * cols + j]) + { + max.size = m[i * cols + j]; + max.y = i; + max.x = j; + } + } + free(m); + return (max); +} diff --git a/group_BSQ/srcs/main.c b/group_BSQ/srcs/main.c new file mode 100755 index 0000000..f3ddf08 --- /dev/null +++ b/group_BSQ/srcs/main.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 19:14:37 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 22:11:48 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" +#include "output.h" +#include "read.h" +#include +#include + +int main(int argc, char **argv) +{ + int fd; + int i; + char *buf; + + if (argc == 1) + { + buf = read_file(0); + bsq(buf); + } + else + { + i = 0; + while (++i < argc) + { + if ((fd = open(argv[i], O_RDONLY)) == -1) + continue ; + buf = read_file(fd); + bsq(buf); + if (i != argc - 1) + ft_putchar('\n'); + close(fd); + } + } + return (0); +} diff --git a/group_BSQ/srcs/output.c b/group_BSQ/srcs/output.c new file mode 100755 index 0000000..64e9619 --- /dev/null +++ b/group_BSQ/srcs/output.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* output.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:58:15 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 21:53:11 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "output.h" +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +void ft_puterror(char *str) +{ + while (*str) + write(2, str++, 1); +} + +void print_map(char **map) +{ + int i; + int j; + + i = 0; + while (map[i]) + { + j = 0; + while (map[i][j] != '\0') + write(1, &map[i][j++], 1); + write(1, "\n", 1); + i++; + } +} + +int ft_strlen(char *str) +{ + int length; + + length = 0; + while (str[length]) + length++; + return (length); +} diff --git a/group_BSQ/srcs/read.c b/group_BSQ/srcs/read.c new file mode 100755 index 0000000..a06707d --- /dev/null +++ b/group_BSQ/srcs/read.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:04:02 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 21:36:05 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "read.h" +#include +#include + +char *expand_buf(char *buf, unsigned int *size) +{ + char *new_buf; + unsigned int i; + + new_buf = malloc(sizeof(char) * (*size) * 2); + i = 0; + while (i < *size) + { + new_buf[i] = buf[i]; + i++; + } + *size *= 2; + free(buf); + return (new_buf); +} + +char *read_file(int fd) +{ + char *buf; + unsigned int length; + unsigned int buf_size; + int readed; + + length = 0; + buf_size = 16; + buf = malloc(sizeof(char) * buf_size); + while ((readed = read(fd, buf + length, buf_size - length))) + { + length += readed; + if (length == buf_size) + buf = expand_buf(buf, &buf_size); + } + buf[length] = '\0'; + return (buf); +} + +int ft_atoi(char *str) +{ + int result; + + result = 0; + while (*str >= '0' && *str <= '9') + { + result = result * 10 + *str - '0'; + str++; + } + if (*str != '\0') + return (0); + return (result); +} + +char *fill_line(char **str) +{ + char *res; + int length; + int i; + + length = 0; + while (!((*str)[length] == '\n' || (*str)[length] == '\0')) + length++; + res = malloc(sizeof(char) * length + 1); + res[length--] = '\0'; + i = 0; + while (i <= length) + { + res[i++] = **str; + (*str)++; + } + (*str)++; + return (res); +} + +char **ft_split_linebreak(char *buf) +{ + char **res; + int lines; + char *stepbuf; + int i; + char *for_delete; + + lines = 0; + for_delete = buf; + stepbuf = buf; + while (*stepbuf) + if (*stepbuf++ == '\n') + lines++; + if (*(stepbuf - 1) != '\n') + return (0); + res = malloc(sizeof(char*) * lines + 1); + res[lines] = 0; + i = 0; + while (i < lines) + res[i++] = fill_line(&buf); + free(for_delete); + return (res); +} diff --git a/my_bsq/Makefile b/my_bsq/Makefile new file mode 100644 index 0000000..e72f78e --- /dev/null +++ b/my_bsq/Makefile @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/14 16:05:12 by gtertysh #+# #+# # +# Updated: 2016/11/15 16:10:36 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = bsq +SRC = src/*.c +INC = headers/ +LIBSRC = lib_src/*.c +LIB = libft.a +FLAGS = -Wall -Werror -Wextra + +all: $(LIB) $(NAME) + +$(NAME): + gcc $(FLAGS) $(SRC) -I $(INC) -o $(NAME) -L . -lft + +$(LIB): + gcc -c $(FLAGS) $(LIBSRC) -I $(INC) + ar cr $(LIB) *.o + +clean: + rm -f *.o + +fclean: clean + rm -f $(NAME) $(LIB) + +re: fclean all diff --git a/my_bsq/headers/ft.h b/my_bsq/headers/ft.h new file mode 100644 index 0000000..9dcc726 --- /dev/null +++ b/my_bsq/headers/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:12:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/my_bsq/lib_src/ft_atoi.c b/my_bsq/lib_src/ft_atoi.c new file mode 100644 index 0000000..65189f7 --- /dev/null +++ b/my_bsq/lib_src/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 16:20:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/my_bsq/lib_src/ft_putchar.c b/my_bsq/lib_src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/my_bsq/lib_src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/my_bsq/lib_src/ft_putnbr.c b/my_bsq/lib_src/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/my_bsq/lib_src/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/my_bsq/lib_src/ft_putstr.c b/my_bsq/lib_src/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/my_bsq/lib_src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/my_bsq/lib_src/ft_str_is_alpha.c b/my_bsq/lib_src/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_lowercase.c b/my_bsq/lib_src/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_numeric.c b/my_bsq/lib_src/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_printable.c b/my_bsq/lib_src/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_uppercase.c b/my_bsq/lib_src/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_strcapitalize.c b/my_bsq/lib_src/ft_strcapitalize.c new file mode 100644 index 0000000..83fbea2 --- /dev/null +++ b/my_bsq/lib_src/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 16:18:12 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/my_bsq/lib_src/ft_strcat.c b/my_bsq/lib_src/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/my_bsq/lib_src/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/my_bsq/lib_src/ft_strcmp.c b/my_bsq/lib_src/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/my_bsq/lib_src/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/my_bsq/lib_src/ft_strcpy.c b/my_bsq/lib_src/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/my_bsq/lib_src/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/my_bsq/lib_src/ft_strlen.c b/my_bsq/lib_src/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/my_bsq/lib_src/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/my_bsq/lib_src/ft_strlowcase.c b/my_bsq/lib_src/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/my_bsq/lib_src/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/my_bsq/lib_src/ft_strncmp.c b/my_bsq/lib_src/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/my_bsq/lib_src/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/my_bsq/lib_src/ft_strncpy.c b/my_bsq/lib_src/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/my_bsq/lib_src/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/my_bsq/lib_src/ft_strstr.c b/my_bsq/lib_src/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/my_bsq/lib_src/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/my_bsq/lib_src/ft_strupcase.c b/my_bsq/lib_src/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/my_bsq/lib_src/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/my_bsq/lib_src/ft_swap.c b/my_bsq/lib_src/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/my_bsq/lib_src/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/my_bsq/map_gen.pl b/my_bsq/map_gen.pl new file mode 100755 index 0000000..a72422f --- /dev/null +++ b/my_bsq/map_gen.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; + +die "program x y density" unless (scalar(@ARGV) == 3); +my ($x, $y, $density) = @ARGV; +print "$y.ox\n"; +for (my $i = 0; $i < $y; $i++) { + for (my $j = 0; $j < $x; $j++) { + if (int(rand($y) * 2) < $density) { + print "o"; + } + else { + print "."; + } + } + print "\n"; +} diff --git a/my_bsq/src/main.c b/my_bsq/src/main.c new file mode 100644 index 0000000..56f56d1 --- /dev/null +++ b/my_bsq/src/main.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 16:17:17 by gtertysh #+# #+# */ +/* Updated: 2016/11/16 13:29:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include +#include +#include +#include + +# define BUF_S 131072 + +char *char_realloc(char *old, unsigned int size) +{ + char *new_p; + + new_p = malloc(size); + ft_strcpy(new_p, old); + free(old); + return (new_p); +} + +char *read_in(int type, char *path) +{ + int fd; + int readed; + char buf[BUF_S + 1]; + char *input; + int old_size; + + old_size = 0; + if (type == 3) + { + fd = open(path, O_RDONLY); + if (fd == -1) + return (0); + } + else + fd = 0; + input = malloc(sizeof(char)); + while ((readed = read(fd, buf, BUF_S))) + { + + buf[readed] = '\0'; + old_size = ft_strlen(input); + input = char_realloc(input, old_size + readed + 1); + ft_strcat(input, buf); + } + return (input); +} + +int main(int argc, char **argv) +{ + char *input_string; + int i; + + i = 1; + input_string = 0; + if (argc >= 2) + { + while (i < argc) + { + input_string = read_in(3, argv[i]); + //ft_putstr(input_string); + //free(input_string); + i++; + } + } + else + { + input_string = read_in(0, 0); + //ft_putstr(input_string); + free(input_string); + } + //while(1); + return (0); +} diff --git a/rushes/rush00/ex00/ft_putchar.c b/rushes/rush00/ex00/ft_putchar.c new file mode 100644 index 0000000..2414190 --- /dev/null +++ b/rushes/rush00/ex00/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 14:20:03 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 14:20:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/rushes/rush00/ex00/main.c b/rushes/rush00/ex00/main.c new file mode 100644 index 0000000..5bd2ed4 --- /dev/null +++ b/rushes/rush00/ex00/main.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 11:13:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:05:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +int ft_putchar(char c); +int ft_atoi(char *str); +void rush(int x, int y); + +int main(int argc, char **argv) +{ + int x; + int y; + + if (argc != 3) + return (0); + x = ft_atoi(argv[1]); + y = ft_atoi(argv[2]); + rush(x, y); + return (0); +} diff --git a/rushes/rush00/ex00/rush00.c b/rushes/rush00/ex00/rush00.c new file mode 100644 index 0000000..197fe1a --- /dev/null +++ b/rushes/rush00/ex00/rush00.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 17:45:41 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('o'); + else if (j == x && i == 1) + ft_putchar('o'); + else if (j == 1 && i == y) + ft_putchar('o'); + else if (j == x && i == y) + ft_putchar('o'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('-'); + else + ft_putchar('|'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush01.c b/rushes/rush00/ex00/rush01.c new file mode 100644 index 0000000..5de961b --- /dev/null +++ b/rushes/rush00/ex00/rush01.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 14:57:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('/'); + else if (j == x && i == 1) + ft_putchar('\\'); + else if (j == 1 && i == y) + ft_putchar('\\'); + else if (j == x && i == y) + ft_putchar('/'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('*'); + else + ft_putchar('*'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush02.c b/rushes/rush00/ex00/rush02.c new file mode 100644 index 0000000..0e8273d --- /dev/null +++ b/rushes/rush00/ex00/rush02.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 15:27:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('A'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush03.c b/rushes/rush00/ex00/rush03.c new file mode 100644 index 0000000..4fedea1 --- /dev/null +++ b/rushes/rush00/ex00/rush03.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 15:31:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('A'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush04.c b/rushes/rush00/ex00/rush04.c new file mode 100644 index 0000000..b5325c0 --- /dev/null +++ b/rushes/rush00/ex00/rush04.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 17:00:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('A'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/Makefile b/rushes/rush02/ex00/Makefile new file mode 100644 index 0000000..d78325d --- /dev/null +++ b/rushes/rush02/ex00/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/12 13:37:10 by gtertysh #+# #+# # +# Updated: 2016/11/13 21:51:43 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +RUSH2 = rush-2 +RUSH0 = rush-0 +RUSH0SRC = src-rush-00/ +RUSH2SRC = src-rush-02/*.c +INC = headers/ +LIB = lib/ +BIN = bin/ +FLAGS = -Wall -Werror -Wextra + +all: $(RUSH2) $(RUSH0) + +$(RUSH2): + @gcc $(FLAGS) $(RUSH2SRC) -I $(INC) -o $(BIN)$(RUSH2) -L $(LIB) -lft + +$(RUSH0): + @for number in 0 1 2 3 4 ; do \ + gcc $(FLAGS) $(RUSH0SRC)main.c $(RUSH0SRC)rush0$$number.c \ + -I $(INC) -o $(BIN)$(RUSH0)$$number -L $(LIB) -lft ; \ + done + +fclean: + @rm -f $(BIN)* + +re: fclean all diff --git a/rushes/rush02/ex00/bin/rush-00 b/rushes/rush02/ex00/bin/rush-00 new file mode 100755 index 0000000..cf081ad Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-00 differ diff --git a/rushes/rush02/ex00/bin/rush-01 b/rushes/rush02/ex00/bin/rush-01 new file mode 100755 index 0000000..51b2304 Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-01 differ diff --git a/rushes/rush02/ex00/bin/rush-02 b/rushes/rush02/ex00/bin/rush-02 new file mode 100755 index 0000000..92944ef Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-02 differ diff --git a/rushes/rush02/ex00/bin/rush-03 b/rushes/rush02/ex00/bin/rush-03 new file mode 100755 index 0000000..abbcde8 Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-03 differ diff --git a/rushes/rush02/ex00/bin/rush-04 b/rushes/rush02/ex00/bin/rush-04 new file mode 100755 index 0000000..40f5cf4 Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-04 differ diff --git a/rushes/rush02/ex00/bin/rush-2 b/rushes/rush02/ex00/bin/rush-2 new file mode 100755 index 0000000..7925b2f Binary files /dev/null and b/rushes/rush02/ex00/bin/rush-2 differ diff --git a/rushes/rush02/ex00/headers/ft.h b/rushes/rush02/ex00/headers/ft.h new file mode 100644 index 0000000..9dcc726 --- /dev/null +++ b/rushes/rush02/ex00/headers/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:12:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/rushes/rush02/ex00/headers/rush00.h b/rushes/rush02/ex00/headers/rush00.h new file mode 100644 index 0000000..20e76ae --- /dev/null +++ b/rushes/rush02/ex00/headers/rush00.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:15:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:16:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RUSH00_H +# define RUSH00_H + +void rush(int x, int y); + +#endif diff --git a/rushes/rush02/ex00/headers/rush02.h b/rushes/rush02/ex00/headers/rush02.h new file mode 100644 index 0000000..81d9d04 --- /dev/null +++ b/rushes/rush02/ex00/headers/rush02.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:16:44 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:44:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RUSH02_H +# define RUSH02_H + +# define BUF_S 8192 + +typedef char (*t_rush)(int *, int, int); + +char *buf_concat(char *old, char *buf, int readed); +char *input_read(void); +int *det_dimensions(char *str); +char *rush_creator(int *dim, t_rush ch); +int *find_rush(char *str, int *dim); +void print_result(int *dim, int *checked); +char ch_rush00(int *dim, int x, int y); +char ch_rush01(int *dim, int x, int y); +char ch_rush02(int *dim, int x, int y); +char ch_rush03(int *dim, int x, int y); +char ch_rush04(int *dim, int x, int y); + +#endif diff --git a/rushes/rush02/ex00/lib/libft.a b/rushes/rush02/ex00/lib/libft.a new file mode 100644 index 0000000..e14cca6 Binary files /dev/null and b/rushes/rush02/ex00/lib/libft.a differ diff --git a/rushes/rush02/ex00/src-rush-00/main.c b/rushes/rush02/ex00/src-rush-00/main.c new file mode 100644 index 0000000..063d74c --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/main.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 11:13:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:17:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "rush00.h" +#include "ft.h" + +int main(int argc, char **argv) +{ + int x; + int y; + + if (argc != 3) + return (0); + x = ft_atoi(argv[1]); + y = ft_atoi(argv[2]); + rush(x, y); + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush00.c b/rushes/rush02/ex00/src-rush-00/rush00.c new file mode 100644 index 0000000..6782f81 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush00.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:16:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('o'); + else if (j == x && i == 1) + ft_putchar('o'); + else if (j == 1 && i == y) + ft_putchar('o'); + else if (j == x && i == y) + ft_putchar('o'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('-'); + else + ft_putchar('|'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush01.c b/rushes/rush02/ex00/src-rush-00/rush01.c new file mode 100644 index 0000000..1202116 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush01.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush01.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('/'); + else if (j == x && i == 1) + ft_putchar('\\'); + else if (j == 1 && i == y) + ft_putchar('\\'); + else if (j == x && i == y) + ft_putchar('/'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('*'); + else + ft_putchar('*'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush02.c b/rushes/rush02/ex00/src-rush-00/rush02.c new file mode 100644 index 0000000..9e6012e --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush02.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('A'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush03.c b/rushes/rush02/ex00/src-rush-00/rush03.c new file mode 100644 index 0000000..61e651b --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush03.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush03.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:47 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('A'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush04.c b/rushes/rush02/ex00/src-rush-00/rush04.c new file mode 100644 index 0000000..1d2b429 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush04.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush04.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:18:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:18:04 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('A'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-02/buf_concat.c b/rushes/rush02/ex00/src-rush-02/buf_concat.c new file mode 100644 index 0000000..cc9f4b0 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/buf_concat.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* buf_concat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:19:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:24:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include + +char *buf_concat(char *old, char *buf, int readed) +{ + char *new_ptr; + int old_size; + + old_size = 0; + new_ptr = NULL; + old_size = ft_strlen(old); + new_ptr = malloc(sizeof(char) * (old_size + readed + 1)); + ft_strcat(new_ptr, old); + ft_strcat(new_ptr, buf); + return (new_ptr); +} diff --git a/rushes/rush02/ex00/src-rush-02/det_dimensions.c b/rushes/rush02/ex00/src-rush-02/det_dimensions.c new file mode 100644 index 0000000..6e24b33 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/det_dimensions.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* det_dimensions.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:29:53 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:30:39 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *det_dimensions(char *str) +{ + int *xy; + int i; + + xy = malloc(sizeof(int) * 2); + xy[0] = 0; + xy[1] = 0; + i = 0; + while (str[i]) + { + while (str[i] != '\n') + { + xy[0]++; + i++; + } + break ; + } + i = 0; + while (str[i]) + { + if (str[i] == '\n') + xy[1]++; + i++; + } + return (xy); +} diff --git a/rushes/rush02/ex00/src-rush-02/find_rush.c b/rushes/rush02/ex00/src-rush-02/find_rush.c new file mode 100644 index 0000000..40249e5 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/find_rush.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_rush.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:33:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:50:10 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include "rush02.h" +#include + +int *find_rush(char *str, int *dim) +{ + t_rush rush_func[5]; + int *checked; + int i; + + i = 0; + rush_func[0] = ch_rush00; + rush_func[1] = ch_rush01; + rush_func[2] = ch_rush02; + rush_func[3] = ch_rush03; + rush_func[4] = ch_rush04; + checked = malloc(sizeof(int) * 5); + while (i < 5) + checked[i++] = 1; + if (dim[0] <= 0 || dim[1] <= 0) + return (checked); + i = 0; + while (i < 5) + { + checked[i] = ft_strcmp(str, rush_creator(dim, rush_func[i])); + i++; + } + return (checked); +} diff --git a/rushes/rush02/ex00/src-rush-02/input_read.c b/rushes/rush02/ex00/src-rush-02/input_read.c new file mode 100644 index 0000000..0ccd179 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/input_read.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:10:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "rush02.h" + +char *input_read(void) +{ + char *input; + char buf[BUF_S + 1]; + int readed; + + input = malloc(sizeof(char) * (BUF_S + 1)); + while ((readed = read(0, buf, BUF_S))) + { + buf[readed] = '\0'; + input = buf_concat(input, buf, readed); + } + return (input); +} diff --git a/rushes/rush02/ex00/src-rush-02/main.c b/rushes/rush02/ex00/src-rush-02/main.c new file mode 100644 index 0000000..eca2a94 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:32:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "rush02.h" + +int main(void) +{ + char *in_str; + int *dimensions; + int *checked; + + in_str = input_read(); + dimensions = det_dimensions(in_str); + checked = find_rush(in_str, dimensions); + print_result(dimensions, checked); + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-02/print_result.c b/rushes/rush02/ex00/src-rush-02/print_result.c new file mode 100644 index 0000000..79aa793 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/print_result.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_result.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:34:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 15:02:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void print(int i, int *dim, int *mult, int *wtf) +{ + ft_putstr("[rush-0"); + ft_putnbr(i); + ft_putstr("] ["); + ft_putnbr(dim[0]); + ft_putstr("] ["); + ft_putnbr(dim[1]); + ft_putstr("]"); + *mult = 1; + *wtf = 0; +} + +void print_result(int *dim, int *checked) +{ + int i; + int mult; + int wtf; + + i = 0; + mult = 0; + wtf = 1; + if (dim[0] <= 0 || dim[1] <= 0) + { + ft_putstr("ALL GLORY TO THE HYPNOTOAD\n"); + return ; + } + while (i < 5) + { + if (checked[i] == 0) + { + if (mult != 0) + ft_putstr(" || "); + print(i, dim, &mult, &wtf); + } + i++; + } + if (wtf) + ft_putstr("ALL GLORY TO THE HYPNOTOAD"); + ft_putstr("\n"); +} diff --git a/rushes/rush02/ex00/src-rush-02/rush_creator.c b/rushes/rush02/ex00/src-rush-02/rush_creator.c new file mode 100644 index 0000000..6c07455 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/rush_creator.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 22:17:35 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "rush02.h" + +char *rush_creator(int *dim, t_rush ch) +{ + char *rush; + int x; + int y; + int i; + + rush = malloc(sizeof(char) * (((dim[0] + 1) * dim[1]) + 1)); + x = 0; + y = 0; + i = 0; + if (dim[0] <= 0 || dim[1] <= 0) + return (0); + while (y < dim[1]) + { + x = 0; + while (x < dim[0]) + { + rush[i] = ch(dim, x, y); + i++; + x++; + } + rush[i++] = '\n'; + y++; + } + rush[i] = '\0'; + return (rush); +} diff --git a/rushes/rush02/ex00/src-rush-02/rush_functions.c b/rushes/rush02/ex00/src-rush-02/rush_functions.c new file mode 100644 index 0000000..bdf16fb --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/rush_functions.c @@ -0,0 +1,101 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush_functions.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:08:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 22:08:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char ch_rush00(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('o'); + else if (x == dim[0] - 1 && y == 0) + return ('o'); + else if (x == 0 && y == dim[1] - 1) + return ('o'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('o'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('-'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('|'); + else + return (' '); +} + +char ch_rush01(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('/'); + else if (x == dim[0] - 1 && y == 0) + return ('\\'); + else if (x == 0 && y == dim[1] - 1) + return ('\\'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('/'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('*'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('*'); + else + return (' '); +} + +char ch_rush02(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('A'); + else if (x == 0 && y == dim[1] - 1) + return ('C'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('C'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +} + +char ch_rush03(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('C'); + else if (x == 0 && y == dim[1] - 1) + return ('A'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('C'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +} + +char ch_rush04(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('C'); + else if (x == 0 && y == dim[1] - 1) + return ('C'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('A'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +}