├── shell00 ├── ex00 │ └── z ├── ex04 │ └── midLS ├── ex09 │ └── ft_magic ├── ex06 │ └── git_ignore.sh ├── ex05 │ └── git_commit.sh ├── ex08 │ └── clean ├── ex03 │ └── klist.txt ├── ex07 │ └── b └── ex01 │ └── testShell00.tar ├── bsq ├── auteur ├── Makefile └── src │ ├── ft_atoi.c │ ├── utility.c │ ├── header.h │ └── grid_parsing.c ├── shell01 ├── ex05 │ └── "\?$*'MaRViN'*$?\" ├── ex03 │ └── count_files.sh ├── ex06 │ └── skip.sh ├── ex01 │ └── print_groups.sh ├── ex04 │ └── MAC.sh └── ex02 │ └── find_sh.sh ├── c05 ├── ex07 │ ├── a.out │ └── ft_find_next_prime.c ├── ex04 │ └── ft_fibonacci.c ├── ex00 │ └── ft_iterative_factorial.c ├── ex01 │ └── ft_recursive_factorial.c ├── ex05 │ └── ft_sqrt.c ├── ex03 │ └── ft_recursive_power.c ├── ex02 │ └── ft_iterative_power.c └── ex06 │ └── ft_is_prime.c ├── c10 ├── ex02 │ ├── get.o │ ├── c10.zip │ ├── ft_tail │ ├── ft_tail.o │ ├── ft_on_str.o │ ├── ft_putstr_error.o │ ├── ft_writing_reading.o │ ├── Makefile │ ├── ft_tail.c │ ├── ft_on_str.c │ ├── get.c │ ├── tail.h │ ├── ft_putstr_error.c │ └── ft_writing_reading.c ├── ex00 │ ├── Makefile │ └── ft_display_file.c └── ex01 │ ├── Makefile │ └── ft_cat.c ├── c12 ├── .DS_Store ├── ex00 │ ├── ft_list.h │ └── ft_create_elem.c ├── ex01 │ ├── ft_list.h │ └── ft_list_push_front.c ├── ex02 │ ├── ft_list.h │ └── ft_list_size.c ├── ex03 │ ├── ft_list.h │ └── ft_list_last.c ├── ex04 │ ├── ft_list.h │ └── ft_list_push_back.c ├── ex05 │ ├── ft_list.h │ └── ft_list_push_strs.c ├── ex06 │ ├── ft_list.h │ └── ft_list_clear.c ├── ex07 │ ├── ft_list.h │ └── ft_list_at.c ├── ex08 │ ├── ft_list.h │ └── ft_list_reverse.c ├── ex09 │ ├── ft_list.h │ └── ft_list_foreach.c ├── ex10 │ ├── ft_list.h │ └── ft_list_foreach_if.c ├── ex11 │ ├── ft_list.h │ └── ft_list_find.c ├── ex12 │ ├── ft_list.h │ └── ft_list_remove_if.c ├── ex13 │ ├── ft_list.h │ └── ft_list_merge.c ├── ex14 │ ├── ft_list.h │ └── ft_list_sort.c ├── ex15 │ ├── ft_list.h │ └── ft_list_reverse_fun.c ├── ex16 │ ├── ft_list.h │ └── ft_sorted_list_insert.c ├── ex17 │ ├── ft_list.h │ └── ft_sorted_list_merge.c ├── main2.c └── main.c ├── c07 ├── ex04 │ ├── code.zip │ ├── ft_convert_base2.c │ └── ft_convert_base.c ├── ex01 │ └── ft_range.c ├── ex02 │ └── ft_ultimate_range.c ├── ex00 │ └── ft_strdup.c ├── ex03 │ └── ft_strjoin.c └── ex05 │ └── ft_split.c ├── c09 ├── ex00 │ ├── libft_creator.sh │ ├── ft_putchar.c │ ├── ft_swap.c │ ├── ft_putstr.c │ ├── ft_strlen.c │ └── ft_strcmp.c ├── ex01 │ └── Makefile └── ex02 │ └── ft_split.c ├── c11 ├── ex05 │ ├── Makefile │ ├── header.h │ ├── ft_putnbr.c │ ├── ft_op.c │ ├── ft_op2.c │ └── ft_atoi.c ├── ex00 │ └── ft_foreach.c ├── ex02 │ └── ft_any.c ├── ex03 │ └── ft_count_if.c ├── ex01 │ └── ft_map.c ├── ex04 │ └── ft_is_sort.c └── ex06 │ └── ft_sort_string_tab.c ├── ReadMe.md ├── c01 ├── ex00 │ └── ft_ft.c ├── ex01 │ └── ft_ultimate_ft.c ├── ex02 │ └── ft_swap.c ├── ex03 │ └── ft_div_mod.c ├── ex05 │ └── ft_putstr.c ├── ex06 │ └── ft_strlen.c ├── ex04 │ └── ft_ultimate_div_mod.c ├── ex07 │ └── ft_rev_int_tab.c └── ex08 │ └── ft_sort_int_tab.c ├── c08 ├── ex02 │ └── ft_abs.h ├── ex03 │ └── ft_point.h ├── ex00 │ └── ft.h ├── ex01 │ └── ft_boolean.h ├── ex04 │ └── ft_strs_to_tab.c └── ex05 │ └── ft_show_tab.c ├── c00 ├── ex00 │ └── ft_putchar.c ├── ex03 │ └── ft_print_numbers.c ├── ex01 │ └── ft_print_alphabet.c ├── ex02 │ └── ft_print_reverse_alphabet.c ├── ex04 │ └── ft_is_negative.c ├── ex06 │ └── ft_print_comb2.c └── ex05 │ └── ft_print_comb.c ├── c04 ├── ex00 │ └── ft_strlen.c ├── ex01 │ └── ft_putstr.c ├── ex02 │ └── ft_putnbr.c ├── ex03 │ └── ft_atoi.c ├── ex04 │ └── ft_putnbr_base.c └── ex05 │ └── ft_atoi_base.c ├── c02 ├── ex03 │ └── ft_str_is_numeric.c ├── ex04 │ └── ft_str_is_lowercase.c ├── ex05 │ └── ft_str_is_uppercase.c ├── ex06 │ └── ft_str_is_printable.c ├── ex00 │ └── ft_strcpy.c ├── ex02 │ └── ft_str_is_alpha.c ├── ex07 │ └── ft_strupcase.c ├── ex08 │ └── ft_strlowcase.c ├── ex01 │ └── ft_strncpy.c ├── ex10 │ └── ft_strlcpy.c ├── ex11 │ └── ft_putstr_non_printable.c └── ex09 │ └── ft_strcapitalize.c ├── c03 ├── ex00 │ └── ft_strcmp.c ├── ex02 │ └── ft_strcat.c ├── ex01 │ └── ft_strncmp.c ├── ex03 │ └── ft_strncat.c ├── ex04 │ └── ft_strstr.c └── ex05 │ └── ft_strlcat.c ├── c13 ├── ex01 │ ├── ft_btree.h │ └── btree_apply_prefix.c ├── ex00 │ ├── btree_create_node.c │ └── ft_btree.h ├── ex02 │ ├── ft_btree.h │ └── btree_apply_infix.c ├── ex03 │ ├── ft_btree.h │ └── btree_apply_suffix.c ├── ex04 │ ├── ft_btree.h │ └── btree_insert_data.c ├── ex05 │ ├── ft_btree.h │ └── btree_search_item.c └── ex06 │ ├── ft_btree.h │ └── btree_level_count.c └── c06 ├── ex00 └── ft_print_program_name.c ├── ex02 └── ft_rev_params.c ├── ex01 └── ft_print_params.c └── ex03 └── ft_sort_params.c /shell00/ex00/z: -------------------------------------------------------------------------------- 1 | Z 2 | -------------------------------------------------------------------------------- /bsq/auteur: -------------------------------------------------------------------------------- 1 | vgoldman:tmarx 2 | -------------------------------------------------------------------------------- /shell00/ex04/midLS: -------------------------------------------------------------------------------- 1 | ls -pmtU 2 | -------------------------------------------------------------------------------- /shell01/ex05/"\?$*'MaRViN'*$?\": -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /shell00/ex09/ft_magic: -------------------------------------------------------------------------------- 1 | 41 string 42 42 file 2 | -------------------------------------------------------------------------------- /shell00/ex06/git_ignore.sh: -------------------------------------------------------------------------------- 1 | git check-ignore * 2 | -------------------------------------------------------------------------------- /shell00/ex05/git_commit.sh: -------------------------------------------------------------------------------- 1 | git log --pretty="%H" -n 5 2 | -------------------------------------------------------------------------------- /shell01/ex03/count_files.sh: -------------------------------------------------------------------------------- 1 | find . | wc -l | tr -d ' ' 2 | -------------------------------------------------------------------------------- /shell01/ex06/skip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | ls -l | awk '{if (NR % 2) print}' 3 | -------------------------------------------------------------------------------- /shell01/ex01/print_groups.sh: -------------------------------------------------------------------------------- 1 | groups $FT_USER | sed 's/ /,/g' | tr -d "\n" 2 | -------------------------------------------------------------------------------- /c05/ex07/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c05/ex07/a.out -------------------------------------------------------------------------------- /c10/ex02/get.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/get.o -------------------------------------------------------------------------------- /c12/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c12/.DS_Store -------------------------------------------------------------------------------- /shell01/ex04/MAC.sh: -------------------------------------------------------------------------------- 1 | ifconfig | grep ether | cut -c 8- | rev | cut -c 2- | rev 2 | -------------------------------------------------------------------------------- /c07/ex04/code.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c07/ex04/code.zip -------------------------------------------------------------------------------- /c10/ex02/c10.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/c10.zip -------------------------------------------------------------------------------- /c10/ex02/ft_tail: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/ft_tail -------------------------------------------------------------------------------- /shell00/ex08/clean: -------------------------------------------------------------------------------- 1 | find . -type f \( -name "#*#" -o -name "*~" \) -delete -print 2 | -------------------------------------------------------------------------------- /c10/ex02/ft_tail.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/ft_tail.o -------------------------------------------------------------------------------- /c10/ex02/ft_on_str.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/ft_on_str.o -------------------------------------------------------------------------------- /shell01/ex02/find_sh.sh: -------------------------------------------------------------------------------- 1 | find . -name "*.sh" -type f |sed 's#.*/##' | rev | cut -c 4- | rev 2 | -------------------------------------------------------------------------------- /c10/ex02/ft_putstr_error.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/ft_putstr_error.o -------------------------------------------------------------------------------- /c09/ex00/libft_creator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | gcc -c *.c 3 | ar rc libft.a *.o 4 | ranlib libft.a 5 | rm -f *.o 6 | -------------------------------------------------------------------------------- /c10/ex02/ft_writing_reading.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/t0mm4rx/Piscine-42/HEAD/c10/ex02/ft_writing_reading.o -------------------------------------------------------------------------------- /shell00/ex03/klist.txt: -------------------------------------------------------------------------------- 1 | Credentials cache: API:D68E3D33-3E44-4961-B498-206C880BB977 2 | Principal: tmarx@42.FR 3 | 4 | Issued Expires Principal 5 | Jul 1 09:39:29 2019 Jul 8 09:39:29 2019 krbtgt/42.FR@42.FR 6 | Jul 1 10:36:10 2019 Jul 8 09:39:29 2019 host/vgs-fn1.42.fr@42.FR 7 | -------------------------------------------------------------------------------- /c10/ex00/Makefile: -------------------------------------------------------------------------------- 1 | SRC = ft_display_file.c 2 | OBJ = ft_display_file.o 3 | NAME = ft_display_file 4 | 5 | all: ${NAME} 6 | 7 | ${NAME}: 8 | gcc -c -Wall -Werror -Wextra ${SRC} 9 | gcc -o ${NAME} ${OBJ} 10 | 11 | clean: 12 | rm -f *.o 13 | 14 | fclean: clean 15 | rm -f ${NAME} 16 | 17 | .PHONY: all ${NAME} clean 18 | -------------------------------------------------------------------------------- /c10/ex01/Makefile: -------------------------------------------------------------------------------- 1 | NAME = ft_cat 2 | OBJS = ${SRC:%.c=%.o} 3 | SRC = ft_cat.c 4 | CFLAGS += -Wall -Wextra -Werror 5 | DEBUG = debug 6 | 7 | all: ${NAME} 8 | 9 | ${NAME}: $(OBJS) 10 | gcc -o ${NAME} ${OBJS} 11 | 12 | ${DEBUG}: 13 | gcc -o ${DEBUG} ${CFLAGS} -g -fsanitize=address ${SRC} 14 | 15 | clean: 16 | rm -f ${OBJS} 17 | 18 | fclean: clean 19 | rm -f ${NAME} 20 | rm -f ${DEBUG} 21 | rm -Rf *.dSYM 22 | 23 | re: fclean all -------------------------------------------------------------------------------- /c09/ex01/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-Wall -Wextra -Werror -Iincludes 3 | HEADERS=includes/ft.h 4 | SRC = ./srcs/ft_putchar.c ./srcs/ft_swap.c ./srcs/ft_putstr.c ./srcs/ft_strlen.c ./srcs/ft_strcmp.c 5 | COMP = ${SRC:.c=.o} 6 | NAME = libft.a 7 | 8 | all: ${NAME} 9 | 10 | ${NAME}: ${HEADERS} ${COMP} 11 | ar rcs ${NAME} ${COMP} 12 | ranlib ${NAME} 13 | 14 | clean: 15 | rm -f ${COMP} 16 | 17 | fclean: clean 18 | rm -f ${NAME} 19 | 20 | re: fclean all 21 | -------------------------------------------------------------------------------- /c10/ex02/Makefile: -------------------------------------------------------------------------------- 1 | SRCS = ${wildcard *.c} 2 | OBJS = ${SRCS:.c=.o} 3 | CFLAGS = -Wall -Wextra -Werror 4 | CC = gcc 5 | RM = rm -f 6 | NAME = ft_tail 7 | 8 | .c.o : 9 | ${CC} ${CFLAGS} -c $< -o ${<:.c=.o} 10 | 11 | all : ${OBJS} 12 | ${CC} ${FLAGS} ${OBJS} -o ${NAME} 13 | 14 | clean : 15 | ${RM} ${OBJS} 16 | 17 | fclean : clean 18 | ${RM} ${NAME} 19 | 20 | ${NAME} : all 21 | 22 | re : fclean all 23 | 24 | .PHONY : all clean fclean re ${NAME} -------------------------------------------------------------------------------- /c11/ex05/Makefile: -------------------------------------------------------------------------------- 1 | NAME = do-op 2 | OBJS = ${SRC:%.c=%.o} 3 | SRC = ft_op.c ft_atoi.c ft_op2.c ft_putnbr.c 4 | CFLAGS += -Wall -Wextra -Werror 5 | DEBUG = debug 6 | 7 | all: ${NAME} 8 | 9 | ${NAME}: $(OBJS) 10 | gcc -o ${NAME} ${OBJS} 11 | 12 | ${DEBUG}: 13 | gcc -o ${DEBUG} ${CFLAGS} -g -fsanitize=address ${SRC} 14 | 15 | clean: 16 | rm -f ${OBJS} 17 | 18 | fclean: clean 19 | rm -f ${NAME} 20 | rm -f ${DEBUG} 21 | rm -Rf *.dSYM 22 | 23 | re: fclean all -------------------------------------------------------------------------------- /bsq/Makefile: -------------------------------------------------------------------------------- 1 | NAME = bsq 2 | SRC = ./src/main.c ./src/ft_atoi.c ./src/map_parsing.c ./src/utility.c ./src/grid_parsing.c ./src/map_solving.c 3 | OBJS = ${SRC:%.c=%.o} 4 | CFLAGS = -Wall -Wextra -Werror 5 | DEBUG = debug 6 | 7 | all: ${NAME} 8 | 9 | ${NAME}: $(OBJS) 10 | gcc -o ${NAME} ${OBJS} 11 | 12 | ${DEBUG}: 13 | gcc -o ${DEBUG} ${CFLAGS} -ggdb -fsanitize=address ${SRC} 14 | 15 | clean: 16 | rm -f ${OBJS} 17 | 18 | fclean: clean 19 | rm -f ${NAME} 20 | rm -f ${DEBUG} 21 | rm -Rf *.dSYM 22 | 23 | re: fclean all 24 | -------------------------------------------------------------------------------- /shell00/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 | -------------------------------------------------------------------------------- /ReadMe.md: -------------------------------------------------------------------------------- 1 | # Piscine 42 - July 2019 2 | 3 | Copy/Pasting exercices without understanding is bad, for you and for the wellness of the piscine. This repo is only here to help you **UNDERSTAND** exercices. 4 | 5 | Every exercices is correct and has been approved by the Moulinette. However, keep in mind that Moulinette might be often updated. 6 | 7 | There are also slight changes in BSQ subject each year, and check it in multiple languages to be sure. 8 | BSQ in this repo passed the functionnal test, but is not fully optimized. Credits to Violetta Goldman for this one. 9 | 10 | Check my work on: 11 | https://tommarx.fr/ -------------------------------------------------------------------------------- /c01/ex00/ft_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 13:58:55 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 14:32:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_ft(int *nbr) 14 | { 15 | *nbr = 42; 16 | } 17 | -------------------------------------------------------------------------------- /c01/ex01/ft_ultimate_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 14:06:46 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 14:31:29 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_ultimate_ft(int *********nbr) 14 | { 15 | *********nbr = 42; 16 | } 17 | -------------------------------------------------------------------------------- /c08/ex02/ft_abs.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_abs.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 12:55:26 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 12:56:13 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_ABS_H 14 | # define FT_ABS_H 15 | # define ABS(x) (x < 0 ? -x : x) 16 | #endif 17 | -------------------------------------------------------------------------------- /c00/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/02 14:48:15 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/02 15:18:51 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /c09/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 14:19:42 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/11 14:20:23 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /c01/ex02/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 14:33:44 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 19:42:49 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_swap(int *a, int *b) 14 | { 15 | int c; 16 | 17 | c = *a; 18 | *a = *b; 19 | *b = c; 20 | } 21 | -------------------------------------------------------------------------------- /c01/ex03/ft_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 14:40:07 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 14:47:35 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_div_mod(int a, int b, int *div, int *mod) 14 | { 15 | *div = a / b; 16 | *mod = a % b; 17 | } 18 | -------------------------------------------------------------------------------- /c09/ex00/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 14:21:50 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/11 14:34:55 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_swap(int *a, int *b) 14 | { 15 | int c; 16 | 17 | c = *a; 18 | *a = *b; 19 | *b = c; 20 | } 21 | -------------------------------------------------------------------------------- /c00/ex03/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_numbers.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/02 15:49:52 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 17:46:24 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_numbers(void) 16 | { 17 | write(1, "0123456789", 10); 18 | } 19 | -------------------------------------------------------------------------------- /c04/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 11:03:04 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/06 20:10:53 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i]) 19 | i++; 20 | return (i); 21 | } 22 | -------------------------------------------------------------------------------- /c00/ex01/ft_print_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 08:14:23 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 08:14:28 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_alphabet(void) 16 | { 17 | write(1, "abcdefghijklmnopqrstuvwxyz", 26); 18 | } 19 | -------------------------------------------------------------------------------- /c08/ex03/ft_point.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_point.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 13:02:17 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 13:09:06 by tmarx ### ########.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 | #endif 22 | -------------------------------------------------------------------------------- /c00/ex02/ft_print_reverse_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_reverse_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/02 15:20:33 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/02 16:11:40 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_reverse_alphabet(void) 16 | { 17 | write(1, "zyxwvutsrqponmlkjihgfedcba", 26); 18 | } 19 | -------------------------------------------------------------------------------- /c11/ex00/ft_foreach.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_foreach.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 04:14:16 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 04:18:06 by tmarx ### ########.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 | f(tab[i++]); 20 | } 21 | -------------------------------------------------------------------------------- /c01/ex05/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 14:54:06 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 15:27:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str != 0x00) 18 | { 19 | write(1, str, 1); 20 | str++; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c04/ex01/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 11:12:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 22:29:08 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str != 0x00) 18 | { 19 | write(1, str, 1); 20 | str++; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c09/ex00/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 14:22:43 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/11 14:34:25 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str != 0x00) 18 | { 19 | write(1, str, 1); 20 | str++; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /c01/ex06/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 15:28:42 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 15:33:07 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int c; 16 | 17 | c = 0; 18 | while (*str != 0x00) 19 | { 20 | c++; 21 | str++; 22 | } 23 | return (c); 24 | } 25 | -------------------------------------------------------------------------------- /c09/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 14:23:26 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/11 14:34:44 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int c; 16 | 17 | c = 0; 18 | while (*str != 0x00) 19 | { 20 | c++; 21 | str++; 22 | } 23 | return (c); 24 | } 25 | -------------------------------------------------------------------------------- /c01/ex04/ft_ultimate_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 14:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 14:53:37 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_ultimate_div_mod(int *a, int *b) 14 | { 15 | int r; 16 | int v; 17 | 18 | r = *a / *b; 19 | v = *a % *b; 20 | *a = r; 21 | *b = v; 22 | } 23 | -------------------------------------------------------------------------------- /c02/ex03/ft_str_is_numeric.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_numeric.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 08:51:04 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 08:54:23 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_str_is_numeric(char *str) 14 | { 15 | while (*str) 16 | { 17 | if (*str < 48 || *str > 57) 18 | return (0); 19 | str++; 20 | } 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /c02/ex04/ft_str_is_lowercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_lowercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 08:55:24 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 08:59:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_str_is_lowercase(char *str) 14 | { 15 | while (*str) 16 | { 17 | if (*str < 97 || *str > 122) 18 | return (0); 19 | str++; 20 | } 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /c02/ex05/ft_str_is_uppercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_uppercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 08:59:55 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 09:03:37 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_str_is_uppercase(char *str) 14 | { 15 | while (*str) 16 | { 17 | if (*str < 65 || *str > 90) 18 | return (0); 19 | str++; 20 | } 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /c02/ex06/ft_str_is_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 09:05:33 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 09:07:21 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_str_is_printable(char *str) 14 | { 15 | while (*str) 16 | { 17 | if (*str < 32 || *str > 127) 18 | return (0); 19 | str++; 20 | } 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /c00/ex04/ft_is_negative.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_negative.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/02 16:14:56 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/02 16:23:29 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_is_negative(int n) 16 | { 17 | if (n < 0) 18 | { 19 | write(1, "N", 1); 20 | } 21 | else 22 | { 23 | write(1, "P", 1); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /c03/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 17:00:29 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/05 14:54:00 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(char *s1, char *s2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (s1[i] && s2[i] && s1[i] == s2[i]) 19 | { 20 | i++; 21 | } 22 | return (s1[i] - s2[i]); 23 | } 24 | -------------------------------------------------------------------------------- /c09/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 14:25:05 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/11 14:34:35 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(char *s1, char *s2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (s1[i] && s2[i] && s1[i] == s2[i]) 19 | { 20 | i++; 21 | } 22 | return (s1[i] - s2[i]); 23 | } 24 | -------------------------------------------------------------------------------- /c11/ex02/ft_any.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_any.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 04:22:30 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 22:33:45 by tmarx ### ########.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]) 19 | { 20 | if (f(tab[i++]) != 0) 21 | return (1); 22 | } 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /c12/ex00/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex01/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex02/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex03/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex04/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex05/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex06/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex07/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex08/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex09/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex10/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex11/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex12/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex13/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex14/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex15/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex16/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c12/ex17/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:37:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 10:26:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_LIST_H 14 | # define FT_LIST_H 15 | 16 | typedef struct s_list 17 | { 18 | struct s_list *next; 19 | void *data; 20 | } t_list; 21 | t_list *ft_create_elem(void *data); 22 | #endif 23 | -------------------------------------------------------------------------------- /c02/ex00/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 20:09:25 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 16:38:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strcpy(char *dest, char *src) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (src[i]) 19 | { 20 | dest[i] = src[i]; 21 | i++; 22 | } 23 | dest[i] = 0x00; 24 | return (dest); 25 | } 26 | -------------------------------------------------------------------------------- /c03/ex02/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 23:34:33 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/06 16:09:30 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strcat(char *dest, char *src) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (dest[i]) 19 | i++; 20 | while (*src) 21 | dest[i++] = *src++; 22 | dest[i] = '\0'; 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /c02/ex02/ft_str_is_alpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_alpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 08:34:32 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 08:50:12 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_str_is_alpha(char *str) 14 | { 15 | while (*str) 16 | { 17 | if (!(*str >= 65 && *str <= 90) && !(*str >= 97 && *str <= 122)) 18 | return (0); 19 | str++; 20 | } 21 | return (1); 22 | } 23 | -------------------------------------------------------------------------------- /c05/ex04/ft_fibonacci.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_fibonacci.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 17:06:13 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 17:09:04 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_fibonacci(int i) 14 | { 15 | if (i < 0) 16 | return (-1); 17 | if (i == 0) 18 | return (0); 19 | if (i == 1) 20 | return (1); 21 | return (ft_fibonacci(i - 1) + ft_fibonacci(i - 2)); 22 | } 23 | -------------------------------------------------------------------------------- /c08/ex00/ft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 12:36:48 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 12:41:16 by tmarx ### ########.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 | #endif 22 | -------------------------------------------------------------------------------- /c13/ex01/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 23:56:07 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | #endif 24 | -------------------------------------------------------------------------------- /c02/ex07/ft_strupcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strupcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 09:08:17 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 11:28:29 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strupcase(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (*(str + i)) 19 | { 20 | if (*(str + i) >= 97 && *(str + i) <= 122) 21 | *(str + i) -= 32; 22 | i++; 23 | } 24 | return (str); 25 | } 26 | -------------------------------------------------------------------------------- /c02/ex08/ft_strlowcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlowcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 09:21:00 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 11:30:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strlowcase(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (*(str + i)) 19 | { 20 | if (*(str + i) >= 65 && *(str + i) <= 90) 21 | *(str + i) += 32; 22 | i++; 23 | } 24 | return (str); 25 | } 26 | -------------------------------------------------------------------------------- /c12/ex01/ft_list_push_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:51:59 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 09:32:04 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_push_front(t_list **list, void *data) 16 | { 17 | t_list *elem; 18 | 19 | elem = ft_create_elem(data); 20 | if (*list) 21 | elem->next = *list; 22 | *list = elem; 23 | } 24 | -------------------------------------------------------------------------------- /c12/ex03/ft_list_last.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_last.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 20:09:50 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 20:12:05 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | t_list *ft_list_last(t_list *list) 16 | { 17 | t_list *current; 18 | 19 | current = list; 20 | while (current->next) 21 | { 22 | current = current->next; 23 | } 24 | return (current); 25 | } 26 | -------------------------------------------------------------------------------- /c05/ex00/ft_iterative_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 00:03:36 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 09:18:38 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_iterative_factorial(int nb) 14 | { 15 | int res; 16 | 17 | if (nb < 0) 18 | return (0); 19 | if (nb == 0) 20 | return (1); 21 | res = nb; 22 | while (nb-- > 2) 23 | res *= nb; 24 | return (res); 25 | } 26 | -------------------------------------------------------------------------------- /c05/ex01/ft_recursive_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 00:02:43 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 00:03:11 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_recursive_factorial(int nb) 14 | { 15 | if (nb == 2) 16 | return (2); 17 | if (nb == 1 || nb == 0) 18 | return (1); 19 | if (nb < 0) 20 | return (0); 21 | return (ft_recursive_factorial(nb - 1) * nb); 22 | } 23 | -------------------------------------------------------------------------------- /c05/ex05/ft_sqrt.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sqrt.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 17:12:35 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 20:55:59 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_sqrt(int nb) 14 | { 15 | long n; 16 | 17 | if (nb < 0) 18 | return (0); 19 | if (nb == 1) 20 | return (1); 21 | n = 1; 22 | while (n * n < nb) 23 | n++; 24 | if (n * n == nb) 25 | return (n); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /c05/ex03/ft_recursive_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 16:59:55 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 17:11:12 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_recursive_power(int nb, int power) 14 | { 15 | if (power < 0) 16 | return (0); 17 | if (power == 0) 18 | return (1); 19 | if (power == 1) 20 | return (nb); 21 | return (nb * ft_recursive_power(nb, power - 1)); 22 | } 23 | -------------------------------------------------------------------------------- /c11/ex03/ft_count_if.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_count_if.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 04:28:15 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 04:36:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_count_if(char **tab, int length, int (*f)(char*)) 14 | { 15 | int i; 16 | int res; 17 | 18 | i = 0; 19 | res = 0; 20 | while (i < length) 21 | { 22 | if (f(tab[i]) != 0) 23 | res++; 24 | i++; 25 | } 26 | return (res); 27 | } 28 | -------------------------------------------------------------------------------- /c12/ex02/ft_list_size.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_size.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 20:05:37 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 20:08:34 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | int ft_list_size(t_list *list) 16 | { 17 | t_list *current; 18 | int i; 19 | 20 | i = 0; 21 | current = list; 22 | while (current) 23 | { 24 | i++; 25 | current = current->next; 26 | } 27 | return (i); 28 | } 29 | -------------------------------------------------------------------------------- /c13/ex00/btree_create_node.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_create_node.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:51:52 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 09:59:58 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | t_btree *btree_create_node(void *item) 16 | { 17 | t_btree *el; 18 | 19 | if (!(el = malloc(sizeof(t_btree)))) 20 | return (0); 21 | el->left = 0; 22 | el->right = 0; 23 | el->item = item; 24 | return (el); 25 | } 26 | -------------------------------------------------------------------------------- /c13/ex00/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex02/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex03/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex04/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex05/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex06/ft_btree.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_btree.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 03:48:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 10:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BTREE_H 14 | # define FT_BTREE_H 15 | # include 16 | 17 | typedef struct s_btree 18 | { 19 | struct s_btree *left; 20 | struct s_btree *right; 21 | void *item; 22 | } t_btree; 23 | t_btree *btree_create_node(void *item); 24 | #endif 25 | -------------------------------------------------------------------------------- /c05/ex02/ft_iterative_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 16:08:19 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 16:14:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_iterative_power(int nb, int power) 14 | { 15 | int res; 16 | int i; 17 | 18 | if (power < 0) 19 | return (0); 20 | if (power == 0) 21 | return (1); 22 | res = nb; 23 | i = power - 1; 24 | while (i--) 25 | res *= nb; 26 | return (res); 27 | } 28 | -------------------------------------------------------------------------------- /c12/ex09/ft_list_foreach.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_foreach.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 10:12:14 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 11:03:52 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)) 16 | { 17 | t_list *el; 18 | 19 | if (!begin_list) 20 | return ; 21 | el = begin_list; 22 | while (el) 23 | { 24 | f(el->data); 25 | el = el->next; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /c12/ex00/ft_create_elem.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_create_elem.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 19:39:58 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 19:51:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | 16 | t_list *ft_create_elem(void *data) 17 | { 18 | t_list *res; 19 | 20 | res = 0; 21 | if ((res = malloc(sizeof(t_list)))) 22 | { 23 | res->data = data; 24 | res->next = 0; 25 | } 26 | return (res); 27 | } 28 | -------------------------------------------------------------------------------- /c13/ex03/btree_apply_suffix.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_apply_suffix.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 05:36:32 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/20 06:18:57 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | void btree_apply_suffix(t_btree *root, void (*applyf)(void *)) 16 | { 17 | if (root->left) 18 | btree_apply_suffix(root->left, applyf); 19 | if (root->right) 20 | btree_apply_suffix(root->right, applyf); 21 | applyf(root->item); 22 | } 23 | -------------------------------------------------------------------------------- /c02/ex01/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 08:19:53 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/05 00:43:44 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strncpy(char *dest, char *src, unsigned int n) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | while (i < n && src[i]) 19 | { 20 | dest[i] = src[i]; 21 | i++; 22 | } 23 | while (i < n) 24 | { 25 | dest[i] = 0x00; 26 | i++; 27 | } 28 | return (dest); 29 | } 30 | -------------------------------------------------------------------------------- /c03/ex01/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* st_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 17:09:59 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 13:25:35 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strncmp(char *s1, char *s2, unsigned int n) 14 | { 15 | unsigned int i; 16 | 17 | if (!n) 18 | return (0); 19 | i = 0; 20 | while (i < n && s1[i] && s2[i] && s1[i] == s2[i]) 21 | i++; 22 | if (i < n) 23 | return (s1[i] - s2[i]); 24 | else 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /c11/ex01/ft_map.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_map.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 04:19:03 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 14:50:43 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int *ft_map(int *tab, int length, int (*f)(int)) 16 | { 17 | int *res; 18 | int i; 19 | 20 | i = 0; 21 | res = (int*)malloc(sizeof(int) * length); 22 | while (i < length) 23 | { 24 | res[i] = f(tab[i]); 25 | i++; 26 | } 27 | return (res); 28 | } 29 | -------------------------------------------------------------------------------- /c01/ex07/ft_rev_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 15:42:18 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 16:09:17 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_rev_int_tab(int *tab, int size) 14 | { 15 | int buffer[size]; 16 | int i; 17 | int j; 18 | 19 | i = 0; 20 | while (i++ < size) 21 | { 22 | buffer[size - i] = *(tab + i - 1); 23 | } 24 | j = 0; 25 | while (j++ < size) 26 | { 27 | tab[j - 1] = buffer[j - 1]; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /c12/ex11/ft_list_find.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_find.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 10:46:08 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 11:05:19 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) 16 | { 17 | t_list *el; 18 | 19 | el = begin_list; 20 | while (el) 21 | { 22 | if (cmp(el->data, data_ref) == 0) 23 | return (el); 24 | el = el->next; 25 | } 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /c11/ex05/header.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* header.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 12:42:05 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 14:55:04 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HEADER_H 14 | # define HEADER_H 15 | # include 16 | 17 | int ft_atoi(char *str); 18 | void ft_putnbr(int a); 19 | void process(int a, int b, void (*f)(int, int)); 20 | void add(int a, int b); 21 | void mult(int a, int b); 22 | void div(int a, int b); 23 | void mod(int a, int b); 24 | #endif 25 | -------------------------------------------------------------------------------- /c13/ex02/btree_apply_infix.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_apply_infix.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 04:29:19 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/20 06:18:38 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | void btree_apply_infix(t_btree *root, void (*applyf)(void *)) 16 | { 17 | if (!root) 18 | return ; 19 | if (root->left) 20 | btree_apply_infix(root->left, applyf); 21 | applyf(root->item); 22 | if (root->right) 23 | btree_apply_infix(root->right, applyf); 24 | } 25 | -------------------------------------------------------------------------------- /c03/ex03/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 00:04:28 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/06 17:57:53 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strncat(char *dest, char *src, unsigned int nb) 14 | { 15 | unsigned int j; 16 | unsigned int i; 17 | 18 | i = 0; 19 | j = 0; 20 | while (dest[i]) 21 | i++; 22 | while (src[j] && j < nb) 23 | { 24 | dest[i + j] = src[j]; 25 | j++; 26 | } 27 | dest[i + j] = '\0'; 28 | return (dest); 29 | } 30 | -------------------------------------------------------------------------------- /c12/ex10/ft_list_foreach_if.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_foreach_if.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 10:36:56 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 11:04:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), void 16 | *data_ref, int (*cmp)()) 17 | { 18 | t_list *el; 19 | 20 | el = begin_list; 21 | while (el) 22 | { 23 | if (cmp(el->data, data_ref) == 0) 24 | f(el->data); 25 | el = el->next; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /c13/ex01/btree_apply_prefix.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_apply_prefix.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/20 04:24:25 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/22 00:42:40 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) 16 | { 17 | if (!root) 18 | return ; 19 | applyf(root->item); 20 | if (root->left) 21 | btree_apply_prefix(root->left, applyf); 22 | if (root->right) 23 | btree_apply_prefix(root->right, applyf); 24 | } 25 | -------------------------------------------------------------------------------- /c06/ex00/ft_print_program_name.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_program_name.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/08 15:56:06 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 01:05:37 by tmarx ### ########.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 | int main(int argc, char **argv) 26 | { 27 | argc++; 28 | write(1, argv[0], ft_strlen(argv[0])); 29 | write(1, "\n", 1); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /c12/ex07/ft_list_at.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_at.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 08:35:53 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 11:39:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr) 16 | { 17 | t_list *list; 18 | unsigned int i; 19 | 20 | i = 0; 21 | list = begin_list; 22 | while (i < nbr) 23 | { 24 | if (!list) 25 | return (0); 26 | list = list->next; 27 | i++; 28 | } 29 | return (list); 30 | } 31 | -------------------------------------------------------------------------------- /c11/ex04/ft_is_sort.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_sort.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 04:38:27 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/18 14:34:56 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_sort(int *tab, int length, int (*f)(int, int)) 14 | { 15 | int a; 16 | int d; 17 | int i; 18 | 19 | a = 1; 20 | d = 1; 21 | i = 1; 22 | while (i < length) 23 | { 24 | if (f(tab[i - 1], tab[i]) > 0) 25 | d = 0; 26 | if (f(tab[i - 1], tab[i]) < 0) 27 | a = 0; 28 | i++; 29 | } 30 | return (a || d); 31 | } 32 | -------------------------------------------------------------------------------- /c08/ex01/ft_boolean.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_boolean.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 12:42:10 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 12:57:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BOOLEAN_H 14 | # define FT_BOOLEAN_H 15 | # include 16 | # define TRUE 1 17 | # define FALSE 0 18 | # define EVEN(x) (x % 2 == 0) 19 | # define EVEN_MSG "I have an even number of arguments.\n" 20 | # define ODD_MSG "I have an odd number of arguments.\n" 21 | # define SUCCESS 0 22 | 23 | typedef int t_bool; 24 | #endif 25 | -------------------------------------------------------------------------------- /c12/ex06/ft_list_clear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_clear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 08:25:32 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 11:41:57 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | 16 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)) 17 | { 18 | t_list *ptr; 19 | 20 | while (begin_list) 21 | { 22 | ptr = begin_list->next; 23 | free_fct(begin_list->data); 24 | free(begin_list); 25 | begin_list = ptr; 26 | } 27 | begin_list = 0; 28 | } 29 | -------------------------------------------------------------------------------- /c07/ex01/ft_range.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_range.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/09 11:24:52 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 12:07:52 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int *ft_range(int min, int max) 16 | { 17 | int i; 18 | int *res; 19 | 20 | if (min >= max) 21 | return (0); 22 | res = malloc(sizeof(int) * (max - min)); 23 | if (!res) 24 | return (0); 25 | i = 0; 26 | while (i + min < max) 27 | { 28 | res[i] = min + i; 29 | i++; 30 | } 31 | return (res); 32 | } 33 | -------------------------------------------------------------------------------- /c12/ex04/ft_list_push_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/18 22:51:00 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 18:34:28 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_push_back(t_list **begin_list, void *data) 16 | { 17 | t_list *list; 18 | 19 | if (!(*begin_list)) 20 | { 21 | *begin_list = ft_create_elem(data); 22 | return ; 23 | } 24 | list = *begin_list; 25 | while (list->next) 26 | list = list->next; 27 | list->next = ft_create_elem(data); 28 | } 29 | -------------------------------------------------------------------------------- /c12/ex13/ft_list_merge.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_merge.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 16:27:15 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 18:05:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_merge(t_list **begin_list1, t_list *begin_list2) 16 | { 17 | t_list *list; 18 | 19 | if (!(*begin_list1)) 20 | { 21 | *begin_list1 = begin_list2; 22 | return ; 23 | } 24 | list = *begin_list1; 25 | while (list->next) 26 | { 27 | list = list->next; 28 | } 29 | list->next = begin_list2; 30 | } 31 | -------------------------------------------------------------------------------- /c13/ex06/btree_level_count.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_level_count.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/24 18:58:00 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/24 18:58:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | int cmp(int left, int right) 16 | { 17 | if (left > right) 18 | return (left); 19 | else 20 | return (right); 21 | } 22 | 23 | int btree_level_count(t_btree *root) 24 | { 25 | if (!root) 26 | return (0); 27 | return (1 + cmp(btree_level_count(root->left), 28 | btree_level_count(root->right))); 29 | } 30 | -------------------------------------------------------------------------------- /c03/ex04/ft_strstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 00:27:40 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/05 01:38:25 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | char *ft_strstr(char *str, char *to_find) 14 | { 15 | int i; 16 | int j; 17 | 18 | if (*to_find == '\0') 19 | return (str); 20 | i = 0; 21 | while (str[i]) 22 | { 23 | j = 0; 24 | while (to_find[j] == str[i + j]) 25 | { 26 | if (to_find[j + 1] == '\0') 27 | { 28 | return (str + i); 29 | } 30 | j++; 31 | } 32 | i++; 33 | } 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /c06/ex02/ft_rev_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/08 16:15:12 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 10:48:58 by tmarx ### ########.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 | int main(int argc, char **argv) 26 | { 27 | int i; 28 | 29 | i = argc - 1; 30 | while (i) 31 | { 32 | write(1, argv[i], ft_strlen(argv[i])); 33 | write(1, "\n", 1); 34 | i--; 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /c06/ex01/ft_print_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/08 16:06:35 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 10:48:41 by tmarx ### ########.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 | int main(int argc, char **argv) 26 | { 27 | int i; 28 | 29 | i = 1; 30 | while (i < argc) 31 | { 32 | write(1, argv[i], ft_strlen(argv[i])); 33 | write(1, "\n", 1); 34 | i++; 35 | } 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /c12/ex08/ft_list_reverse.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_reverse.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 08:39:37 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 18:41:05 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_reverse(t_list **begin_list) 16 | { 17 | t_list *prev; 18 | t_list *next; 19 | t_list *current; 20 | 21 | prev = 0; 22 | next = 0; 23 | current = *begin_list; 24 | while (current) 25 | { 26 | next = current->next; 27 | current->next = prev; 28 | prev = current; 29 | current = next; 30 | } 31 | *begin_list = prev; 32 | } 33 | -------------------------------------------------------------------------------- /c05/ex06/ft_is_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 20:57:23 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 09:23:45 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_prime(int nb) 14 | { 15 | long i; 16 | 17 | if (nb == 1) 18 | return (0); 19 | if (nb == 2 || nb == 3) 20 | return (1); 21 | if (nb <= 0) 22 | return (0); 23 | else if (nb % 2 == 0 || nb % 3 == 0) 24 | return (0); 25 | i = 5; 26 | while (i * i <= nb) 27 | { 28 | if (nb % i == 0 || nb % (i + 2) == 0) 29 | return (0); 30 | i += 6; 31 | } 32 | return (1); 33 | } 34 | -------------------------------------------------------------------------------- /c02/ex10/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 11:45:15 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 02:19:55 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | if (size >= 1) 19 | { 20 | while (i < size - 1 && src[i]) 21 | { 22 | dest[i] = src[i]; 23 | i++; 24 | } 25 | while (i < size) 26 | { 27 | dest[i] = '\0'; 28 | i++; 29 | } 30 | } 31 | i = 0; 32 | while (src[i++]) 33 | { 34 | } 35 | return (i - 1); 36 | } 37 | -------------------------------------------------------------------------------- /c03/ex05/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 01:27:25 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/07 13:24:58 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | unsigned int ft_strlcat(char *dest, char *src, unsigned int size) 14 | { 15 | unsigned int i; 16 | unsigned int j; 17 | unsigned int r; 18 | 19 | i = 0; 20 | j = 0; 21 | r = 0; 22 | while (dest[i]) 23 | i++; 24 | while (src[r]) 25 | r++; 26 | if (size <= i) 27 | r += size; 28 | else 29 | r += i; 30 | while (src[j] && i + 1 < size) 31 | dest[i++] = src[j++]; 32 | dest[i] = '\0'; 33 | return (r); 34 | } 35 | -------------------------------------------------------------------------------- /c01/ex08/ft_sort_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 16:10:05 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 16:23:57 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_swap(int *a, int *b) 14 | { 15 | int c; 16 | 17 | c = *a; 18 | *a = *b; 19 | *b = c; 20 | } 21 | 22 | void ft_sort_int_tab(int *tab, int size) 23 | { 24 | int i; 25 | int j; 26 | 27 | i = 0; 28 | while (i < size) 29 | { 30 | j = i + 1; 31 | while (j < size) 32 | { 33 | if (tab[j] < tab[i]) 34 | { 35 | ft_swap(tab + j, tab + i); 36 | } 37 | j++; 38 | } 39 | i++; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /c07/ex02/ft_ultimate_range.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_range.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/09 12:40:41 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 23:44:34 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_ultimate_range(int **range, int min, int max) 16 | { 17 | int i; 18 | int *tab; 19 | 20 | if (min >= max) 21 | { 22 | *range = 0; 23 | return (0); 24 | } 25 | tab = malloc(sizeof(int) * (max - min)); 26 | if (!tab) 27 | return (-1); 28 | i = 0; 29 | while (min + i < max) 30 | { 31 | tab[i] = min + i; 32 | i++; 33 | } 34 | *range = tab; 35 | return (i); 36 | } 37 | -------------------------------------------------------------------------------- /c10/ex02/ft_tail.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_tail.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:54:46 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:02:25 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tail.h" 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int option; 18 | char *str; 19 | 20 | if (argc < 2) 21 | { 22 | return (0); 23 | } 24 | option = ft_atoi(argv[2], 0); 25 | if (option == -1) 26 | { 27 | ft_illegal_offset(argv); 28 | return (0); 29 | } 30 | if (argc == 3) 31 | { 32 | ft_putstr(get_stdin(option)); 33 | } 34 | else 35 | str = ft_write(argv, argc, option); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /c13/ex05/btree_search_item.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_search_item.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/24 18:57:45 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/24 18:57:48 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | void *btree_search_item(t_btree *root, void *data_ref, 16 | int (*cmpf)(void *, void *)) 17 | { 18 | void *item_found; 19 | 20 | if (root == 0) 21 | return (0); 22 | if ((item_found = btree_search_item(root->left, data_ref, cmpf))) 23 | return (item_found); 24 | if (!cmpf(root->item, data_ref)) 25 | return (root->item); 26 | return (btree_search_item(root->right, data_ref, cmpf)); 27 | } 28 | -------------------------------------------------------------------------------- /c12/ex05/ft_list_push_strs.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_strs.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/18 23:14:44 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 18:13:28 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_push_front2(t_list **list, void *data) 16 | { 17 | t_list *elem; 18 | 19 | elem = ft_create_elem(data); 20 | if (*list) 21 | elem->next = *list; 22 | *list = elem; 23 | } 24 | 25 | t_list *ft_list_push_strs(int size, char **strs) 26 | { 27 | int i; 28 | t_list *begin; 29 | 30 | begin = 0; 31 | i = 0; 32 | while (i < size) 33 | ft_list_push_front2(&begin, strs[i++]); 34 | return (begin); 35 | } 36 | -------------------------------------------------------------------------------- /c04/ex02/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 12:26:51 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/06 20:24:26 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_digit(int n) 16 | { 17 | n += 48; 18 | write(1, &n, 1); 19 | } 20 | 21 | void ft_putnbr(int n) 22 | { 23 | if (n <= -2147483648) 24 | { 25 | write(1, "-2147483648", 11); 26 | return ; 27 | } 28 | if (n < 0) 29 | { 30 | write(1, "-", 1); 31 | ft_putnbr(-n); 32 | return ; 33 | } 34 | if (n < 10) 35 | { 36 | ft_print_digit(n); 37 | } 38 | else 39 | { 40 | ft_putnbr(n / 10); 41 | ft_print_digit(n % 10); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /c11/ex05/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 12:26:51 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 13:00:39 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "header.h" 14 | 15 | void ft_print_digit(int n) 16 | { 17 | n += 48; 18 | write(1, &n, 1); 19 | } 20 | 21 | void ft_putnbr(int n) 22 | { 23 | if (n <= -2147483648) 24 | { 25 | write(1, "-2147483648", 11); 26 | return ; 27 | } 28 | if (n < 0) 29 | { 30 | write(1, "-", 1); 31 | ft_putnbr(-n); 32 | return ; 33 | } 34 | if (n < 10) 35 | { 36 | ft_print_digit(n); 37 | } 38 | else 39 | { 40 | ft_putnbr(n / 10); 41 | ft_print_digit(n % 10); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /c11/ex05/ft_op.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_op.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 12:38:37 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 18:57:40 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "header.h" 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int a; 18 | int b; 19 | 20 | if (argc != 4) 21 | return (0); 22 | a = ft_atoi(argv[1]); 23 | b = ft_atoi(argv[3]); 24 | if (argv[2][0] == '-') 25 | process(a, -b, &add); 26 | else if (argv[2][0] == '+') 27 | process(a, b, &add); 28 | else if (argv[2][0] == '*') 29 | process(a, b, &mult); 30 | else if (argv[2][0] == '/') 31 | process(a, b, &div); 32 | else if (argv[2][0] == '%') 33 | process(a, b, &mod); 34 | else 35 | write(1, "0\n", 2); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /c00/ex06/ft_print_comb2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/03 08:13:24 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/03 09:13:01 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_digit(int n) 16 | { 17 | n += 48; 18 | write(1, &n, 1); 19 | } 20 | 21 | void ft_print_comb2(void) 22 | { 23 | int a; 24 | int b; 25 | 26 | a = 0; 27 | while (a <= 98) 28 | { 29 | b = a + 1; 30 | while (b <= 99) 31 | { 32 | ft_print_digit(a / 10); 33 | ft_print_digit(a % 10); 34 | write(1, " ", 1); 35 | ft_print_digit(b / 10); 36 | ft_print_digit(b % 10); 37 | if (a != 98 || b != 99) 38 | { 39 | write(1, ", ", 2); 40 | } 41 | b++; 42 | } 43 | a++; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /c10/ex02/ft_on_str.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_on_str.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:53:35 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:02:02 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tail.h" 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 | int ft_is_numeric(char c) 26 | { 27 | if (c >= '0' && c <= '9') 28 | return (1); 29 | return (0); 30 | } 31 | 32 | int ft_atoi(char *str, int j) 33 | { 34 | int i; 35 | int res; 36 | 37 | res = 0; 38 | i = j; 39 | if (!ft_is_numeric(str[i])) 40 | return (-1); 41 | while (ft_is_numeric(str[i])) 42 | { 43 | res = res * 10 + (str[i] - '0'); 44 | i++; 45 | } 46 | return (res); 47 | } 48 | -------------------------------------------------------------------------------- /bsq/src/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: vgoldman +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/07 12:56:48 by vgoldman #+# #+# */ 9 | /* Updated: 2019/07/09 16:28:31 by vgoldman ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_atoi(char *str) 14 | { 15 | long long int res; 16 | int i; 17 | int sign; 18 | 19 | res = 0; 20 | i = 0; 21 | sign = 1; 22 | while (str[i] != '\0' && (str[i] == '\f' || str[i] == '\n' || 23 | str[i] == '\r' || str[i] == '\t' || str[i] == '\v' || 24 | str[i] == ' ')) 25 | i++; 26 | while (str[i] == '-' || str[i] == '+') 27 | { 28 | if (str[i] == '-') 29 | sign *= -1; 30 | i++; 31 | } 32 | while (str[i] != '\0' && str[i] >= '0' && str[i] <= '9') 33 | { 34 | res = res * 10 + (str[i] - '0'); 35 | i++; 36 | } 37 | return ((int)res * sign); 38 | } 39 | -------------------------------------------------------------------------------- /c07/ex00/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/09 11:13:03 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 11:23:37 by tmarx ### ########.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 | char *ft_strcpy(char *dest, char *src) 26 | { 27 | int i; 28 | 29 | i = 0; 30 | while (src[i]) 31 | { 32 | dest[i] = src[i]; 33 | i++; 34 | } 35 | dest[i] = '\0'; 36 | return (dest); 37 | } 38 | 39 | char *ft_strdup(char *src) 40 | { 41 | int len; 42 | char *res; 43 | 44 | len = ft_strlen(src) + 1; 45 | res = malloc(len); 46 | if (!res) 47 | return (0); 48 | ft_strcpy(res, src); 49 | return (res); 50 | } 51 | -------------------------------------------------------------------------------- /c11/ex05/ft_op2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_op2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/17 12:46:54 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/17 14:55:16 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "header.h" 14 | 15 | void add(int a, int b) 16 | { 17 | ft_putnbr(a + b); 18 | } 19 | 20 | void mult(int a, int b) 21 | { 22 | ft_putnbr(a * b); 23 | } 24 | 25 | void div(int a, int b) 26 | { 27 | if (b == 0) 28 | { 29 | write(1, "Stop : division by zero", 23); 30 | return ; 31 | } 32 | ft_putnbr(a / b); 33 | } 34 | 35 | void mod(int a, int b) 36 | { 37 | if (b == 0) 38 | { 39 | write(1, "Stop : modulo by zero", 21); 40 | return ; 41 | } 42 | ft_putnbr(a % b); 43 | } 44 | 45 | void process(int a, int b, void (*f)(int, int)) 46 | { 47 | f(a, b); 48 | write(1, "\n", 1); 49 | } 50 | -------------------------------------------------------------------------------- /c13/ex04/btree_insert_data.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* btree_insert_data.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/24 18:57:30 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/24 18:57:35 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_btree.h" 14 | 15 | void btree_insert_data(t_btree **root, void *item, 16 | int (*cmpf)(void *, void *)) 17 | { 18 | t_btree *node; 19 | 20 | if (!*root) 21 | { 22 | *root = btree_create_node(item); 23 | return ; 24 | } 25 | node = *root; 26 | if (cmpf(item, node->item) < 0) 27 | { 28 | if (node->left) 29 | btree_insert_data(&node->left, item, cmpf); 30 | else 31 | node->left = btree_create_node(item); 32 | } 33 | else 34 | { 35 | if (node->right) 36 | btree_insert_data(&node->right, item, cmpf); 37 | else 38 | node->right = btree_create_node(item); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /c11/ex06/ft_sort_string_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_string_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/18 01:48:48 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/18 13:40:49 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strcmp(char *s1, char *s2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (s1[i] && s2[i] && s1[i] == s2[i]) 19 | i++; 20 | return (s1[i] - s2[i]); 21 | } 22 | 23 | void ft_swap(void **p1, void **p2) 24 | { 25 | void *temp; 26 | 27 | temp = *p1; 28 | *p1 = *p2; 29 | *p2 = temp; 30 | } 31 | 32 | void ft_sort_string_tab(char **tab) 33 | { 34 | int i; 35 | int j; 36 | 37 | i = 0; 38 | while (tab[i + 1]) 39 | { 40 | j = i + 1; 41 | while (tab[j]) 42 | { 43 | if (ft_strcmp(tab[i], tab[j]) > 0) 44 | { 45 | ft_swap((void**)&tab[i], (void**)&tab[j]); 46 | } 47 | j++; 48 | } 49 | i++; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /c12/ex12/ft_list_remove_if.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_remove_if.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 15:12:24 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 23:27:39 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | 16 | void ft_list_remove_if(t_list **begin_list, void *data_ref, 17 | int (*cmp)(), void (*free_fct)(void *)) 18 | { 19 | t_list *tmp; 20 | t_list *el; 21 | 22 | while (*begin_list && cmp((*begin_list)->data, data_ref) == 0) 23 | { 24 | tmp = *begin_list; 25 | *begin_list = (*begin_list)->next; 26 | free_fct(tmp->data); 27 | free(tmp); 28 | } 29 | el = *begin_list; 30 | while (el && el->next) 31 | { 32 | if (cmp(el->next->data, data_ref) == 0) 33 | { 34 | tmp = el->next; 35 | el->next = tmp->next; 36 | free_fct(tmp->data); 37 | free(tmp); 38 | } 39 | el = el->next; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /c04/ex03/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 12:30:17 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/08 17:48:18 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_space(char c) 14 | { 15 | if (c == '\t' || c == '\n' || c == '\r' || 16 | c == '\v' || c == '\f' || c == ' ') 17 | return (1); 18 | return (0); 19 | } 20 | 21 | int ft_atoi(char *str) 22 | { 23 | int sign; 24 | int result; 25 | int i; 26 | 27 | sign = 1; 28 | result = 0; 29 | i = 0; 30 | while (ft_is_space(*str)) 31 | str++; 32 | while (*str == '-' || *str == '+') 33 | { 34 | if (*(str++) == '-') 35 | sign *= -1; 36 | } 37 | while (*str) 38 | { 39 | if (*str >= '0' && *str <= '9') 40 | { 41 | result *= 10; 42 | result += (*(str++) - '0'); 43 | } 44 | else 45 | return (result * sign); 46 | } 47 | return (result * sign); 48 | } 49 | -------------------------------------------------------------------------------- /c10/ex02/get.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* get.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:55:36 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:01:51 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tail.h" 14 | 15 | char *get_stdin(int option) 16 | { 17 | char buffer[524288]; 18 | char *res; 19 | int size; 20 | int i; 21 | 22 | i = 0; 23 | size = 0; 24 | while (read(0, &buffer[size], 1) != 0) 25 | size++; 26 | res = ft_res(buffer, option, size); 27 | return (res); 28 | } 29 | 30 | char *ft_res(char *membuff, int option, int size) 31 | { 32 | char *res; 33 | int i; 34 | 35 | i = 0; 36 | res = malloc(option + 1); 37 | if (size - option > 0) 38 | { 39 | while (membuff[size - option + i]) 40 | { 41 | res[i] = membuff[size - option + i]; 42 | i++; 43 | } 44 | res[i] = 0; 45 | } 46 | else 47 | return (membuff); 48 | return (res); 49 | } 50 | -------------------------------------------------------------------------------- /c11/ex05/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/05 12:30:17 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/08 17:48:18 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_space(char c) 14 | { 15 | if (c == '\t' || c == '\n' || c == '\r' || 16 | c == '\v' || c == '\f' || c == ' ') 17 | return (1); 18 | return (0); 19 | } 20 | 21 | int ft_atoi(char *str) 22 | { 23 | int sign; 24 | int result; 25 | int i; 26 | 27 | sign = 1; 28 | result = 0; 29 | i = 0; 30 | while (ft_is_space(*str)) 31 | str++; 32 | while (*str == '-' || *str == '+') 33 | { 34 | if (*(str++) == '-') 35 | sign *= -1; 36 | } 37 | while (*str) 38 | { 39 | if (*str >= '0' && *str <= '9') 40 | { 41 | result *= 10; 42 | result += (*(str++) - '0'); 43 | } 44 | else 45 | return (result * sign); 46 | } 47 | return (result * sign); 48 | } 49 | -------------------------------------------------------------------------------- /c02/ex11/ft_putstr_non_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_non_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 12:15:20 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/10 10:56:12 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_char_is_printable(char c) 16 | { 17 | if (c >= 32 && c < 127) 18 | return (1); 19 | return (0); 20 | } 21 | 22 | void ft_hex(char c, char *res) 23 | { 24 | char *charset; 25 | 26 | charset = "0123456789abcdef"; 27 | res[1] = charset[(unsigned char)c % 16]; 28 | res[0] = charset[((unsigned char)c / 16)]; 29 | } 30 | 31 | void ft_putstr_non_printable(char *str) 32 | { 33 | char hex[2]; 34 | 35 | while (*str) 36 | { 37 | if (ft_char_is_printable(*str)) 38 | { 39 | write(1, str, 1); 40 | } 41 | else 42 | { 43 | write(1, "\\", 1); 44 | ft_hex(*str, hex); 45 | write(1, hex, 2); 46 | } 47 | str++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /c12/ex14/ft_list_sort.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_sort.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 22:43:10 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/20 00:09:34 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_swap(t_list **el1, t_list **el2) 16 | { 17 | void *tmp; 18 | 19 | tmp = (*el1)->data; 20 | (*el1)->data = (*el2)->data; 21 | (*el2)->data = tmp; 22 | } 23 | 24 | void ft_list_sort(t_list **begin_list, int (*cmp)()) 25 | { 26 | t_list *tmp1; 27 | t_list *tmp2; 28 | int i; 29 | 30 | i = 1; 31 | if (!(*begin_list) || !(*begin_list)->next) 32 | return ; 33 | while (i) 34 | { 35 | i = 0; 36 | tmp1 = *begin_list; 37 | tmp2 = tmp1->next; 38 | while (tmp2) 39 | { 40 | if (cmp(tmp1->data, tmp2->data) > 0) 41 | { 42 | ft_swap(&tmp1, &tmp2); 43 | i = 1; 44 | } 45 | tmp1 = tmp1->next; 46 | tmp2 = tmp2->next; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /c00/ex05/ft_print_comb.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/02 17:22:57 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/02 18:28:46 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_print_int(int a) 16 | { 17 | char *alphabet; 18 | 19 | alphabet = "0123456789"; 20 | write(1, alphabet + a, 1); 21 | } 22 | 23 | void ft_print_nums(int a, int b, int c) 24 | { 25 | ft_print_int(a); 26 | ft_print_int(b); 27 | ft_print_int(c); 28 | } 29 | 30 | void ft_print_comb(void) 31 | { 32 | int a; 33 | int b; 34 | int c; 35 | 36 | a = 0; 37 | while (a <= 7) 38 | { 39 | b = a + 1; 40 | while (b <= 8) 41 | { 42 | c = b + 1; 43 | while (c <= 9) 44 | { 45 | ft_print_nums(a, b, c); 46 | if (a != 7 || b != 8 || c != 9) 47 | { 48 | write(1, ", ", 2); 49 | } 50 | c += 1; 51 | } 52 | b += 1; 53 | } 54 | a += 1; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /c05/ex07/ft_find_next_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_find_next_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/08 15:18:08 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/12 13:28:27 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_is_prime(int nb) 14 | { 15 | long i; 16 | 17 | if (nb == 1) 18 | return (0); 19 | if (nb == 2 || nb == 3) 20 | return (1); 21 | if (nb <= 0) 22 | return (0); 23 | else if (nb % 2 == 0 || nb % 3 == 0) 24 | return (0); 25 | i = 5; 26 | while (i * i <= nb) 27 | { 28 | if (nb % i == 0 || nb % (i + 2) == 0) 29 | return (0); 30 | i += 6; 31 | } 32 | return (1); 33 | } 34 | 35 | int ft_find_next_prime(int nb) 36 | { 37 | int i; 38 | 39 | if (ft_is_prime(nb)) 40 | return (nb); 41 | i = 1; 42 | while (!ft_is_prime(nb + i)) 43 | i++; 44 | return (nb + i); 45 | } 46 | 47 | #include 48 | int main(void) 49 | { 50 | printf("%d", ft_find_next_prime(-2143647)); 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /c06/ex03/ft_sort_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/08 16:17:47 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/09 10:48:17 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | while (*str) 18 | write(1, str++, 1); 19 | } 20 | 21 | void ft_swap(char **s1, char **s2) 22 | { 23 | char *t; 24 | 25 | t = *s1; 26 | *s1 = *s2; 27 | *s2 = t; 28 | } 29 | 30 | int ft_strcmp(char *s1, char *s2) 31 | { 32 | int i; 33 | 34 | i = 0; 35 | while (s1[i] && s2[i] && s1[i] == s2[i]) 36 | i++; 37 | return (s1[i] - s2[i]); 38 | } 39 | 40 | int main(int argc, char **argv) 41 | { 42 | int i; 43 | int j; 44 | 45 | i = 1; 46 | while (i++ < argc) 47 | { 48 | j = 1; 49 | while (j < argc - 1) 50 | { 51 | if (ft_strcmp(argv[j], argv[j + 1]) > 0) 52 | ft_swap(&argv[j], &argv[j + 1]); 53 | j++; 54 | } 55 | } 56 | i = 1; 57 | while (i < argc) 58 | { 59 | ft_putstr(argv[i++]); 60 | write(1, "\n", 1); 61 | } 62 | return (0); 63 | } 64 | -------------------------------------------------------------------------------- /c02/ex09/ft_strcapitalize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcapitalize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/04 09:27:31 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/04 11:40:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_char_is_alphnum(char c) 14 | { 15 | if (c >= 65 && c <= 90) 16 | return (1); 17 | if (c >= 97 && c <= 122) 18 | return (2); 19 | if (c >= 48 && c <= 57) 20 | return (3); 21 | return (0); 22 | } 23 | 24 | void ft_char_upper(char *c) 25 | { 26 | if (ft_char_is_alphnum(*c) == 2) 27 | *c -= 32; 28 | } 29 | 30 | void ft_char_lower(char *c) 31 | { 32 | if (ft_char_is_alphnum(*c) == 1) 33 | *c += 32; 34 | } 35 | 36 | char *ft_strcapitalize(char *str) 37 | { 38 | char b; 39 | int type_b; 40 | int type; 41 | int i; 42 | 43 | ft_char_upper(str); 44 | i = 1; 45 | while (*(str + i)) 46 | { 47 | b = *(str + i - 1); 48 | type_b = ft_char_is_alphnum(b); 49 | type = ft_char_is_alphnum(*(str + i)); 50 | if (type_b == 0) 51 | { 52 | ft_char_upper(str + i); 53 | } 54 | else 55 | { 56 | ft_char_lower(str + i); 57 | } 58 | i++; 59 | } 60 | return (str); 61 | } 62 | -------------------------------------------------------------------------------- /c08/ex04/ft_strs_to_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strs_to_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 14:57:17 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/12 12:31:16 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "ft_stock_str.h" 15 | 16 | int ft_strlen(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i]) 22 | i++; 23 | return (i); 24 | } 25 | 26 | char *ft_str_clone(char *str) 27 | { 28 | char *res; 29 | int i; 30 | 31 | res = malloc(ft_strlen(str) + 1); 32 | i = 0; 33 | while (str[i]) 34 | { 35 | res[i] = str[i]; 36 | i++; 37 | } 38 | res[i] = '\0'; 39 | return (res); 40 | } 41 | 42 | struct s_stock_str *ft_strs_to_tab(int ac, char **av) 43 | { 44 | int i; 45 | t_stock_str *res; 46 | 47 | res = malloc((ac + 1) * sizeof(t_stock_str)); 48 | if (!res) 49 | return (0); 50 | i = 0; 51 | while (i < ac) 52 | { 53 | res[i].size = ft_strlen(av[i]); 54 | res[i].str = av[i]; 55 | res[i].copy = ft_str_clone(av[i]); 56 | i++; 57 | } 58 | res[i].size = 0; 59 | res[i].str = 0; 60 | res[i].copy = 0; 61 | return ((struct s_stock_str*)res); 62 | } 63 | -------------------------------------------------------------------------------- /c10/ex00/ft_display_file.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_display_file.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/25 13:57:34 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/25 13:57:37 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_strlen(char *str) 17 | { 18 | char *s; 19 | 20 | s = str; 21 | while (*str) 22 | str++; 23 | return (str - s); 24 | } 25 | 26 | void ft_putstr(int chan, char *str) 27 | { 28 | write(chan, str, ft_strlen(str)); 29 | } 30 | 31 | void ft_display_file(char *file) 32 | { 33 | int fd; 34 | int n; 35 | char buffer[4096]; 36 | 37 | fd = open(file, 0); 38 | if (fd == -1) 39 | { 40 | ft_putstr(2, "Cannot read file.\n"); 41 | return ; 42 | } 43 | while ((n = read(fd, buffer, 4096)) > 0) 44 | { 45 | write(1, buffer, n); 46 | } 47 | close(fd); 48 | } 49 | 50 | int main(int argc, char **argv) 51 | { 52 | (void)argv; 53 | if (argc < 2) 54 | { 55 | ft_putstr(2, "File name missing.\n"); 56 | return (0); 57 | } 58 | else if (argc > 2) 59 | { 60 | ft_putstr(2, "Too many arguments.\n"); 61 | return (0); 62 | } 63 | ft_display_file(argv[1]); 64 | return (0); 65 | } 66 | -------------------------------------------------------------------------------- /c08/ex05/ft_show_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_show_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/10 15:51:24 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/12 12:46:55 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "ft_stock_str.h" 15 | 16 | void ft_putstr(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i]) 22 | { 23 | write(1, &str[i], 1); 24 | i++; 25 | } 26 | } 27 | 28 | void ft_print_digit(int n) 29 | { 30 | n += 48; 31 | write(1, &n, 1); 32 | } 33 | 34 | void ft_putnbr(int n) 35 | { 36 | if (n < 0) 37 | { 38 | write(1, "-", 1); 39 | ft_putnbr(-n); 40 | return ; 41 | } 42 | if (n < 10) 43 | { 44 | ft_print_digit(n); 45 | } 46 | else 47 | { 48 | ft_putnbr(n / 10); 49 | ft_print_digit(n % 10); 50 | } 51 | } 52 | 53 | void ft_show_tab(struct s_stock_str *tab) 54 | { 55 | int i; 56 | t_stock_str temp; 57 | 58 | i = 0; 59 | while (((t_stock_str*)tab)[i].str) 60 | { 61 | temp = ((t_stock_str*)tab)[i]; 62 | ft_putstr(temp.str); 63 | ft_putstr("\n"); 64 | ft_putnbr(temp.size); 65 | ft_putstr("\n"); 66 | ft_putstr(temp.copy); 67 | ft_putstr("\n"); 68 | i++; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /c12/ex15/ft_list_reverse_fun.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_reverse_fun.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/21 18:17:54 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 19:17:07 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | int ft_list_size3(t_list *list) 16 | { 17 | t_list *current; 18 | int i; 19 | 20 | i = 0; 21 | current = list; 22 | while (current) 23 | { 24 | i++; 25 | current = current->next; 26 | } 27 | return (i); 28 | } 29 | 30 | t_list *ft_list_at3(t_list *begin_list, unsigned int nbr) 31 | { 32 | t_list *list; 33 | unsigned int i; 34 | 35 | i = 0; 36 | list = begin_list; 37 | while (i < nbr) 38 | { 39 | if (!list) 40 | return (0); 41 | list = list->next; 42 | i++; 43 | } 44 | return (list); 45 | } 46 | 47 | void ft_list_reverse_fun(t_list *begin_list) 48 | { 49 | int i; 50 | int l; 51 | void *tmp; 52 | 53 | i = 0; 54 | l = ft_list_size3(begin_list); 55 | while (i < l / 2) 56 | { 57 | tmp = ft_list_at3(begin_list, i)->data; 58 | ft_list_at3(begin_list, i)->data = 59 | ft_list_at3(begin_list, l - i - 1)->data; 60 | ft_list_at3(begin_list, l - i - 1)->data = tmp; 61 | i++; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /bsq/src/utility.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* utility.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: vgoldman +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/22 17:35:37 by vgoldman #+# #+# */ 9 | /* Updated: 2019/07/24 22:37:20 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "header.h" 14 | 15 | void create_grid(int x, int y, int ***grid, int is_aux) 16 | { 17 | int i; 18 | int j; 19 | 20 | i = 0; 21 | *grid = malloc(sizeof(int*) * x); 22 | while (i < x) 23 | { 24 | (*grid)[i] = malloc(sizeof(int) * y); 25 | i++; 26 | } 27 | i = 0; 28 | j = 0; 29 | while (i < x) 30 | { 31 | j = 0; 32 | while (j < y) 33 | { 34 | (*grid)[i][j] = is_aux; 35 | j++; 36 | } 37 | i++; 38 | } 39 | } 40 | 41 | void free_grid(t_map *map) 42 | { 43 | int i; 44 | 45 | i = 0; 46 | while (i < (map->x)) 47 | { 48 | free(map->grid[i]); 49 | free(map->grid_copy[i++]); 50 | } 51 | free(map->grid); 52 | free(map->grid_copy); 53 | } 54 | 55 | int min(int a, int b, int c) 56 | { 57 | int m; 58 | 59 | m = a; 60 | if (m > b) 61 | m = b; 62 | if (m > c) 63 | m = c; 64 | return (m); 65 | } 66 | 67 | void handle_map(t_map *map) 68 | { 69 | if (!map) 70 | { 71 | ft_putstr(2, "map error\n"); 72 | } 73 | else 74 | { 75 | process_map(map); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /c10/ex02/tail.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* tail.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:56:22 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:02:10 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef TAIL_H 14 | # define TAIL_H 15 | # include 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | 23 | int ft_strlen(char *str); 24 | int ft_is_numeric(char c); 25 | int ft_atoi(char *str, int j); 26 | void ft_puterror(char *str); 27 | void ft_putstr(char *str); 28 | int ft_error(int fd, char **argv, int i); 29 | void ft_banner(char **argv, int argc, int i); 30 | void ft_putfinal(int i, int argc); 31 | char *ft_write(char **argv, int argc, int option); 32 | int ft_count(char **argv, int i); 33 | int ft_init(char **argv); 34 | void ft_disp_stdin(void); 35 | int ft_flag(int flag, char **argv, int argc, int i); 36 | void ft_illegal_offset(char **argv); 37 | char *get_stdin(int option); 38 | char *stdin_memory(int size, char *res, char buffer); 39 | char *ft_res(char *membuff, int option, int size); 40 | char *ft_output(char *str, int option); 41 | void ft_display(int c_f[2], char *str, int fd); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /bsq/src/header.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* header.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: vgoldman +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/22 11:32:16 by vgoldman #+# #+# */ 9 | /* Updated: 2019/07/24 22:38:06 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef HEADER_H 14 | # define HEADER_H 15 | # include 16 | # include 17 | # include 18 | # include 19 | # define FIRST_LINE_BUFFER 200 20 | # define PRINT_LINE_NB 10 21 | # define X_BUFFER 50000 22 | 23 | typedef struct s_map 24 | { 25 | int x; 26 | int y; 27 | int **grid; 28 | int **grid_copy; 29 | char empty; 30 | char obst; 31 | char full; 32 | } t_map; 33 | int ft_atoi(char *str); 34 | t_map *map_parse(char *file); 35 | void create_grid(int x, int y, int ***grid, int is_aux); 36 | int check_lines(char *file, t_map *map); 37 | int min(int a, int b, int c); 38 | void compute_auxiliary(t_map *map); 39 | void biggest_square(t_map *map, int *top_i, int *left_i, int *size); 40 | void fill_grid_square(int ***grid, int x, int y, int size); 41 | int parse_grid(int fd, t_map *map); 42 | t_map *map_parse_stdin(void); 43 | void free_grid(t_map *map); 44 | void process_map(t_map *map); 45 | void handle_map(t_map *map); 46 | void ft_putstr(int channel, char *str); 47 | #endif 48 | -------------------------------------------------------------------------------- /shell00/ex01/testShell00.tar: -------------------------------------------------------------------------------- 1 | testShell00000455 106433 010321 00000000050 13474570450 014100 0ustar00tmarx2019_paris000000 000000 qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq 2 | -------------------------------------------------------------------------------- /c12/ex16/ft_sorted_list_insert.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sorted_list_insert.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/21 18:55:02 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 19:19:44 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_list_push_front3(t_list **list, void *data) 16 | { 17 | t_list *elem; 18 | 19 | elem = ft_create_elem(data); 20 | if (*list) 21 | elem->next = *list; 22 | *list = elem; 23 | } 24 | 25 | void ft_swap2(t_list **el1, t_list **el2) 26 | { 27 | void *tmp; 28 | 29 | tmp = (*el1)->data; 30 | (*el1)->data = (*el2)->data; 31 | (*el2)->data = tmp; 32 | } 33 | 34 | void ft_list_sort2(t_list **begin_list, int (*cmp)()) 35 | { 36 | t_list *tmp1; 37 | t_list *tmp2; 38 | int i; 39 | 40 | i = 1; 41 | if (!(*begin_list) || !(*begin_list)->next) 42 | return ; 43 | while (i) 44 | { 45 | i = 0; 46 | tmp1 = *begin_list; 47 | tmp2 = tmp1->next; 48 | while (tmp2) 49 | { 50 | if (cmp(tmp1->data, tmp2->data) > 0) 51 | { 52 | ft_swap2(&tmp1, &tmp2); 53 | i = 1; 54 | } 55 | tmp1 = tmp1->next; 56 | tmp2 = tmp2->next; 57 | } 58 | } 59 | } 60 | 61 | void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()) 62 | { 63 | ft_list_push_front3(begin_list, data); 64 | ft_list_sort2(begin_list, cmp); 65 | } 66 | -------------------------------------------------------------------------------- /c10/ex02/ft_putstr_error.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_error.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:54:22 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:02:38 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tail.h" 14 | 15 | void ft_puterror(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i]) 21 | { 22 | write(2, &str[i], 1); 23 | i++; 24 | } 25 | } 26 | 27 | void ft_putstr(char *str) 28 | { 29 | int i; 30 | 31 | i = 0; 32 | while (str[i]) 33 | { 34 | write(1, &str[i], 1); 35 | i++; 36 | } 37 | } 38 | 39 | int ft_error(int fd, char **argv, int i) 40 | { 41 | if (fd < 0) 42 | { 43 | ft_puterror(basename(argv[0])); 44 | ft_puterror(": "); 45 | ft_puterror(argv[i]); 46 | ft_puterror(": "); 47 | ft_puterror(strerror(errno)); 48 | ft_puterror("\n"); 49 | return (1); 50 | } 51 | return (0); 52 | } 53 | 54 | void ft_banner(char **argv, int argc, int i) 55 | { 56 | int size; 57 | 58 | size = ft_strlen(argv[1]); 59 | if ((size >= 3 && argc > 3) || argc > 4) 60 | { 61 | ft_putstr("==> "); 62 | ft_putstr(argv[i]); 63 | ft_putstr(" <=="); 64 | ft_putstr("\n"); 65 | } 66 | } 67 | 68 | void ft_illegal_offset(char **argv) 69 | { 70 | ft_puterror(basename(argv[0])); 71 | ft_puterror(": "); 72 | ft_puterror("illegal offset -- "); 73 | ft_puterror(argv[2]); 74 | ft_puterror("\n"); 75 | } 76 | -------------------------------------------------------------------------------- /c10/ex01/ft_cat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_cat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/25 13:57:57 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/25 13:58:00 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int ft_strlen(char *str) 18 | { 19 | char *s; 20 | 21 | s = str; 22 | while (*str) 23 | str++; 24 | return (str - s); 25 | } 26 | 27 | void ft_putstr(int chan, char *str) 28 | { 29 | write(chan, str, ft_strlen(str)); 30 | } 31 | 32 | void ft_display_file(char *file, char *program_name) 33 | { 34 | int fd; 35 | int n; 36 | char buffer[2]; 37 | 38 | fd = open(file, 0); 39 | if (fd == -1) 40 | { 41 | ft_putstr(2, program_name); 42 | ft_putstr(2, ": "); 43 | ft_putstr(2, file); 44 | ft_putstr(2, ": No such file or directory\n"); 45 | return ; 46 | } 47 | while ((n = read(fd, buffer, 2)) > 0) 48 | write(1, buffer, n); 49 | close(fd); 50 | } 51 | 52 | void ft_display_stdin(void) 53 | { 54 | int n; 55 | char buffer[2]; 56 | 57 | while ((n = read(0, buffer, 2)) > 0) 58 | write(1, buffer, n); 59 | } 60 | 61 | int main(int argc, char **argv) 62 | { 63 | int i; 64 | 65 | i = 1; 66 | if (argc > 1) 67 | { 68 | while (i < argc) 69 | { 70 | ft_display_file(argv[i++], basename(argv[0])); 71 | } 72 | } 73 | else 74 | ft_display_stdin(); 75 | return (0); 76 | } 77 | -------------------------------------------------------------------------------- /c07/ex03/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strjoin.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/09 23:45:30 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/16 12:15:45 by tmarx ### ########.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 | int ft_strlen2(char **strs, int size) 26 | { 27 | int i; 28 | int res; 29 | 30 | i = 0; 31 | res = 0; 32 | if (size == 0) 33 | return (0); 34 | while (i < size) 35 | { 36 | res += ft_strlen(strs[i++]); 37 | } 38 | return (res); 39 | } 40 | 41 | char *ft_strcat(char *dest, char *src) 42 | { 43 | int i; 44 | 45 | i = 0; 46 | while (dest[i]) 47 | i++; 48 | while (*src) 49 | dest[i++] = *src++; 50 | dest[i] = '\0'; 51 | return (dest); 52 | } 53 | 54 | char *ft_strjoin(int size, char **strs, char *sep) 55 | { 56 | char *res; 57 | int len; 58 | int i; 59 | 60 | if (size <= 0 || !sep || !strs) 61 | { 62 | res = malloc(sizeof(char)); 63 | res[0] = '\0'; 64 | return (res); 65 | } 66 | len = ft_strlen(sep) * (size - 1) + ft_strlen2(strs, size) + 1; 67 | res = malloc(sizeof(char) * len); 68 | if (!res) 69 | return (0); 70 | res[0] = 0; 71 | i = 0; 72 | while (i < size) 73 | { 74 | ft_strcat(res, strs[i++]); 75 | if (i < size) 76 | ft_strcat(res, sep); 77 | } 78 | res[len - 1] = '\0'; 79 | return (res); 80 | } 81 | -------------------------------------------------------------------------------- /c04/ex04/ft_putnbr_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/12 10:49:32 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/12 11:06:35 by tmarx ### ########.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 | int check_base(char *str) 26 | { 27 | int i; 28 | int j; 29 | 30 | if (ft_strlen(str) <= 1) 31 | return (0); 32 | i = 0; 33 | while (str[i]) 34 | { 35 | if (!(str[i] >= 'A' && str[i] <= 'Z') 36 | && !(str[i] >= 'a' && str[i] <= 'z') 37 | && !(str[i] >= '0' && str[i] <= '9')) 38 | return (0); 39 | j = i + 1; 40 | while (str[j]) 41 | { 42 | if (str[j] == str[i]) 43 | return (0); 44 | j++; 45 | } 46 | i++; 47 | } 48 | return (1); 49 | } 50 | 51 | void ft_putnbr_base(int nbr, char *base) 52 | { 53 | int b; 54 | 55 | if (!check_base(base)) 56 | return ; 57 | b = ft_strlen(base); 58 | if (nbr <= -2147483648) 59 | { 60 | write(1, "-", 1); 61 | ft_putnbr_base((-(long int)nbr) / b, base); 62 | ft_putnbr_base((-(long int)nbr) % b, base); 63 | } 64 | else if (nbr < 0) 65 | { 66 | write(1, "-", 1); 67 | ft_putnbr_base(-nbr, base); 68 | } 69 | else if (nbr < b) 70 | { 71 | write(1, &base[nbr], 1); 72 | } 73 | else 74 | { 75 | ft_putnbr_base(nbr / b, base); 76 | ft_putnbr_base(nbr % b, base); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /c12/ex17/ft_sorted_list_merge.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sorted_list_merge.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/21 19:06:14 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/21 19:19:59 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | 15 | void ft_swap4(t_list **el1, t_list **el2) 16 | { 17 | void *tmp; 18 | 19 | tmp = (*el1)->data; 20 | (*el1)->data = (*el2)->data; 21 | (*el2)->data = tmp; 22 | } 23 | 24 | void ft_list_sort4(t_list **begin_list, int (*cmp)()) 25 | { 26 | t_list *tmp1; 27 | t_list *tmp2; 28 | int i; 29 | 30 | i = 1; 31 | if (!(*begin_list) || !(*begin_list)->next) 32 | return ; 33 | while (i) 34 | { 35 | i = 0; 36 | tmp1 = *begin_list; 37 | tmp2 = tmp1->next; 38 | while (tmp2) 39 | { 40 | if (cmp(tmp1->data, tmp2->data) > 0) 41 | { 42 | ft_swap4(&tmp1, &tmp2); 43 | i = 1; 44 | } 45 | tmp1 = tmp1->next; 46 | tmp2 = tmp2->next; 47 | } 48 | } 49 | } 50 | 51 | void ft_list_merge2(t_list **begin_list1, t_list *begin_list2) 52 | { 53 | t_list *list; 54 | 55 | if (!(*begin_list1)) 56 | { 57 | *begin_list1 = begin_list2; 58 | return ; 59 | } 60 | list = *begin_list1; 61 | while (list->next) 62 | { 63 | list = list->next; 64 | } 65 | list->next = begin_list2; 66 | } 67 | 68 | void ft_sorted_list_merge(t_list **begin_list1, t_list *begin_list2, 69 | int (*cmp)()) 70 | { 71 | ft_list_merge2(begin_list1, begin_list2); 72 | ft_list_sort4(begin_list1, cmp); 73 | } 74 | -------------------------------------------------------------------------------- /c12/main2.c: -------------------------------------------------------------------------------- 1 | #include "ex00/ft_list.h" 2 | #include "ex04/ft_list_push_back.c" 3 | #include "ex05/ft_list_push_strs.c" 4 | #include "ex08/ft_list_reverse.c" 5 | #include "ex12/ft_list_remove_if.c" 6 | #include "ex13/ft_list_merge.c" 7 | #include "ex15/ft_list_reverse_fun.c" 8 | #include "ex16/ft_sorted_list_insert.c" 9 | #include "ex17/ft_sorted_list_merge.c" 10 | #include 11 | #include 12 | 13 | t_list *ft_create_elem(void *data) 14 | { 15 | t_list *res; 16 | 17 | res = 0; 18 | if ((res = malloc(sizeof(t_list)))) 19 | { 20 | res->data = data; 21 | res->next = 0; 22 | } 23 | return (res); 24 | } 25 | 26 | void ft_print_list(t_list *list) 27 | { 28 | while(list) 29 | { 30 | printf("%s", (char *)list->data); 31 | printf(" -> "); 32 | list = list->next; 33 | } 34 | printf("NULL\n"); 35 | } 36 | 37 | int ft_strcmp(char *s1, char *s2) 38 | { 39 | int i; 40 | 41 | i = 0; 42 | while (s1[i] && s2[i] && s1[i] == s2[i]) 43 | { 44 | i++; 45 | } 46 | return (s1[i] - s2[i]); 47 | } 48 | 49 | void free_ftc(void *data) 50 | { 51 | (void)data; 52 | } 53 | 54 | int main(void) 55 | { 56 | printf("Test exo04\n"); 57 | t_list *list1; 58 | list1 = 0; 59 | ft_list_push_back(&list1, "bip"); 60 | ft_list_push_back(&list1, "pouet"); 61 | ft_list_push_back(&list1, "salut"); 62 | ft_print_list(list1); 63 | 64 | printf("Test ex05\n"); 65 | char *a[] = {"test", "test2", "test3"}; 66 | t_list *list2 = ft_list_push_strs(3, a); 67 | ft_print_list(list2); 68 | 69 | printf("Test exo08\n"); 70 | ft_list_reverse(&list2); 71 | ft_print_list(list2); 72 | 73 | printf("Test ex12\n"); 74 | char *c[] = {"Test1", "Test2", "Test3"}; 75 | t_list *tab = ft_list_push_strs(3, c); 76 | ft_list_remove_if(&tab, "Test1", &ft_strcmp, &free_ftc); 77 | ft_print_list(tab); 78 | 79 | printf("Test ex13\n"); 80 | ft_list_merge(&list1, list2); 81 | ft_print_list(list1); 82 | 83 | printf("Test ex15\n"); 84 | ft_list_reverse_fun(list1); 85 | ft_print_list(list1); 86 | 87 | printf("Test ex16\n"); 88 | ft_sorted_list_insert(&list1, "btestttt", &ft_strcmp); 89 | ft_print_list(list1); 90 | 91 | printf("Test ex17\n"); 92 | char *b[] = {"a", "b", "ta", "ok"}; 93 | t_list *list3 = ft_list_push_strs(4, b); 94 | ft_sorted_list_merge(&list1, list3, &ft_strcmp); 95 | ft_print_list(list1); 96 | 97 | return (0); 98 | } -------------------------------------------------------------------------------- /c10/ex02/ft_writing_reading.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_writing_reading.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/19 07:55:14 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/19 08:01:09 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "tail.h" 14 | 15 | char *ft_write(char **argv, int argc, int option) 16 | { 17 | int i; 18 | int fd; 19 | char *str; 20 | int c_f[2]; 21 | 22 | c_f[1] = 0; 23 | str = malloc((option + 1) * sizeof(char)); 24 | i = ft_init(argv); 25 | while (i < argc) 26 | { 27 | c_f[0] = ft_count(argv, i) - option; 28 | fd = open(argv[i], O_RDONLY); 29 | if (!ft_error(fd, argv, i)) 30 | { 31 | c_f[1] = ft_flag(c_f[1], argv, argc, i); 32 | ft_display(c_f, str, fd); 33 | } 34 | i++; 35 | } 36 | return (str); 37 | } 38 | 39 | int ft_count(char **argv, int i) 40 | { 41 | char c; 42 | int count; 43 | int fd; 44 | 45 | count = 0; 46 | fd = open(argv[i], O_RDONLY); 47 | if (fd > 0) 48 | { 49 | while (read(fd, &c, 1) > 0) 50 | { 51 | count++; 52 | } 53 | close(fd); 54 | } 55 | i++; 56 | return (count); 57 | } 58 | 59 | int ft_init(char **argv) 60 | { 61 | if (ft_strlen(argv[1]) >= 3) 62 | return (2); 63 | else 64 | return (3); 65 | } 66 | 67 | int ft_flag(int flag, char **argv, int argc, int i) 68 | { 69 | if (flag == 1) 70 | ft_putstr("\n"); 71 | ft_banner(argv, argc, i); 72 | return (1); 73 | } 74 | 75 | void ft_display(int c_f[2], char *str, int fd) 76 | { 77 | int j; 78 | 79 | j = 0; 80 | while (j < c_f[0] && read(fd, &str, 1) > 0) 81 | j++; 82 | j = 0; 83 | while (read(fd, &str[j], 1) > 0) 84 | j++; 85 | close(fd); 86 | str[j] = 0; 87 | ft_putstr(str); 88 | } 89 | -------------------------------------------------------------------------------- /c04/ex05/ft_atoi_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/06 23:08:18 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/12 11:43:50 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i]) 19 | i++; 20 | return (i); 21 | } 22 | 23 | int get_value(char c, char *base) 24 | { 25 | int i; 26 | 27 | i = 0; 28 | while (base[i] && base[i] != c) 29 | i++; 30 | if (i >= ft_strlen(base)) 31 | return (-1); 32 | return (i); 33 | } 34 | 35 | int is_space(char c) 36 | { 37 | if ((c >= 9 && c <= 13) || c == 32) 38 | return (1); 39 | return (0); 40 | } 41 | 42 | int check_base(char *str) 43 | { 44 | int i; 45 | int j; 46 | 47 | if (ft_strlen(str) <= 1) 48 | return (0); 49 | i = 0; 50 | while (str[i]) 51 | { 52 | if (str[i] < 32 || str[i] > 127 || is_space(str[i]) || str[i] == '-' 53 | || str[i] == '+') 54 | return (0); 55 | j = i + 1; 56 | while (str[j]) 57 | { 58 | if (str[j] == str[i]) 59 | return (0); 60 | j++; 61 | } 62 | i++; 63 | } 64 | return (1); 65 | } 66 | 67 | int ft_atoi_base(char *str, char *base) 68 | { 69 | int i; 70 | int b; 71 | int sign; 72 | long res; 73 | 74 | i = 0; 75 | sign = 1; 76 | res = 0; 77 | if (!check_base(base)) 78 | return (0); 79 | b = ft_strlen(base); 80 | while (is_space(str[i])) 81 | i++; 82 | while (str[i] == '+' || str[i] == '-') 83 | { 84 | if (str[i] == '-') 85 | sign *= -1; 86 | i++; 87 | } 88 | while (get_value(str[i], base) >= 0) 89 | { 90 | res = res * b + get_value(str[i], base); 91 | i++; 92 | } 93 | return (res * sign); 94 | } 95 | -------------------------------------------------------------------------------- /c07/ex04/ft_convert_base2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_convert_base2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/14 04:19:48 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/14 07:28:16 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i]) 19 | i++; 20 | return (i); 21 | } 22 | 23 | int get_value(char c, char *base) 24 | { 25 | int i; 26 | 27 | i = 0; 28 | while (base[i] && base[i] != c) 29 | i++; 30 | if (i >= ft_strlen(base)) 31 | return (-1); 32 | return (i); 33 | } 34 | 35 | int is_space(char c) 36 | { 37 | if ((c >= 9 && c <= 13) || c == 32) 38 | return (1); 39 | return (0); 40 | } 41 | 42 | int check_base(char *str) 43 | { 44 | int i; 45 | int j; 46 | 47 | if (ft_strlen(str) <= 1) 48 | return (0); 49 | i = 0; 50 | while (str[i]) 51 | { 52 | if (str[i] < 32 || str[i] > 127 || is_space(str[i]) || str[i] == '-' 53 | || str[i] == '+') 54 | return (0); 55 | j = i + 1; 56 | while (str[j]) 57 | { 58 | if (str[j] == str[i]) 59 | return (0); 60 | j++; 61 | } 62 | i++; 63 | } 64 | return (1); 65 | } 66 | 67 | int ft_atoi_base(char *str, char *base) 68 | { 69 | int i; 70 | int b; 71 | int sign; 72 | long res; 73 | 74 | i = 0; 75 | sign = 1; 76 | res = 0; 77 | if (!check_base(base)) 78 | return (0); 79 | b = ft_strlen(base); 80 | while (is_space(str[i])) 81 | i++; 82 | while (str[i] == '+' || str[i] == '-') 83 | { 84 | if (str[i] == '-') 85 | sign *= -1; 86 | i++; 87 | } 88 | while (get_value(str[i], base) >= 0) 89 | { 90 | res = res * b + get_value(str[i], base); 91 | i++; 92 | } 93 | return (res * sign); 94 | } 95 | -------------------------------------------------------------------------------- /c12/main.c: -------------------------------------------------------------------------------- 1 | #include "ex00/ft_list.h" 2 | #include "ex00/ft_create_elem.c" 3 | #include "ex01/ft_list_push_front.c" 4 | #include "ex02/ft_list_size.c" 5 | #include "ex03/ft_list_last.c" 6 | #include "ex04/ft_list_push_back.c" 7 | #include "ex05/ft_list_push_strs.c" 8 | #include "ex06/ft_list_clear.c" 9 | #include "ex07/ft_list_at.c" 10 | #include "ex08/ft_list_reverse.c" 11 | #include "ex09/ft_list_foreach.c" 12 | #include "ex12/ft_list_remove_if.c" 13 | #include "ex13/ft_list_merge.c" 14 | #include "ex14/ft_list_sort.c" 15 | #include 16 | 17 | void ft_print_list(t_list *list) 18 | { 19 | while(list) 20 | { 21 | printf("%s", (char *)list->data); 22 | printf(" -> "); 23 | list = list->next; 24 | } 25 | printf("NULL\n"); 26 | } 27 | 28 | void handle_data(void *data) 29 | { 30 | printf("%s\n", (char*)data); 31 | } 32 | 33 | int remove_p(char *d1, char *d2) 34 | { 35 | (void)d2; 36 | return (!(d1[0] == 'p')); 37 | } 38 | 39 | void free_list(void *el) 40 | { 41 | (void)el; 42 | } 43 | 44 | int cmp(char *str1, char *str2) 45 | { 46 | int i; 47 | 48 | i = 0; 49 | while (str1[i] && str2[i] && str1[i] == str2[i]) 50 | i++; 51 | return (str1[i] - str2[i]); 52 | } 53 | 54 | int main() 55 | { 56 | t_list *list; 57 | t_list *list2; 58 | t_list *list3; 59 | 60 | printf("* test creation tableau:\n"); 61 | list = ft_create_elem("premier"); 62 | ft_list_push_front(&list, "avant"); 63 | ft_list_push_back(&list, "deuxieme"); 64 | ft_print_list(list); 65 | printf("* size: %d\n", ft_list_size(list)); 66 | printf("* last: %s\n", ft_list_last(list)->data); 67 | 68 | printf("* test ft_list_push_strs:\n"); 69 | char *a[] = {"test", "test1", "pa", "test2", "pouet"}; 70 | list2 = ft_list_push_strs(5, a); 71 | ft_print_list(list2); 72 | printf("* element 1: %s\n", ft_list_at(list2, 1)->data); 73 | ft_list_reverse(&list2); 74 | printf("* after reverse:\n"); 75 | ft_print_list(list2); 76 | printf("* test foreach:\n"); 77 | ft_list_foreach(list2, &handle_data); 78 | ft_list_remove_if(&list2, "test", &remove_p, &free_list); 79 | printf("* test remove_if:\n"); 80 | ft_print_list(list2); 81 | printf("* test tri (strcmp):\n"); 82 | ft_list_sort(&list2, &cmp); 83 | ft_print_list(list2); 84 | printf("* test merge:\n"); 85 | list = ft_list_push_strs(5, a); 86 | list3 = ft_create_elem("liste3"); 87 | ft_list_merge(&list3, list); 88 | //ft_list_merge(&list3, list2); 89 | ft_print_list(list3); 90 | } 91 | -------------------------------------------------------------------------------- /bsq/src/grid_parsing.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* grid_parsing.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/24 08:18:38 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/24 17:38:56 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "header.h" 14 | 15 | int fill_row(char buffer[X_BUFFER], t_map *map, int y) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | if (y > map->y - 1) 21 | return (0); 22 | while (buffer[i] && (buffer[i] == map->empty || buffer[i] == map->obst) 23 | && i < map->x) 24 | { 25 | if (buffer[i] == map->empty) 26 | map->grid[i][y] = 0; 27 | else if (buffer[i] == map->obst) 28 | map->grid[i][y] = 1; 29 | else 30 | return (0); 31 | i++; 32 | } 33 | if (i != map->x) 34 | return (0); 35 | return (1); 36 | } 37 | 38 | int parse_first_grid_line(int fd, t_map *map) 39 | { 40 | int i; 41 | char buffer[X_BUFFER]; 42 | char buffer_1[1]; 43 | 44 | (void)map; 45 | i = 0; 46 | while (read(fd, buffer_1, 1) > 0 && buffer_1[0] && buffer_1[0] != '\n') 47 | { 48 | buffer[i++] = buffer_1[0]; 49 | } 50 | buffer[i] = '\0'; 51 | map->x = i; 52 | create_grid(map->x, map->y, &(map->grid), 0); 53 | create_grid(map->x, map->y, &(map->grid_copy), 1); 54 | return (fill_row(buffer, map, 0)); 55 | } 56 | 57 | int parse_body_grid(int fd, t_map *map) 58 | { 59 | int i; 60 | char buffer[map->x + 2]; 61 | 62 | i = 1; 63 | while (read(fd, buffer, map->x + 1)) 64 | { 65 | if (!fill_row(buffer, map, i++)) 66 | return (0); 67 | } 68 | if (i != map->y) 69 | return (0); 70 | return (1); 71 | } 72 | 73 | int parse_grid(int fd, t_map *map) 74 | { 75 | if (!parse_first_grid_line(fd, map)) 76 | return (0); 77 | if (!parse_body_grid(fd, map)) 78 | return (0); 79 | return (1); 80 | } 81 | -------------------------------------------------------------------------------- /c07/ex05/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 22:33:50 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/13 23:52:43 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int is_pattern(char c, char *pattern) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (pattern[i]) 21 | { 22 | if (pattern[i] == c) 23 | return (1); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | 29 | int is_pattern_at(char *src, char *pattern, int i) 30 | { 31 | if (src[i - 1] && src[i + 1] && 32 | !is_pattern(src[i + 1], pattern) && is_pattern(src[i], pattern)) 33 | return (1); 34 | return (0); 35 | } 36 | 37 | int count_splits(char *src, char *pattern) 38 | { 39 | int i; 40 | int res; 41 | 42 | i = 0; 43 | res = 0; 44 | while (is_pattern(src[i], pattern)) 45 | i++; 46 | if (!src[i]) 47 | return (0); 48 | while (src[i]) 49 | { 50 | if (is_pattern_at(src, pattern, i++)) 51 | res++; 52 | } 53 | return (res + 1); 54 | } 55 | 56 | int len(char *str, char *charset, int j) 57 | { 58 | int x; 59 | 60 | x = 0; 61 | while (!is_pattern_at(str, charset, j + x) && str[j + x]) 62 | x++; 63 | return (x); 64 | } 65 | 66 | char **ft_split(char *str, char *charset) 67 | { 68 | int i; 69 | int j; 70 | int k; 71 | char **res; 72 | 73 | res = malloc(sizeof(char*) * (count_splits(str, charset) + 1)); 74 | i = 0; 75 | j = 0; 76 | while (i < count_splits(str, charset)) 77 | { 78 | k = 0; 79 | while (is_pattern(str[j], charset)) 80 | j++; 81 | res[i] = malloc(sizeof(char) * (len(str, charset, j) + 1)); 82 | while (!is_pattern_at(str, charset, j) && str[j]) 83 | { 84 | if (!is_pattern(str[j], charset)) 85 | res[i][k++] = str[j]; 86 | j++; 87 | } 88 | j += 1; 89 | res[i++][k] = '\0'; 90 | } 91 | res[i] = 0; 92 | return (res); 93 | } 94 | -------------------------------------------------------------------------------- /c09/ex02/ft_split.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_split.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/11 22:33:50 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/13 23:52:43 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int is_pattern(char c, char *pattern) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (pattern[i]) 21 | { 22 | if (pattern[i] == c) 23 | return (1); 24 | i++; 25 | } 26 | return (0); 27 | } 28 | 29 | int is_pattern_at(char *src, char *pattern, int i) 30 | { 31 | if (src[i - 1] && src[i + 1] && 32 | !is_pattern(src[i + 1], pattern) && is_pattern(src[i], pattern)) 33 | return (1); 34 | return (0); 35 | } 36 | 37 | int count_splits(char *src, char *pattern) 38 | { 39 | int i; 40 | int res; 41 | 42 | i = 0; 43 | res = 0; 44 | while (is_pattern(src[i], pattern)) 45 | i++; 46 | if (!src[i]) 47 | return (0); 48 | while (src[i]) 49 | { 50 | if (is_pattern_at(src, pattern, i++)) 51 | res++; 52 | } 53 | return (res + 1); 54 | } 55 | 56 | int len(char *str, char *charset, int j) 57 | { 58 | int x; 59 | 60 | x = 0; 61 | while (!is_pattern_at(str, charset, j + x) && str[j + x]) 62 | x++; 63 | return (x); 64 | } 65 | 66 | char **ft_split(char *str, char *charset) 67 | { 68 | int i; 69 | int j; 70 | int k; 71 | char **res; 72 | 73 | res = malloc(sizeof(char*) * (count_splits(str, charset) + 1)); 74 | i = 0; 75 | j = 0; 76 | while (i < count_splits(str, charset)) 77 | { 78 | k = 0; 79 | while (is_pattern(str[j], charset)) 80 | j++; 81 | res[i] = malloc(sizeof(char) * (len(str, charset, j) + 1)); 82 | while (!is_pattern_at(str, charset, j) && str[j]) 83 | { 84 | if (!is_pattern(str[j], charset)) 85 | res[i][k++] = str[j]; 86 | j++; 87 | } 88 | j += 1; 89 | res[i++][k] = '\0'; 90 | } 91 | res[i] = 0; 92 | return (res); 93 | } 94 | -------------------------------------------------------------------------------- /c07/ex04/ft_convert_base.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_convert_base.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tmarx +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2019/07/14 07:27:51 by tmarx #+# #+# */ 9 | /* Updated: 2019/07/16 00:55:12 by tmarx ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int ft_strlen(char *str); 16 | int get_value(char c, char *base); 17 | int is_space(char c); 18 | int check_base(char *str); 19 | int ft_atoi_base(char *str, char *base); 20 | 21 | void ft_putnbr_base(char *res, int nbr, char *base, int *last_n) 22 | { 23 | int b; 24 | 25 | b = ft_strlen(base); 26 | if (nbr <= -2147483648) 27 | { 28 | res[0] = '-'; 29 | (*last_n)++; 30 | ft_putnbr_base(res, (-(long int)nbr) / b, base, last_n); 31 | ft_putnbr_base(res, (-(long int)nbr) % b, base, last_n); 32 | } 33 | else if (nbr < 0) 34 | { 35 | res[0] = '-'; 36 | (*last_n)++; 37 | ft_putnbr_base(res, -nbr, base, last_n); 38 | } 39 | else if (nbr < b) 40 | { 41 | res[(*last_n)++] = base[nbr]; 42 | } 43 | else 44 | { 45 | ft_putnbr_base(res, nbr / b, base, last_n); 46 | ft_putnbr_base(res, nbr % b, base, last_n); 47 | } 48 | } 49 | 50 | int count_digits(int nb, char *base) 51 | { 52 | int i; 53 | 54 | i = 0; 55 | if (nb == 0) 56 | return (1); 57 | if (nb < 0) 58 | { 59 | i++; 60 | nb = -nb; 61 | } 62 | while (nb != 0) 63 | { 64 | nb = nb - (nb % ft_strlen(base)); 65 | nb = nb / ft_strlen(base); 66 | i++; 67 | } 68 | return (i); 69 | } 70 | 71 | char *ft_convert_base(char *nbr, char *base_from, char *base_to) 72 | { 73 | int n; 74 | char *res; 75 | int last_n; 76 | 77 | if (!check_base(base_from) || !check_base(base_to)) 78 | return (0); 79 | n = ft_atoi_base(nbr, base_from); 80 | res = malloc(sizeof(char) * (count_digits(n, base_to) + 1)); 81 | last_n = 0; 82 | ft_putnbr_base(res, n, base_to, &last_n); 83 | res[count_digits(n, base_to)] = '\0'; 84 | return (res); 85 | } 86 | --------------------------------------------------------------------------------