├── Shell_00 ├── ex00 │ └── z ├── ex04 │ └── midLS ├── ex09 │ ├── ft_magic │ └── msg.txt ├── ex05 │ └── git_commit.sh ├── .DS_Store ├── ex06 │ ├── git_ignore.sh │ └── .git_ignore.sh.swp ├── ex08 │ └── clean ├── ex02 │ ├── .DS_Store │ └── exo2.tar ├── ex03 │ ├── .DS_Store │ └── id_rsa_pub ├── ex07 │ └── b └── ex01 │ └── testShell00.tar ├── Shell_01 ├── ex05 │ └── "\?$*'MaRViN'*$?\" ├── ex06 │ └── skip.sh ├── ex07 │ ├── r_dwssap.sh │ └── .r_dwsaap.sh.swp ├── ex03 │ └── count_files.sh ├── ex04 │ ├── MAC.sh │ └── .MAC.sh.swp ├── ex01 │ └── print_groups.sh └── ex02 │ └── find_sh.sh ├── C_00 ├── .DS_Store ├── ex05 │ ├── .ft_print_comb.c.swo │ ├── .ft_print_comb.c.swp │ └── ft_print_comb.c ├── ex00 │ └── ft_putchar.c ├── ex04 │ └── ft_is_negative.c ├── ex01 │ └── ft_print_alphabet.c ├── ex03 │ └── ft_print_numbers.c ├── ex02 │ └── ft_print_reverse_alphabet.c ├── ex07 │ └── ft_putnbr.c ├── ex06 │ └── ft_print_comb2.c └── ex08 │ └── ft_print_combn.c ├── C_09 ├── ex02 │ ├── .tst.swp │ ├── .ft_split.c.swp │ └── ft_split.c ├── ex00 │ ├── libft_creator.sh │ ├── ft_putchar.c │ ├── ft_swap.c │ ├── ft_strlen.c │ ├── ft_putstr.c │ └── ft_strcmp.c └── ex01 │ └── Makefile ├── C_03 ├── .ft_strcmp.c.swp ├── ex00 │ └── ft_strcmp.c ├── ex01 │ └── ft_strncmp.c ├── ex02 │ └── ft_strcat.c ├── ex03 │ └── ft_strncat.c ├── ex04 │ └── ft_strstr.c └── ex05 │ └── ft_strlcat.c ├── C_02 ├── ex01 │ ├── .ft_strncpy.c.swp │ └── ft_strncpy.c ├── ex00 │ └── ft_strcpy.c ├── ex07 │ └── ft_strupcase.c ├── ex08 │ └── ft_strlowcase.c ├── ex03 │ └── ft_str_is_numeric.c ├── ex06 │ └── ft_str_is_printable.c ├── ex04 │ └── ft_str_is_lowercase.c ├── ex05 │ └── ft_str_is_uppercase.c ├── ex02 │ └── ft_str_is_alpha.c ├── ex10 │ └── ft_strlcpy.c ├── ex11 │ └── ft_putstr_non_printable.c └── ex09 │ └── ft_strcapitalize.c ├── C_11 ├── ex00 │ ├── .ft_foreach.c.swp │ └── ft_foreach.c ├── ex05 │ ├── Makefile │ ├── ft_add.c │ ├── ft_div.c │ ├── ft_mod.c │ ├── ft_mul.c │ ├── ft_sub.c │ ├── do_op.h │ ├── ft_atoi.c │ ├── ft_putnbr.c │ └── do_op.c ├── ex02 │ └── ft_any.c ├── ex04 │ └── ft_is_sort.c ├── ex03 │ └── ft_count_if.c └── ex01 │ └── ft_map.c ├── C_01 ├── ex00 │ └── ft_ft.c ├── ex01 │ └── ft_ultimate_ft.c ├── ex02 │ └── ft_swap.c ├── ex03 │ └── ft_div_mod.c ├── ex06 │ └── ft_strlen.c ├── ex05 │ └── ft_putstr.c ├── ex04 │ └── ft_ultimate_div_mod.c ├── ex07 │ └── ft_rev_int_tab.c └── ex08 │ └── ft_sort_int_tab.c ├── C_04 ├── ex01 │ └── ft_putstr.c ├── ex00 │ └── ft_strlen.c ├── ex02 │ └── ft_putnbr.c ├── ex03 │ └── ft_atoi.c ├── ex04 │ └── ft_putnbr_base.c └── ex05 │ └── ft_atoi_base.c ├── C_08 ├── ex02 │ └── ft_abs.h ├── ex03 │ └── ft_point.h ├── ex00 │ └── ft.h ├── ex01 │ └── ft_boolean.h ├── ex05 │ └── ft_show_tab.c └── ex04 │ └── ft_strs_to_tab.c ├── C_05 ├── ex00 │ └── ft_iterative_factorial.c ├── ex03 │ └── ft_recursive_power.c ├── ex06 │ └── ft_is_prime.c ├── ex02 │ └── ft_iterative_power.c ├── ex01 │ └── ft_recursive_factorial.c ├── ex04 │ └── ft_fibonacci.c ├── ex05 │ └── ft_sqrt.c └── ex07 │ └── ft_find_next_prime.c ├── C_06 ├── ex00 │ └── ft_print_program_name.c ├── ex01 │ └── ft_print_params.c ├── ex02 │ └── ft_rev_params.c └── ex03 │ └── ft_sort_params.c ├── C_07 ├── ex00 │ └── ft_strdup.c ├── ex01 │ └── ft_range.c ├── ex02 │ └── ft_ultimate_range.c ├── ex03 │ └── ft_strjoin.c ├── ex04 │ ├── ft_convert_base2.c │ └── ft_convert_base.c └── ex05 │ └── ft_split.c └── README.md /Shell_00/ex00/z: -------------------------------------------------------------------------------- 1 | Z 2 | -------------------------------------------------------------------------------- /Shell_00/ex04/midLS: -------------------------------------------------------------------------------- 1 | ls -p -t -m 2 | -------------------------------------------------------------------------------- /Shell_01/ex05/"\?$*'MaRViN'*$?\": -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /Shell_00/ex09/ft_magic: -------------------------------------------------------------------------------- 1 | 41 string 42 42 file 2 | -------------------------------------------------------------------------------- /Shell_01/ex06/skip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ls -l | awk 'NR % 2 == 1' 3 | -------------------------------------------------------------------------------- /Shell_00/ex05/git_commit.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | git log -n5 --format="%H" 3 | -------------------------------------------------------------------------------- /Shell_00/ex09/msg.txt: -------------------------------------------------------------------------------- 1 | 0123456789012345678901234567890123456789142xcmbx 2 | -------------------------------------------------------------------------------- /Shell_01/ex07/r_dwssap.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | cat /etc/passwd | sed '/^#/d' 3 | -------------------------------------------------------------------------------- /Shell_01/ex03/count_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | find . | wc -l | sed 's/ //g' 4 | -------------------------------------------------------------------------------- /Shell_01/ex04/MAC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | ifconfig | grep -w ether | cut -d " " -f2 3 | -------------------------------------------------------------------------------- /C_00/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_00/.DS_Store -------------------------------------------------------------------------------- /Shell_01/ex01/print_groups.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | id -nG $FT_USER | tr ' ' ',' | tr -d '\n' 3 | -------------------------------------------------------------------------------- /C_09/ex02/.tst.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_09/ex02/.tst.swp -------------------------------------------------------------------------------- /Shell_00/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_00/.DS_Store -------------------------------------------------------------------------------- /Shell_01/ex02/find_sh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | find . -type f -name "*.sh" -exec basename {} .sh \; 3 | -------------------------------------------------------------------------------- /C_03/.ft_strcmp.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_03/.ft_strcmp.c.swp -------------------------------------------------------------------------------- /Shell_00/ex06/git_ignore.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | git ls-files --ignored --exclude-standard --others 4 | -------------------------------------------------------------------------------- /Shell_00/ex08/clean: -------------------------------------------------------------------------------- 1 | find . -name "#*#" -type f -print -delete -o -name "*~" -type f -print -delete 2 | -------------------------------------------------------------------------------- /Shell_00/ex02/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_00/ex02/.DS_Store -------------------------------------------------------------------------------- /Shell_00/ex03/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_00/ex03/.DS_Store -------------------------------------------------------------------------------- /C_09/ex02/.ft_split.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_09/ex02/.ft_split.c.swp -------------------------------------------------------------------------------- /Shell_01/ex04/.MAC.sh.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_01/ex04/.MAC.sh.swp -------------------------------------------------------------------------------- /C_02/ex01/.ft_strncpy.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_02/ex01/.ft_strncpy.c.swp -------------------------------------------------------------------------------- /C_11/ex00/.ft_foreach.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_11/ex00/.ft_foreach.c.swp -------------------------------------------------------------------------------- /C_00/ex05/.ft_print_comb.c.swo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_00/ex05/.ft_print_comb.c.swo -------------------------------------------------------------------------------- /C_00/ex05/.ft_print_comb.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/C_00/ex05/.ft_print_comb.c.swp -------------------------------------------------------------------------------- /Shell_01/ex07/.r_dwsaap.sh.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_01/ex07/.r_dwsaap.sh.swp -------------------------------------------------------------------------------- /Shell_00/ex06/.git_ignore.sh.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mohcine-Ghalmi/POOL_2022/HEAD/Shell_00/ex06/.git_ignore.sh.swp -------------------------------------------------------------------------------- /C_09/ex00/libft_creator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -Wall -Wextra -Werror -c ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c 3 | ar -rc libft.a ft_putchar.o ft_putstr.o ft_strcmp.o ft_strlen.o ft_swap.o 4 | -------------------------------------------------------------------------------- /C_11/ex05/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = do_op.c ft_add.c ft_sub.c ft_mul.c ft_mod.c ft_atoi.c ft_div.c ft_putnbr.c 2 | OBJS = ${SRCS:.c=.o} 3 | NAME = do-op 4 | CC = gcc 5 | RM = rm -f 6 | CFLAGS = -Wall -Wextra -Werror 7 | 8 | all: 9 | ${CC} ${CFLAGS} ${SRCS} -o ${NAME} 10 | 11 | clean : 12 | ${RM} ${OBJS} 13 | 14 | fclean : 15 | ${RM} ${NAME} 16 | 17 | re : fclean all 18 | -------------------------------------------------------------------------------- /Shell_00/ex03/id_rsa_pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDVXG4BpFPAjKHv8jsszRLJ3EGh5ho9NVwvb5MXaQ8Ln+KRlpXELD/1RdE05qDbvGEXy2jnfNNuiXpcd1kC5fYCgK2GCNE9irUUwUuShYDTn2iR6iMr/6JNw5p3Atp9H9QzCCOQnS9S14YFybn28yC+ESHVLTVHx/uI+P7beWYuro5OIvzXRj1agasRqes0qw+vpkzrKHRqmvPjSkzZHxJ5X5a0I1j8rnouPhA9qFlTXKzqu1DKogAY3DnLNqax+UQvyA1rEVWojdwSAAK7nwTn0hzZ7BdOKRtI43WT6jgLV2b4xg3JSfM8FDLd9MmFnLeLi5MUCgrF28TpYlh78NJb mohcin.ghalmi@gmail.com 2 | -------------------------------------------------------------------------------- /C_09/ex01/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = srcs/ft_putchar.c srcs/ft_putstr.c srcs/ft_strlen.c srcs/ft_strcmp.c srcs/ft_swap.c 2 | OBJS = ${SRCS:.c=.o} 3 | INCS = includes 4 | NAME = libft.a 5 | LIBC = ar -rc 6 | LIBR = ranlib 7 | CC = gcc 8 | RM = rm -f 9 | CFLAGS = -Wall -Wextra -Werror 10 | 11 | .c.o: 12 | ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} -I ${INCS} 13 | 14 | ${NAME}: ${OBJS} 15 | ${LIBC} ${NAME} ${OBJS} 16 | ${LIBR} ${NAME} 17 | 18 | all: ${NAME} 19 | 20 | clean: 21 | ${RM} ${OBJS} 22 | 23 | fclean: clean 24 | ${RM} ${NAME} 25 | 26 | re: fclean all 27 | -------------------------------------------------------------------------------- /Shell_00/ex07/b: -------------------------------------------------------------------------------- 1 | Episode V, A NEW H0PE It is a period of civil war 2 | Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. 3 | 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. 4 | 5 | 6 | Pursued by the Empire's sinister agents, 7 | Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie.. 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /C_11/ex05/ft_add.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_add.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 10:57:16 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 10:57:38 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_add(int a, int b) 14 | { 15 | return (a + b); 16 | } 17 | -------------------------------------------------------------------------------- /C_11/ex05/ft_div.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_div.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 11:25:36 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 11:25:56 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_div(int a, int b) 14 | { 15 | return (a / b); 16 | } 17 | -------------------------------------------------------------------------------- /C_11/ex05/ft_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 11:34:04 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 11:35:29 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_mod(int a, int b) 14 | { 15 | return (a % b); 16 | } 17 | -------------------------------------------------------------------------------- /C_11/ex05/ft_mul.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_mul.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 11:36:46 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 11:37:13 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_mul(int a, int b) 14 | { 15 | return (a * b); 16 | } 17 | -------------------------------------------------------------------------------- /C_11/ex05/ft_sub.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sub.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 11:35:58 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 11:36:23 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_sub(int a, int b) 14 | { 15 | return (a / b); 16 | } 17 | -------------------------------------------------------------------------------- /C_01/ex00/ft_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 15:58:32 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 15:58:34 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_ft(int *nbr) 16 | { 17 | *nbr = 42; 18 | } 19 | -------------------------------------------------------------------------------- /C_00/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:06:47 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 09:08:30 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /C_09/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 19:09:12 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/08 16:51:42 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write (1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /C_09/ex00/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 19:09:33 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 19:09:42 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_swap(int *a, int *b) 14 | { 15 | int tmp; 16 | 17 | tmp = *a; 18 | *a = *b; 19 | *b = tmp; 20 | } 21 | -------------------------------------------------------------------------------- /C_01/ex01/ft_ultimate_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 15:59:29 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 16:07:26 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_ultimate_ft(int *********nbr) 16 | { 17 | *********nbr = 42; 18 | } 19 | -------------------------------------------------------------------------------- /C_04/ex01/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/26 11:05:15 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/26 11:08:22 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str) 18 | write(1, str++, 1); 19 | } 20 | -------------------------------------------------------------------------------- /C_08/ex02/ft_abs.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_abs.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 15:09:57 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 17:30:55 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_ABS_H 14 | # define FT_ABS_H 15 | 16 | # define ABS(Value) (Value < 0 ? -Value : Value) 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /C_01/ex02/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 16:15:10 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 16:19:37 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_swap(int *a, int *b) 16 | { 17 | int temp; 18 | 19 | temp = *a; 20 | *a = *b; 21 | *b = temp; 22 | } 23 | -------------------------------------------------------------------------------- /C_08/ex03/ft_point.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_point.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 17:25:54 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 17:29:44 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_POINT_H 14 | # define FT_POINT_H 15 | 16 | typedef struct s_point 17 | { 18 | int x; 19 | int y; 20 | } t_point; 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /C_09/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 19:10:47 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 19:10:58 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i] != '\0') 19 | { 20 | i++; 21 | } 22 | return (i); 23 | } 24 | -------------------------------------------------------------------------------- /C_01/ex03/ft_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 19:00:14 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 19:06:45 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_div_mod(int a, int b, int *div, int *mod) 16 | { 17 | if (b > 0) 18 | { 19 | *div = a / b; 20 | *mod = a % b; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /C_04/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/26 11:02:16 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/26 11:04:20 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *str) 16 | { 17 | int count; 18 | 19 | count = 0; 20 | while (str[count]) 21 | count++; 22 | return (count); 23 | } 24 | -------------------------------------------------------------------------------- /C_11/ex00/ft_foreach.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_foreach.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/09 16:01:59 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/09 20:03:10 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_foreach(int *tab, int length, void (*f) (int)) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (i < length) 19 | { 20 | f(tab[i]); 21 | i++; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /C_01/ex06/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 19:37:19 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 19:43:16 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *str) 16 | { 17 | int count; 18 | 19 | count = 0; 20 | while (*str++) 21 | { 22 | count++; 23 | } 24 | return (count); 25 | } 26 | -------------------------------------------------------------------------------- /C_09/ex00/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 19:09:52 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 19:10:04 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | { 22 | write (1, &str[i], 1); 23 | i++; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /C_11/ex02/ft_any.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_any.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/09 21:53:23 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/09 21:55:03 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_any(char **tab, int (*f)(char*)) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (tab[i] != '\0') 19 | { 20 | if (f(tab[i])) 21 | return (1); 22 | i++; 23 | } 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /C_01/ex05/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 19:36:24 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 19:36:41 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putstr(char *str) 21 | { 22 | while (*str) 23 | { 24 | ft_putchar(*str++); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /C_01/ex04/ft_ultimate_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 19:16:30 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 19:17:30 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_ultimate_div_mod(int *a, int *b) 16 | { 17 | int dev; 18 | 19 | if (b > 0) 20 | { 21 | dev = *a / *b; 22 | *b = *a % *b; 23 | *a = dev; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /C_09/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 19:11:10 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 19:11:18 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(char *s1, char *s2) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | while (s1[i] == s2[i] && s1[i] != '\0' && s2[i] != '\0') 19 | { 20 | i++; 21 | } 22 | return (s1[i] - s2[i]); 23 | } 24 | -------------------------------------------------------------------------------- /C_08/ex00/ft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 13:17:27 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 15:13:20 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_H 14 | # define FT_H 15 | 16 | void ft_putchar(char c); 17 | void ft_swap(int *a, int *b); 18 | void ft_putstr(char *str); 19 | int ft_strlen(char *str); 20 | int ft_strcmp(char *s1, char *s2); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /C_05/ex00/ft_iterative_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 09:45:38 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 09:53:14 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_iterative_factorial(int nb) 16 | { 17 | int res; 18 | 19 | res = 1; 20 | if (nb < 0) 21 | return (0); 22 | while (nb) 23 | res = res * nb--; 24 | return (res); 25 | } 26 | -------------------------------------------------------------------------------- /C_00/ex04/ft_is_negative.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_negative.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:26:10 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 09:29:15 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_is_negative(int n) 21 | { 22 | if (n < 0) 23 | ft_putchar('N'); 24 | if (n >= 0) 25 | ft_putchar('P'); 26 | } 27 | -------------------------------------------------------------------------------- /C_05/ex03/ft_recursive_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 11:11:24 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/30 22:27:35 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_recursive_power(int nb, int power) 16 | { 17 | if (!power) 18 | return (1); 19 | else if (power < 0) 20 | return (0); 21 | return (nb * ft_recursive_power(nb, power - 1)); 22 | } 23 | -------------------------------------------------------------------------------- /C_02/ex00/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 09:59:31 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/22 12:05:36 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strcpy(char *dest, char *src) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (src[i] != '\0') 21 | { 22 | dest[i] = src[i]; 23 | i++; 24 | } 25 | dest[i] = '\0'; 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /C_11/ex04/ft_is_sort.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_sort.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/09 22:25:06 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/09 22:58:05 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_sort(int *tab, int length, int (*f)(int, int)) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (i < length - 1) 19 | { 20 | if ((*f)(tab[i], tab[i + 1]) > 0) 21 | return (0); 22 | i++; 23 | } 24 | return (1); 25 | } 26 | -------------------------------------------------------------------------------- /C_02/ex07/ft_strupcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strupcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/23 12:20:23 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 16:09:18 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strupcase(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= 'a' && str[i] <= 'z') 23 | str[i] = str[i] - 32; 24 | i++; 25 | } 26 | return (str); 27 | } 28 | -------------------------------------------------------------------------------- /C_02/ex08/ft_strlowcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlowcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/23 13:06:08 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/23 13:10:14 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strlowcase(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= 'A' && str[i] <= 'Z') 23 | str[i] = str[i] + 32; 24 | i++; 25 | } 26 | return (str); 27 | } 28 | -------------------------------------------------------------------------------- /C_05/ex06/ft_is_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 12:24:54 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 12:35:38 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_is_prime(int nb) 16 | { 17 | int i; 18 | 19 | i = 2; 20 | if (nb < 2) 21 | return (0); 22 | while (i <= nb / 2) 23 | { 24 | if (nb % i == 0) 25 | return (0); 26 | i++; 27 | } 28 | return (1); 29 | } 30 | -------------------------------------------------------------------------------- /C_11/ex03/ft_count_if.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_count_if.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/09 22:18:52 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/09 22:24:35 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_count_if(char **tab, int length, int (*f)(char*)) 14 | { 15 | int i; 16 | int count; 17 | 18 | count = 0; 19 | i = 0; 20 | while (i < length) 21 | { 22 | if ((*f)(tab[i])) 23 | count++; 24 | i++; 25 | } 26 | return (count); 27 | } 28 | -------------------------------------------------------------------------------- /C_00/ex01/ft_print_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:09:06 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 09:18:08 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_alphabet(void) 21 | { 22 | char c; 23 | 24 | c = 'a'; 25 | while (c <= 'z') 26 | { 27 | ft_putchar(c); 28 | c++; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /C_00/ex03/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_numbers.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:22:49 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 09:25:31 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_numbers(void) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (i <= 9) 26 | { 27 | ft_putchar(i + '0'); 28 | i++; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /C_02/ex03/ft_str_is_numeric.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_numeric.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 21:39:17 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/22 21:40:43 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_str_is_numeric(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= '0' && str[i] <= '9') 23 | i++; 24 | else 25 | return (0); 26 | } 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /C_02/ex06/ft_str_is_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 21:52:28 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/23 12:13:28 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_str_is_printable(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= 31 && str[i] <= 126) 23 | i++; 24 | else 25 | return (0); 26 | } 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /C_02/ex04/ft_str_is_lowercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_lowercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 21:41:19 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/22 21:42:18 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_str_is_lowercase(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= 'a' && str[i] <= 'z') 23 | i++; 24 | else 25 | return (0); 26 | } 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /C_02/ex05/ft_str_is_uppercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_uppercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 21:46:32 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/23 23:24:08 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_str_is_uppercase(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if (str[i] >= 'A' && str[i] <= 'Z') 23 | i++; 24 | else 25 | return (0); 26 | } 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /C_05/ex02/ft_iterative_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 11:00:49 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 11:10:36 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_iterative_power(int nb, int power) 16 | { 17 | int res; 18 | 19 | res = 1; 20 | if (power < 0) 21 | return (0); 22 | while (power > 0) 23 | { 24 | res *= nb; 25 | power--; 26 | } 27 | return (res); 28 | } 29 | -------------------------------------------------------------------------------- /C_05/ex01/ft_recursive_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 10:04:48 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 10:58:24 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_recursive_factorial(int nb) 16 | { 17 | int res; 18 | 19 | res = 1; 20 | if (nb < 0) 21 | return (0); 22 | if (nb < 2) 23 | return (1); 24 | res = nb * ft_recursive_factorial(nb - 1); 25 | return (res); 26 | } 27 | -------------------------------------------------------------------------------- /C_06/ex00/ft_print_program_name.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_program_name.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 14:39:02 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/30 12:24:47 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str) 18 | write(1, str++, 1); 19 | write(1, "\n", 1); 20 | } 21 | 22 | int main(int ac, char **arv) 23 | { 24 | if (ac == 1) 25 | ft_putstr(arv[0]); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /C_11/ex05/do_op.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* do_op.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 10:55:27 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 19:20:00 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DO_OP_H 14 | # define DO_OP_H 15 | 16 | int ft_add(int a, int b); 17 | int ft_sub(int a, int b); 18 | int ft_mod(int a, int b); 19 | int ft_div(int a, int b); 20 | int ft_mul(int a, int b); 21 | int ft_atoi(char *str); 22 | void ft_putnbr(int nb); 23 | #endif 24 | -------------------------------------------------------------------------------- /C_00/ex02/ft_print_reverse_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_reverse_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:20:09 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 09:22:17 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_reverse_alphabet(void) 21 | { 22 | char c ; 23 | 24 | c = 'z'; 25 | while (c >= 'a') 26 | { 27 | ft_putchar(c); 28 | c--; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /C_03/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 15:13:08 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 15:30:11 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_strcmp(char *s1, char *s2) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (s1[i] && s2[i]) 22 | { 23 | if (s1[i] == s2[i]) 24 | i++; 25 | else 26 | break ; 27 | } 28 | return (s1[i] - s2[i]); 29 | } 30 | -------------------------------------------------------------------------------- /C_05/ex04/ft_fibonacci.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_fibonacci.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 11:27:01 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 12:09:09 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_fibonacci(int index) 16 | { 17 | int res; 18 | 19 | res = 0; 20 | if (index < 0) 21 | return (-1); 22 | else if (index < 2) 23 | return (index); 24 | res = ft_fibonacci(index - 1) + ft_fibonacci(index - 2); 25 | return (res); 26 | } 27 | -------------------------------------------------------------------------------- /C_02/ex02/ft_str_is_alpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_alpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 21:34:20 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/22 21:38:34 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_str_is_alpha(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | if ((str[i] >= 'a' && str[i] <= 'z') 23 | || (str[i] >= 'A' && str[i] <= 'Z')) 24 | i++; 25 | else 26 | return (0); 27 | } 28 | return (1); 29 | } 30 | -------------------------------------------------------------------------------- /C_01/ex07/ft_rev_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 19:45:17 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/24 03:14:49 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_rev_int_tab(int *tab, int size) 16 | { 17 | int start; 18 | int end; 19 | int tmp; 20 | 21 | start = 0; 22 | end = size -1; 23 | while (start < end) 24 | { 25 | tmp = tab[start]; 26 | tab[start++] = tab[end]; 27 | tab[end--] = tmp; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /C_03/ex01/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 15:32:46 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 16:35:16 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strncmp(char *s1, char *s2, unsigned int n) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (s1[i] && s2[i] && (s1[i] == s2[i]) && n) 21 | { 22 | i++; 23 | n--; 24 | } 25 | if (n == 0) 26 | return (0); 27 | else 28 | return (s1[i] - s2[i]); 29 | } 30 | -------------------------------------------------------------------------------- /C_02/ex01/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/22 20:29:49 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/24 05:26:25 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncpy(char *dest, char *src, unsigned int n) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (src[i] != '\0' && i < n) 21 | { 22 | dest[i] = src[i]; 23 | i++; 24 | } 25 | while (i < n) 26 | { 27 | dest[i] = '\0'; 28 | i++; 29 | } 30 | return (dest); 31 | } 32 | -------------------------------------------------------------------------------- /C_06/ex01/ft_print_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 14:44:00 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 14:55:56 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str) 18 | write(1, str++, 1); 19 | write(1, "\n", 1); 20 | } 21 | 22 | int main(int ac, char **arv) 23 | { 24 | int i; 25 | 26 | i = 1; 27 | while (i < ac) 28 | { 29 | ft_putstr(arv[i]); 30 | i++; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /C_06/ex02/ft_rev_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 14:53:17 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 14:56:18 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str) 18 | write(1, str++, 1); 19 | write(1, "\n", 1); 20 | } 21 | 22 | int main(int ac, char **arv) 23 | { 24 | int i; 25 | 26 | i = ac - 1; 27 | while (i > 0) 28 | { 29 | ft_putstr(arv[i]); 30 | i--; 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /C_11/ex01/ft_map.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_map.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/09 20:07:10 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/09 20:15:43 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int *ft_map(int *tab, int length, int (*f)(int)) 17 | { 18 | int i; 19 | int *res; 20 | 21 | res = malloc(length * sizeof(int)); 22 | if (!res) 23 | return (0); 24 | i = 0; 25 | while (i < length) 26 | { 27 | res[i] = (*f)(tab[i]); 28 | i++; 29 | } 30 | return (res); 31 | } 32 | -------------------------------------------------------------------------------- /C_07/ex00/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 19:13:17 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 19:44:30 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strdup(char *src) 16 | { 17 | char *cp; 18 | int i; 19 | 20 | i = 0; 21 | while (src[i]) 22 | i++; 23 | cp = (char *) malloc((sizeof(char) * i) + 1); 24 | if (!cp) 25 | return (NULL); 26 | i = 0; 27 | while (src[i]) 28 | { 29 | cp[i] = src[i]; 30 | i++; 31 | } 32 | cp[i] = '\0'; 33 | return (cp); 34 | } 35 | -------------------------------------------------------------------------------- /C_03/ex02/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 16:35:41 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 17:07:05 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | char *ft_strcat(char *dest, char *src) 17 | { 18 | int i; 19 | int j; 20 | 21 | i = 0; 22 | j = 0; 23 | if (!dest || !src) 24 | return (dest); 25 | while (dest[i]) 26 | i++; 27 | while (src[j]) 28 | { 29 | dest[i + j] = src[j]; 30 | j++; 31 | } 32 | dest[i + j] = '\0'; 33 | return (dest); 34 | } 35 | -------------------------------------------------------------------------------- /C_00/ex07/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 10:20:37 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/23 20:16:24 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putnbr(int nb) 21 | { 22 | unsigned int n; 23 | 24 | n = nb; 25 | if (nb < 0) 26 | { 27 | ft_putchar('-'); 28 | n *= -1; 29 | } 30 | if (n < 10) 31 | ft_putchar(n + '0'); 32 | else 33 | { 34 | ft_putnbr(n / 10); 35 | ft_putnbr(n % 10); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /C_04/ex02/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/26 11:13:36 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/26 11:15:03 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putnbr(int nb) 21 | { 22 | unsigned int n; 23 | 24 | n = nb; 25 | if (nb < 0) 26 | { 27 | ft_putchar('-'); 28 | n *= -1; 29 | } 30 | if (n < 10) 31 | ft_putchar(n + '0'); 32 | else 33 | { 34 | ft_putnbr(n / 10); 35 | ft_putnbr(n % 10); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /C_03/ex03/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 17:23:46 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 18:13:54 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strncat(char *dest, char *src, unsigned int nb) 16 | { 17 | unsigned int i; 18 | unsigned int j; 19 | 20 | i = 0; 21 | j = 0; 22 | if (!src || !dest) 23 | return (dest); 24 | while (dest[i]) 25 | i++; 26 | while (src[j] && j < nb) 27 | { 28 | dest[i + j] = src[j]; 29 | j++; 30 | } 31 | dest[j + i] = '\0'; 32 | return (dest); 33 | } 34 | -------------------------------------------------------------------------------- /C_07/ex01/ft_range.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_range.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 21:05:59 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 10:07:14 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int *ft_range(int min, int max) 17 | { 18 | int i; 19 | int *result; 20 | 21 | if (min >= max) 22 | return (NULL); 23 | i = max - min; 24 | result = (int *)malloc(sizeof(int) * i); 25 | if (result == NULL) 26 | return (NULL); 27 | i = 0; 28 | while (max > min) 29 | { 30 | result[i] = min++; 31 | i++; 32 | } 33 | return (result); 34 | } 35 | -------------------------------------------------------------------------------- /C_03/ex04/ft_strstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 18:14:37 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 20:15:47 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | char *ft_strstr(char *str, char *to_find) 16 | { 17 | int i; 18 | int j; 19 | 20 | if (to_find[0] == '\0') 21 | return (str); 22 | i = 0; 23 | while (str[i]) 24 | { 25 | j = 0; 26 | while (str[i + j] == to_find[j]) 27 | { 28 | if (to_find[j + 1] == '\0') 29 | return (str + i); 30 | else 31 | j++; 32 | } 33 | i++; 34 | } 35 | return (NULL); 36 | } 37 | -------------------------------------------------------------------------------- /C_05/ex05/ft_sqrt.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sqrt.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 12:09:55 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/30 22:29:02 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_power(int nb, int power) 14 | { 15 | if (!power) 16 | return (1); 17 | else if (power < 0) 18 | return (0); 19 | return (nb * ft_power(nb, power - 1)); 20 | } 21 | 22 | int ft_sqrt(int nb) 23 | { 24 | int sqr; 25 | 26 | sqr = 1; 27 | if (nb > 0) 28 | { 29 | while (sqr <= 46360) 30 | { 31 | if (ft_power(sqr, 2) == nb) 32 | return (sqr); 33 | sqr++; 34 | } 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /C_08/ex01/ft_boolean.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_boolean.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 14:49:08 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 15:13:13 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BOOLEAN_H 14 | # define FT_BOOLEAN_H 15 | 16 | # include 17 | 18 | typedef enum a_bool{ 19 | false = 0, 20 | true = 1, 21 | } t_bool; 22 | 23 | # define FALSE false 24 | # define TRUE true 25 | # define EVEN(number) (number % 2 == 0) 26 | # define EVEN_MSG "I have an even number of arguments.\n" 27 | # define ODD_MSG "I have an odd number of arguments.\n" 28 | # define SUCCESS 0 29 | #endif 30 | -------------------------------------------------------------------------------- /C_02/ex10/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/23 17:28:34 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/23 17:31:42 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) 16 | { 17 | unsigned int len; 18 | unsigned int i; 19 | 20 | len = 0; 21 | i = 0; 22 | while (src[i++]) 23 | { 24 | len++; 25 | } 26 | if (size == 0) 27 | return (len); 28 | i = 0; 29 | while (src[i] && i < size - 1) 30 | { 31 | dest[i] = src[i]; 32 | i++; 33 | } 34 | dest[i] = '\0'; 35 | return (len); 36 | } 37 | -------------------------------------------------------------------------------- /C_04/ex03/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/26 12:12:18 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/26 12:29:56 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_atoi(char *str) 16 | { 17 | int signe; 18 | int res; 19 | 20 | signe = 1; 21 | res = 0; 22 | while (*str == 32 || (*str >= 9 && *str <= 13)) 23 | str++; 24 | while (*str == '-' || *str == '+') 25 | { 26 | if (*str == '-') 27 | signe *= -1; 28 | str++; 29 | } 30 | while (*str >= '0' && *str <= '9') 31 | { 32 | res = res * 10 + *str - '0'; 33 | str++; 34 | } 35 | return (res * signe); 36 | } 37 | -------------------------------------------------------------------------------- /C_05/ex07/ft_find_next_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_find_next_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 12:36:11 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/30 22:33:48 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_is_prime(int nb) 16 | { 17 | int i; 18 | 19 | i = 2; 20 | if (nb < 2) 21 | return (0); 22 | if (nb > 2147483640 && nb >= 2147483647) 23 | return (2147483647); 24 | while (i <= nb / 2) 25 | { 26 | if (nb % i == 0) 27 | return (0); 28 | i++; 29 | } 30 | return (1); 31 | } 32 | 33 | int ft_find_next_prime(int nb) 34 | { 35 | while (!ft_is_prime(nb)) 36 | nb++; 37 | return (nb); 38 | } 39 | -------------------------------------------------------------------------------- /C_11/ex05/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 10:57:54 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 11:23:36 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_atoi(char *str) 14 | { 15 | int sign; 16 | int res; 17 | int i; 18 | 19 | sign = 1; 20 | res = 0; 21 | i = 0; 22 | while (str[i] <= 32 && str[i]) 23 | i++; 24 | while (str[i] && (str[i] == '-' || str[i] == '+')) 25 | { 26 | if (str[i] == '-') 27 | sign = -1; 28 | i++; 29 | } 30 | while (str[i] >= '0' && str[i] <= '9' && str[i]) 31 | { 32 | res = res * 10 + str[i] - '0'; 33 | i++; 34 | } 35 | return (res * sign); 36 | } 37 | -------------------------------------------------------------------------------- /C_01/ex08/ft_sort_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 21:18:23 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/22 09:09:01 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_swap(int *a, int *b) 16 | { 17 | int tmp; 18 | 19 | tmp = *a; 20 | *a = *b; 21 | *b = tmp; 22 | } 23 | 24 | void ft_sort_int_tab(int *tab, int size) 25 | { 26 | int i; 27 | int j; 28 | 29 | i = 0; 30 | while (i < size) 31 | { 32 | j = i + 1; 33 | while (j < size) 34 | { 35 | if (tab[i] > tab[j]) 36 | { 37 | ft_swap(&tab[i], &tab[j]); 38 | } 39 | j++; 40 | } 41 | i++; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /C_11/ex05/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 11:37:55 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 12:07:09 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putnbr(int nb) 21 | { 22 | if (nb == -2147483648) 23 | { 24 | ft_putchar('-'); 25 | ft_putchar('2'); 26 | ft_putnbr(147483648); 27 | } 28 | else if (nb < 0) 29 | { 30 | ft_putchar('-'); 31 | nb = -nb; 32 | ft_putnbr(nb); 33 | } 34 | else if (nb > 9) 35 | { 36 | ft_putnbr(nb / 10); 37 | ft_putnbr(nb % 10); 38 | } 39 | else 40 | ft_putchar(nb + 48); 41 | } 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 1337_pool 2 | 3 |

4 | 5 |

6 | 7 | >_The "pool" is a 4-week drenching in the coding scene. Very much like a long distance runner, you will take a profound jump. 8 | Consistently, ends of the week included during a month, you will be dealing with IT projects. 9 | Simultaneously, you get to know individual candidates, submit and assess projects. 10 | The "pool" program resembles a new beginning. 11 | A chance to begin a new and don't bother having IT information to begin. 12 | The main essential… is to know how to utilize a PC. 13 | 14 | ## What you will face 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 |
DAY'sSHELL00, SHELL01, DAY00, DAY02, DAY03, DAY04, DAY05, DAY06, DAY07, DAY08, DAY09, DAY10, DAY11, DAY12
EXAM'sEXAM00, EXAM01, EXAM02, EXAM03
TEAM PROJECTSRUSH00,RUSH01,RUSH02,BSQ
31 | 32 | 33 | ## Pool Program 34 | 35 | ![image](https://user-images.githubusercontent.com/81354228/187966144-160e0e71-10c8-4efe-bc46-688555b9aa26.png) 36 | 37 | 38 | 39 | ## Education Program 40 | 41 | ![image](https://user-images.githubusercontent.com/81354228/187965974-3c7243a5-30c6-46b6-bb55-6ddd3c442d33.png) 42 | -------------------------------------------------------------------------------- /C_07/ex02/ft_ultimate_range.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_range.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/31 18:45:51 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 10:10:04 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_ultimate_range(int **range, int min, int max) 17 | { 18 | int i; 19 | int *result; 20 | 21 | if (min >= max) 22 | { 23 | *range = NULL; 24 | return (0); 25 | } 26 | i = max - min; 27 | result = (int *)malloc(sizeof(int) * i); 28 | if (result == NULL) 29 | { 30 | *range = NULL; 31 | return (-1); 32 | } 33 | *range = result; 34 | i = 0; 35 | while (max > min) 36 | { 37 | result[i] = min; 38 | min++; 39 | i++; 40 | } 41 | return (i); 42 | } 43 | -------------------------------------------------------------------------------- /C_00/ex06/ft_print_comb2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 10:09:44 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 10:19:50 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_comb2(void) 21 | { 22 | int a; 23 | int b; 24 | 25 | a = 0; 26 | while (a <= 98) 27 | { 28 | b = a + 1; 29 | while (b <= 99) 30 | { 31 | ft_putchar((a / 10) + '0'); 32 | ft_putchar((a % 10) + '0'); 33 | ft_putchar(' '); 34 | ft_putchar((b / 10) + '0'); 35 | ft_putchar((b % 10) + '0'); 36 | if (a < 98) 37 | { 38 | ft_putchar(','); 39 | ft_putchar(' '); 40 | } 41 | b++; 42 | } 43 | a++; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /C_00/ex05/ft_print_comb.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 09:29:57 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 11:57:57 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putnumbers(int x, int y, int z) 21 | { 22 | ft_putchar(x + '0'); 23 | ft_putchar(y + '0'); 24 | ft_putchar(z + '0'); 25 | if (x < 7) 26 | { 27 | ft_putchar(','); 28 | ft_putchar(' '); 29 | } 30 | } 31 | 32 | void ft_print_comb(void) 33 | { 34 | int x; 35 | int y; 36 | int z; 37 | 38 | x = 0; 39 | while (x <= 7) 40 | { 41 | y = x + 1; 42 | while (y <= 8) 43 | { 44 | z = y + 1; 45 | while (z <= 9) 46 | { 47 | ft_putnumbers(x, y, z); 48 | z++; 49 | } 50 | y++; 51 | } 52 | x++; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /C_02/ex11/ft_putstr_non_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putsrt_non_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/23 17:32:20 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/03 21:10:41 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_puthex(unsigned char c) 21 | { 22 | char *hex; 23 | 24 | hex = "0123456789abcdef"; 25 | ft_putchar(hex[c / 16]); 26 | ft_putchar(hex[c % 16]); 27 | } 28 | 29 | int ft_str_is_printable(unsigned char c) 30 | { 31 | if (c >= 31 && c <= 126) 32 | return (1); 33 | else 34 | return (0); 35 | } 36 | 37 | void ft_putstr_non_printable(char *str) 38 | { 39 | int i; 40 | 41 | i = 0; 42 | while (str[i]) 43 | { 44 | if (ft_str_is_printable(str[i])) 45 | ft_putchar(str[i]); 46 | else 47 | { 48 | ft_putchar('\\'); 49 | ft_puthex(str[i]); 50 | } 51 | i++; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /C_02/ex09/ft_strcapitalize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcapitalize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/23 17:11:41 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/03 21:11:09 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int is_num_or_char(char c) 17 | { 18 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') 19 | || (c >= '0' && c <= '9')) 20 | return (1); 21 | return (0); 22 | } 23 | 24 | char *ft_strcapitalize(char *str) 25 | { 26 | int first_char; 27 | int i; 28 | 29 | i = 0; 30 | first_char = 1; 31 | while (str[i]) 32 | { 33 | if (is_num_or_char(str[i])) 34 | { 35 | if (first_char && (str[i] >= 'a' && str[i] <= 'z')) 36 | str[i] = str[i] - 32; 37 | else if (!first_char && str[i] >= 'A' && str[i] <= 'Z') 38 | str[i] = str[i] + 32; 39 | first_char = 0; 40 | } 41 | else 42 | first_char = 1; 43 | i++; 44 | } 45 | return (str); 46 | } 47 | -------------------------------------------------------------------------------- /C_03/ex05/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/25 20:21:22 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/25 20:31:39 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | i++; 22 | return (i); 23 | } 24 | 25 | unsigned int ft_strlcat(char *dest, char *src, unsigned int size) 26 | { 27 | unsigned int dest_len; 28 | unsigned int src_len; 29 | unsigned int i; 30 | unsigned int result; 31 | 32 | i = 0; 33 | dest_len = ft_strlen(dest); 34 | src_len = ft_strlen(src); 35 | if (dest_len < size) 36 | result = dest_len + src_len; 37 | else 38 | result = src_len + size; 39 | if (size == 0) 40 | return (result); 41 | while (src[i] && dest_len + i < size - 1) 42 | { 43 | dest[dest_len + i] = src[i]; 44 | i++; 45 | } 46 | dest[dest_len + i] = '\0'; 47 | return (result); 48 | } 49 | -------------------------------------------------------------------------------- /C_06/ex03/ft_sort_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/28 17:22:27 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/28 17:28:23 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strcmp(char *s1, char *s2) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s1[i] && s2[i]) 21 | { 22 | if (s1[i] == s2[i]) 23 | i++; 24 | else 25 | break ; 26 | } 27 | return (s1[i] - s2[i]); 28 | } 29 | 30 | void ft_sort_params(int ac, char **av) 31 | { 32 | char *tmp; 33 | int i; 34 | 35 | i = 1; 36 | while (i < ac - 1) 37 | { 38 | if (ft_strcmp(av[i], av[i + 1]) > 0) 39 | { 40 | tmp = av[i]; 41 | av[i] = av[i + 1]; 42 | av[i + 1] = tmp; 43 | i = 0; 44 | } 45 | i++; 46 | } 47 | } 48 | 49 | void ft_putstr(char *str) 50 | { 51 | while (*str) 52 | write(1, str++, 1); 53 | write(1, "\n", 1); 54 | } 55 | 56 | int main(int ac, char **av) 57 | { 58 | int i; 59 | 60 | i = 1; 61 | ft_sort_params(ac, av); 62 | while (i < ac) 63 | ft_putstr(av[i++]); 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /C_08/ex05/ft_show_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_show_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 18:27:52 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 18:43:18 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "ft_stock_str.h" 15 | 16 | void ft_putchar(char c) 17 | { 18 | write(1, &c, 1); 19 | } 20 | 21 | void ft_putstr(char *str) 22 | { 23 | while (*str) 24 | { 25 | write(1, str, 1); 26 | str++; 27 | } 28 | } 29 | 30 | void ft_putnbr(int nb) 31 | { 32 | if (nb == -2147483648) 33 | { 34 | ft_putchar('-'); 35 | ft_putchar('2'); 36 | ft_putnbr(147483648); 37 | } 38 | else if (nb < 0) 39 | { 40 | ft_putchar('-'); 41 | nb = -nb; 42 | ft_putnbr(nb); 43 | } 44 | else if (nb > 9) 45 | { 46 | ft_putnbr(nb / 10); 47 | ft_putnbr(nb % 10); 48 | } 49 | else 50 | ft_putchar(nb + 48); 51 | } 52 | 53 | void ft_show_tab(struct s_stock_str *par) 54 | { 55 | int index; 56 | 57 | index = 0; 58 | while (par[index].str != 0) 59 | { 60 | ft_putstr(par[index].str); 61 | ft_putstr("\n"); 62 | ft_putnbr(par[index].size); 63 | ft_putstr("\n"); 64 | ft_putstr(par[index].copy); 65 | ft_putstr("\n"); 66 | index++; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Shell_00/ex01/testShell00.tar: -------------------------------------------------------------------------------- 1 | testShell00000455 310074 011610 00000000050 14245765470 014513 0ustar00mghalmicandidate000000 000000 mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm 2 | -------------------------------------------------------------------------------- /C_08/ex04/ft_strs_to_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strs_to_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 17:42:36 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 18:45:03 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "ft_stock_str.h" 16 | 17 | int ft_str_length(char *str) 18 | { 19 | int index; 20 | 21 | index = 0; 22 | while (str[index]) 23 | index++; 24 | return (index); 25 | } 26 | 27 | char *ft_strdup(char *src) 28 | { 29 | int index; 30 | char *dest; 31 | 32 | index = 0; 33 | dest = (char *)malloc(ft_str_length(src) * sizeof(char) + 1); 34 | if (!dest) 35 | return (0); 36 | while (src[index]) 37 | { 38 | dest[index] = src[index]; 39 | index++; 40 | } 41 | dest[index] = '\0'; 42 | return (dest); 43 | } 44 | 45 | struct s_stock_str *ft_strs_to_tab(int ac, char **av) 46 | { 47 | int index; 48 | struct s_stock_str *array; 49 | 50 | array = malloc((ac + 1) * sizeof(struct s_stock_str)); 51 | if (!array) 52 | return (NULL); 53 | index = 0; 54 | while (index < ac) 55 | { 56 | array[index].size = ft_str_length(av[index]); 57 | array[index].str = av[index]; 58 | array[index].copy = ft_strdup(av[index]); 59 | index++; 60 | } 61 | array[index].str = 0; 62 | array[index].copy = 0; 63 | return (array); 64 | } 65 | -------------------------------------------------------------------------------- /C_07/ex03/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/06 12:19:07 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/06 12:42:09 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *s) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (s[i]) 21 | i++; 22 | return (i); 23 | } 24 | 25 | int total_words(int size, char **strs) 26 | { 27 | int total; 28 | 29 | total = 0; 30 | while (size--) 31 | { 32 | total = total + ft_strlen(*strs); 33 | strs++; 34 | } 35 | return (total); 36 | } 37 | 38 | void append_word(char **joined_string, char *str) 39 | { 40 | while (*str) 41 | { 42 | **joined_string = *str; 43 | (*joined_string)++; 44 | str++; 45 | } 46 | } 47 | 48 | char *ft_strjoin(int size, char **strs, char *sep) 49 | { 50 | int length; 51 | char *joined_string; 52 | char *p; 53 | int i; 54 | 55 | length = total_words(size, strs) + ft_strlen(sep) * (size - 1) + 1; 56 | if (size == 0) 57 | length = 1; 58 | joined_string = malloc(length * sizeof(*joined_string)); 59 | if (joined_string == NULL) 60 | return (NULL); 61 | p = joined_string; 62 | i = 0; 63 | while (i < size) 64 | { 65 | append_word(&p, strs[i++]); 66 | if (i < size) 67 | append_word(&p, sep); 68 | } 69 | *p = 0; 70 | return (joined_string); 71 | } 72 | -------------------------------------------------------------------------------- /C_04/ex04/ft_putnbr_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/27 10:14:20 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/03 17:30:08 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | int ft_strlen(char *str) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (str[i]) 26 | i++; 27 | return (i); 28 | } 29 | 30 | int valid(char *base) 31 | { 32 | int i; 33 | int j; 34 | 35 | i = 0; 36 | if (ft_strlen(base) < 2) 37 | return (0); 38 | while (base[i]) 39 | { 40 | if (base[i] == '+' || base[i] == '-') 41 | return (0); 42 | i++; 43 | } 44 | i = 0; 45 | while (base[i]) 46 | { 47 | j = i + 1; 48 | while ((base[i] != base[j]) && base[j]) 49 | j++; 50 | if (base[i] == base[j]) 51 | return (0); 52 | i++; 53 | } 54 | return (1); 55 | } 56 | 57 | void ft_putnbr_base(int nbr, char *base) 58 | { 59 | unsigned int n; 60 | unsigned int base_len; 61 | 62 | if (!valid(base)) 63 | return ; 64 | n = nbr; 65 | if (nbr < 0) 66 | { 67 | ft_putchar('-'); 68 | n *= -1; 69 | } 70 | base_len = ft_strlen(base); 71 | if (n < base_len) 72 | ft_putchar(base[n % base_len]); 73 | else 74 | { 75 | ft_putnbr_base(n / base_len, base); 76 | ft_putnbr_base(n % base_len, base); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /C_07/ex04/ft_convert_base2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_convert_base2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/04 11:34:20 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/04 12:49:57 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_atoi_base(char *str, char *base); 17 | 18 | int checkerror(char *str); 19 | 20 | int dig(int nbr, int base_len) 21 | { 22 | int i; 23 | 24 | i = 1; 25 | while (nbr / base_len) 26 | { 27 | nbr /= base_len; 28 | i++; 29 | } 30 | return (i); 31 | } 32 | 33 | char *convert_to(int nbr, char *base_to, int base_len) 34 | { 35 | char *res; 36 | int size; 37 | int i; 38 | 39 | i = 0; 40 | size = dig(nbr, base_len); 41 | if (nbr < 0) 42 | size++; 43 | res = (char *) malloc(sizeof(char) * size + 1); 44 | if (nbr < 0) 45 | { 46 | res[0] = '-'; 47 | nbr *= -1; 48 | i = 1; 49 | } 50 | res[size--] = '\0'; 51 | while (i <= size) 52 | { 53 | res[size--] = base_to[nbr % base_len]; 54 | nbr /= base_len; 55 | } 56 | return (res); 57 | } 58 | 59 | char *ft_convert_base(char *nbr, char *base_from, char *base_to) 60 | { 61 | int dec; 62 | int bt_len; 63 | char *res; 64 | 65 | bt_len = checkerror(base_to); 66 | if (!checkerror(base_from) || !bt_len) 67 | return (NULL); 68 | dec = ft_atoi_base(nbr, base_from); 69 | res = convert_to(dec, base_to, bt_len); 70 | return (res); 71 | } 72 | -------------------------------------------------------------------------------- /C_11/ex05/do_op.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* do_op.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/10 10:54:06 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/10 20:24:33 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "do_op.h" 14 | #include 15 | #include 16 | 17 | int operator(int a, char *c, int b) 18 | { 19 | int r; 20 | int (*operator[5])(int, int); 21 | 22 | operator[0] = &ft_add; 23 | operator[1] = &ft_sub; 24 | operator[2] = &ft_mul; 25 | operator[3] = &ft_div; 26 | operator[4] = &ft_mod; 27 | r = 1; 28 | if (c[0] == '+') 29 | r = operator[0](a, b); 30 | else if (c[0] == '-') 31 | r = operator[1](a, b); 32 | else if (c[0] == '*') 33 | r = operator[2](a, b); 34 | else if (c[0] == '/') 35 | r = operator[3](a, b); 36 | else if (c[0] == '%') 37 | r = operator[4](a, b); 38 | return (r); 39 | } 40 | 41 | void do_op(char *n, char *c, char *m) 42 | { 43 | int i; 44 | int a; 45 | int b; 46 | int r; 47 | 48 | i = 0; 49 | r = 1; 50 | a = ft_atoi(n); 51 | b = ft_atoi(m); 52 | if (!(c[0] == '+' || c[0] == '-' || c[0] == '/' 53 | || c[0] == '%' || c[0] == '*')) 54 | write(1, "0", 1); 55 | else if (c[0] == '/' && b == 0) 56 | write(1, "Stop : division by zero", 23); 57 | else if (c[0] == '%' && b == 0) 58 | write(1, "Stop : modulo by zero", 21); 59 | else 60 | { 61 | r *= (operator(a, c, b)); 62 | ft_putnbr(r); 63 | } 64 | write(1, "\n", 1); 65 | } 66 | 67 | int main(int ac, char **av) 68 | { 69 | if (ac == 4) 70 | do_op(av[1], av[2], av[3]); 71 | return (0); 72 | } 73 | -------------------------------------------------------------------------------- /C_00/ex08/ft_print_combn.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_combn.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/07/21 10:22:40 by mghalmi #+# #+# */ 9 | /* Updated: 2022/07/21 13:27:20 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_numbers(int arr[], int size) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (i < size) 26 | { 27 | ft_putchar(arr[i] + '0'); 28 | i++; 29 | } 30 | if (arr[0] < 10 - size) 31 | { 32 | ft_putchar(','); 33 | ft_putchar(' '); 34 | } 35 | } 36 | 37 | int ft_get_index(int arr[], int size) 38 | { 39 | int index; 40 | 41 | index = size - 1; 42 | while (index >= 0) 43 | { 44 | if (arr[index] == arr[index - 1] + 1) 45 | { 46 | index--; 47 | } 48 | else 49 | { 50 | break ; 51 | } 52 | } 53 | return (index - 1); 54 | } 55 | 56 | void ft_reset_array(int arr[], int size, int index) 57 | { 58 | arr[index]++; 59 | index++; 60 | while (index < size) 61 | { 62 | arr[index] = arr[index - 1] + 1; 63 | index++; 64 | } 65 | } 66 | 67 | void ft_print_combn(int n) 68 | { 69 | int i; 70 | int arr[10]; 71 | 72 | i = 0; 73 | while (i < n) 74 | { 75 | arr[i] = i; 76 | i++; 77 | } 78 | while (arr[0] <= 10 - n) 79 | { 80 | if (arr[n - 1] < 9) 81 | { 82 | ft_print_numbers(arr, n); 83 | arr[n - 1]++; 84 | } 85 | else 86 | { 87 | ft_print_numbers(arr, n); 88 | i = ft_get_index(arr, n); 89 | if (i < 0) 90 | break ; 91 | ft_reset_array(arr, n, i); 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /C_04/ex05/ft_atoi_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/03 12:40:02 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/03 16:22:57 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int checkerror(char *str) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | if (str[0] == '\0' || str[1] == '\0') 22 | return (0); 23 | while (str[i] != '\0') 24 | { 25 | if (str[i] <= 32 || str[i] == 127 || str[i] == 43 || str[i] == 45) 26 | return (0); 27 | j = i + 1; 28 | while (str[j] != '\0') 29 | { 30 | if (str[i] == str[j]) 31 | return (0); 32 | j++; 33 | } 34 | i++; 35 | } 36 | return (i); 37 | } 38 | 39 | int nb_base(char str, char *base) 40 | { 41 | int nb; 42 | 43 | nb = 0; 44 | while (base[nb] != '\0') 45 | { 46 | if (str == base[nb]) 47 | return (nb); 48 | nb++; 49 | } 50 | return (-1); 51 | } 52 | 53 | int whitespaces(char *str, int *ptr_i) 54 | { 55 | int count; 56 | int i; 57 | 58 | i = 0; 59 | while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) 60 | i++; 61 | count = 1; 62 | while (str[i] && (str[i] == 43 || str[i] == 45)) 63 | { 64 | if (str[i] == 45) 65 | count *= -1; 66 | i++; 67 | } 68 | *ptr_i = i; 69 | return (count); 70 | } 71 | 72 | int ft_atoi_base(char *str, char *base) 73 | { 74 | int i; 75 | int negative; 76 | int nb; 77 | int nb2; 78 | int begin_len; 79 | 80 | nb = 0; 81 | i = 0; 82 | begin_len = checkerror(base); 83 | if (begin_len >= 2) 84 | { 85 | negative = whitespaces(str, &i); 86 | nb2 = nb_base(str[i], base); 87 | while (nb2 != -1) 88 | { 89 | nb = (nb * begin_len) + nb2; 90 | i++; 91 | nb2 = nb_base(str[i], base); 92 | } 93 | return (nb *= negative); 94 | } 95 | return (0); 96 | } 97 | -------------------------------------------------------------------------------- /C_07/ex04/ft_convert_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_convert_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/03 21:47:21 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/04 11:33:58 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int checkerror(char *str) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | if (str[0] == '\0' || str[1] == '\0') 22 | return (0); 23 | while (str[i] != '\0') 24 | { 25 | if (str[i] <= 32 || str[i] == 127 || str[i] == 43 || str[i] == 45) 26 | return (0); 27 | j = i + 1; 28 | while (str[j] != '\0') 29 | { 30 | if (str[i] == str[j]) 31 | return (0); 32 | j++; 33 | } 34 | i++; 35 | } 36 | return (i); 37 | } 38 | 39 | int nb_base(char str, char *base) 40 | { 41 | int nb; 42 | 43 | nb = 0; 44 | while (base[nb] != '\0') 45 | { 46 | if (str == base[nb]) 47 | return (nb); 48 | nb++; 49 | } 50 | return (-1); 51 | } 52 | 53 | int whitespaces(char *str, int *ptr_i) 54 | { 55 | int count; 56 | int i; 57 | 58 | i = 0; 59 | while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) 60 | i++; 61 | count = 1; 62 | while (str[i] && (str[i] == 43 || str[i] == 45)) 63 | { 64 | if (str[i] == 45) 65 | count *= -1; 66 | i++; 67 | } 68 | *ptr_i = i; 69 | return (count); 70 | } 71 | 72 | int ft_atoi_base(char *str, char *base) 73 | { 74 | int i; 75 | int negative; 76 | int nb; 77 | int nb2; 78 | int begin_len; 79 | 80 | nb = 0; 81 | i = 0; 82 | begin_len = checkerror(base); 83 | if (begin_len >= 2) 84 | { 85 | negative = whitespaces(str, &i); 86 | nb2 = nb_base(str[i], base); 87 | while (nb2 != -1) 88 | { 89 | nb = (nb * begin_len) + nb2; 90 | i++; 91 | nb2 = nb_base(str[i], base); 92 | } 93 | return (nb *= negative); 94 | } 95 | return (0); 96 | } 97 | -------------------------------------------------------------------------------- /C_07/ex05/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/04 12:56:11 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/08 19:20:02 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int check_sep(char c, char *sep) 18 | { 19 | int i; 20 | 21 | i = 0; 22 | while (sep[i]) 23 | { 24 | if (c == sep[i]) 25 | return (1); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | 31 | int count_strings(char *str, char *sep) 32 | { 33 | int i; 34 | int count; 35 | 36 | i = 0; 37 | count = 0; 38 | while (str[i]) 39 | { 40 | while (str[i] && check_sep(str[i], sep)) 41 | i++; 42 | if (str[i]) 43 | count++; 44 | while (str[i] && !check_sep(str[i], sep)) 45 | i++; 46 | } 47 | return (count); 48 | } 49 | 50 | int strlen_sep(char *str, char *sep) 51 | { 52 | int i; 53 | 54 | i = 0; 55 | while (str[i] && !check_sep(str[i], sep)) 56 | i++; 57 | return (i); 58 | } 59 | 60 | char *words(char *str, char *sep) 61 | { 62 | int wrd_len; 63 | int i; 64 | char *word; 65 | 66 | i = 0; 67 | wrd_len = strlen_sep(str, sep); 68 | word = malloc(sizeof(char) * (wrd_len + 1)); 69 | while (i < wrd_len) 70 | { 71 | word[i] = str[i]; 72 | i++; 73 | } 74 | word[i] = '\0'; 75 | return (word); 76 | } 77 | 78 | char **ft_split(char *str, char *charset) 79 | { 80 | char **strs; 81 | int i; 82 | 83 | i = 0; 84 | strs = (char **)malloc(sizeof(char *) * (count_strings(str, charset) + 1)); 85 | while (*str) 86 | { 87 | while (*str && check_sep(*str, charset)) 88 | str++; 89 | if (*str) 90 | { 91 | strs[i] = words(str, charset); 92 | i++; 93 | } 94 | while (*str && !check_sep(*str, charset)) 95 | str++; 96 | } 97 | strs[i] = 0; 98 | return (strs); 99 | } 100 | -------------------------------------------------------------------------------- /C_09/ex02/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: mghalmi +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/08 14:51:43 by mghalmi #+# #+# */ 9 | /* Updated: 2022/08/08 19:10:15 by mghalmi ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int check_sep(char c, char *sep) 18 | { 19 | int i; 20 | 21 | i = 0; 22 | while (sep[i]) 23 | { 24 | if (c == sep[i]) 25 | return (1); 26 | i++; 27 | } 28 | return (0); 29 | } 30 | 31 | int count_strings(char *str, char *sep) 32 | { 33 | int i; 34 | int count; 35 | 36 | i = 0; 37 | count = 0; 38 | while (str[i]) 39 | { 40 | while (str[i] && check_sep(str[i], sep)) 41 | i++; 42 | if (str[i]) 43 | count++; 44 | while (str[i] && !check_sep(str[i], sep)) 45 | i++; 46 | } 47 | return (count); 48 | } 49 | 50 | int strlen_sep(char *str, char *sep) 51 | { 52 | int i; 53 | 54 | i = 0; 55 | while (str[i] && !check_sep(str[i], sep)) 56 | i++; 57 | return (i); 58 | } 59 | 60 | char *words(char *str, char *sep) 61 | { 62 | int wrd_len; 63 | int i; 64 | char *word; 65 | 66 | i = 0; 67 | wrd_len = strlen_sep(str, sep); 68 | word = malloc(sizeof(char) * (wrd_len + 1)); 69 | while (i < wrd_len) 70 | { 71 | word[i] = str[i]; 72 | i++; 73 | } 74 | word[i] = '\0'; 75 | return (word); 76 | } 77 | 78 | char **ft_split(char *str, char *charset) 79 | { 80 | char **strs; 81 | int i; 82 | 83 | i = 0; 84 | strs = (char **)malloc(sizeof(char *) * (count_strings(str, charset) + 1)); 85 | while (*str) 86 | { 87 | while (*str && check_sep(*str, charset)) 88 | str++; 89 | if (*str) 90 | { 91 | strs[i] = words(str, charset); 92 | i++; 93 | } 94 | while (*str && !check_sep(*str, charset)) 95 | str++; 96 | } 97 | strs[i] = 0; 98 | return (strs); 99 | } 100 | -------------------------------------------------------------------------------- /Shell_00/ex02/exo2.tar: -------------------------------------------------------------------------------- 1 | test0/000715 310074 011610 00000000000 14245741064 013512 5ustar00mghalmicandidate000000 000000 test1000714 310074 011610 00000000004 14245750010 013421 0ustar00mghalmicandidate000000 000000 123 2 | test2/000504 310074 011610 00000000000 14245756734 013522 5ustar00mghalmicandidate000000 000000 test3000404 310074 011610 00000000001 14245765660 013435 0ustar00mghalmicandidate000000 000000 3 | test4000641 310074 011610 00000000002 14245765564 013445 0ustar00mghalmicandidate000000 000000 1 4 | test5000404 310074 011610 00000000000 14245765660 014422 1test3ustar00mghalmicandidate000000 000000 test6000777 310074 011610 00000000000 14245754000 014420 2test0ustar00mghalmicandidate000000 000000 --------------------------------------------------------------------------------