├── code ├── BSQ │ ├── map5 │ ├── map2 │ ├── map3 │ ├── map1 │ ├── generator │ ├── map4 │ ├── Makefile │ ├── srcs │ │ ├── ft_helper_1.c │ │ ├── ft_string_2.c │ │ ├── ft_integer.c │ │ ├── ft_helper_2.c │ │ └── ft_string_1.c │ └── main.c ├── S00 │ ├── ex00 │ │ └── z │ ├── ex04 │ │ └── midLS │ ├── ex09 │ │ └── ft_magic │ ├── ex05 │ │ └── git_commit.sh │ ├── ex06 │ │ └── git_ignore.sh │ ├── ex08 │ │ └── clean │ ├── README.md │ ├── ex07 │ │ └── b │ └── ex03 │ │ └── id_rsa_pub ├── S01 │ ├── ex05 │ │ └── _ │ │ │ └── _$_'MaRViN'_$_ │ │ │ └── _ │ ├── ex03 │ │ └── count_files.sh │ ├── ex06 │ │ └── skip.sh │ ├── ex04 │ │ └── MAC.sh │ ├── ex01 │ │ └── print_groups.sh │ ├── ex02 │ │ └── find_sh.sh │ ├── ex07 │ │ └── r_dsswap.sh │ ├── ex08 │ │ └── add_chelou.sh │ └── README.md ├── C09 │ ├── ex00 │ │ ├── libft_creator.sh │ │ ├── ft_putchar.c │ │ ├── ft_swap.c │ │ ├── ft_strlen.c │ │ ├── ft_putstr.c │ │ └── ft_strcmp.c │ ├── README.md │ └── ex01 │ │ └── Makefile ├── C06 │ ├── README.md │ ├── ex00 │ │ └── ft_print_program_name.c │ ├── ex01 │ │ └── ft_print_params.c │ ├── ex02 │ │ └── ft_rev_params.c │ └── ex03 │ │ └── ft_sort_params.c ├── C08 │ ├── README.md │ ├── ex02 │ │ └── ft_abs.h │ ├── ex03 │ │ └── ft_point.h │ ├── ex00 │ │ └── ft.h │ └── ex01 │ │ └── ft_boolean.h ├── C03 │ ├── README.md │ ├── ex02 │ │ └── ft_strcat.c │ ├── ex03 │ │ └── ft_strncat.c │ ├── ex05 │ │ └── ft_strlcat.c │ ├── ex00 │ │ └── ft_strcmp.c │ └── ex01 │ │ └── ft_strncmp.c ├── C04 │ ├── README.md │ ├── ex01 │ │ └── ft_putstr.c │ ├── ex00 │ │ └── ft_strlen.c │ ├── ex02 │ │ └── ft_putnbr.c │ └── ex03 │ │ └── ft_atoi.c ├── C07 │ ├── README.md │ ├── ex00 │ │ └── ft_strdup.c │ └── ex01 │ │ └── ft_range.c ├── C10 │ ├── ex00 │ │ └── Makefile │ ├── main.c │ └── ft_utils.c ├── C11 │ ├── README.md │ ├── ex05 │ │ ├── Makefile │ │ ├── srcs │ │ │ ├── ft_ops.c │ │ │ ├── do_op.c │ │ │ ├── ft_util.c │ │ │ └── ft_atoi.c │ │ ├── includes │ │ │ └── do_op.h │ │ └── main.c │ ├── ex04 │ │ └── ft_is_sort.c │ ├── ex00 │ │ └── ft_foreach.c │ ├── ex02 │ │ └── ft_any.c │ ├── ex03 │ │ └── ft_count_if.c │ ├── ex01 │ │ └── ft_map.c │ ├── ex06 │ │ └── ft_sort_string_tab.c │ └── ex07 │ │ └── ft_advanced_sort_string_tab.c ├── C01 │ ├── README.md │ ├── ex00 │ │ └── ft_ft.c │ ├── ex06 │ │ └── ft_strlen.c │ ├── ex02 │ │ └── ft_swap.c │ ├── ex05 │ │ └── ft_putstr.c │ ├── ex03 │ │ └── ft_div_mod.c │ ├── ex04 │ │ └── ft_ultimate_div_mod.c │ ├── ex07 │ │ └── ft_rev_int_tab.c │ ├── ex01 │ │ └── ft_ultimate_ft.c │ └── ex08 │ │ └── ft_sort_int_tab.c ├── C00 │ ├── README.md │ ├── ex00 │ │ └── ft_putchar.c │ ├── ex04 │ │ └── ft_is_negative.c │ ├── ex03 │ │ └── ft_print_numbers.c │ ├── ex01 │ │ └── ft_print_alphabet.c │ ├── ex02 │ │ └── ft_print_reverse_alphabet.c │ ├── ex07 │ │ └── ft_putnbr.c │ ├── ex05 │ │ └── ft_print_comb.c │ ├── ex08 │ │ └── ft_print_combn.c │ └── ex06 │ │ └── ft_print_comb2.c ├── C05 │ ├── README.md │ ├── ex00 │ │ └── ft_iterative_factorial.c │ ├── ex01 │ │ └── ft_recursive_factorial.c │ ├── ex06 │ │ └── ft_is_prime.c │ ├── ex04 │ │ └── ft_fibonacci.c │ ├── ex07 │ │ └── ft_find_next_prime.c │ ├── ex03 │ │ └── ft_recursive_power.c │ ├── ex02 │ │ └── ft_iterative_power.c │ ├── ex05 │ │ └── ft_sqrt.c │ └── ex08 │ │ └── ft_ten_queens_puzzle.c ├── C02 │ ├── README.md │ ├── ex07 │ │ └── ft_strupcase.c │ ├── ex08 │ │ └── ft_strlowcase.c │ ├── ex03 │ │ └── ft_str_is_numeric.c │ ├── ex04 │ │ └── ft_str_is_lowercase.c │ ├── ex05 │ │ └── ft_str_is_uppercase.c │ ├── ex06 │ │ └── ft_str_is_printable.c │ ├── ex02 │ │ └── ft_str_is_alpha.c │ ├── ex00 │ │ └── ft_strcpy.c │ ├── ex10 │ │ └── ft_strlcpy.c │ ├── ex11 │ │ └── ft_putstr_non_printable.c │ ├── ex01 │ │ └── ft_strncpy.c │ └── ex09 │ │ └── ft_strcapitalize.c ├── R02 │ └── ex00 │ │ ├── dict_esp.dict │ │ ├── dict_eng.dict │ │ ├── rush.h │ │ └── state.c ├── C12 │ ├── README.md │ ├── 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 │ ├── ex09 │ │ └── ft_list.h │ ├── ex10 │ │ └── ft_list.h │ ├── ex11 │ │ └── ft_list.h │ ├── ex12 │ │ └── ft_list.h │ ├── ex13 │ │ └── ft_list.h │ ├── ex14 │ │ └── ft_list.h │ ├── ex15 │ │ └── ft_list.h │ ├── ex16 │ │ └── ft_list.h │ └── ex17 │ │ └── ft_list.h ├── R00 │ └── ex00 │ │ ├── ft_putchar.c │ │ ├── main.c │ │ ├── rush03.c │ │ ├── rush00.c │ │ └── rush02.c └── R01 │ └── ex00 │ ├── ft_putchar.c │ ├── in_row_column.c │ ├── main.c │ ├── print.c │ └── conditions.c └── .gitignore /code/BSQ/map5: -------------------------------------------------------------------------------- 1 | 0.ox 2 | -------------------------------------------------------------------------------- /code/S00/ex00/z: -------------------------------------------------------------------------------- 1 | Z 2 | -------------------------------------------------------------------------------- /code/BSQ/map2: -------------------------------------------------------------------------------- 1 | 1.ox 2 | o 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */.vscode 2 | .vscode -------------------------------------------------------------------------------- /code/S00/ex04/midLS: -------------------------------------------------------------------------------- 1 | ls -mpt 2 | -------------------------------------------------------------------------------- /code/S01/ex05/_/_$_'MaRViN'_$_/_: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /code/BSQ/map3: -------------------------------------------------------------------------------- 1 | 3.ox 2 | ... 3 | ... 4 | ..o 5 | -------------------------------------------------------------------------------- /code/S00/ex09/ft_magic: -------------------------------------------------------------------------------- 1 | 41 string 42 42 file 2 | -------------------------------------------------------------------------------- /code/S01/ex03/count_files.sh: -------------------------------------------------------------------------------- 1 | find . | wc -l 2 | -------------------------------------------------------------------------------- /code/S01/ex06/skip.sh: -------------------------------------------------------------------------------- 1 | ls -l | awk 'NR%2==1' 2 | -------------------------------------------------------------------------------- /code/S00/ex05/git_commit.sh: -------------------------------------------------------------------------------- 1 | git log --format=%H -5 2 | -------------------------------------------------------------------------------- /code/S00/ex06/git_ignore.sh: -------------------------------------------------------------------------------- 1 | git status -s | grep '!!' | cut -c 4- -------------------------------------------------------------------------------- /code/S01/ex04/MAC.sh: -------------------------------------------------------------------------------- 1 | ifconfig | grep ether | awk '{print $2}' 2 | -------------------------------------------------------------------------------- /code/S01/ex01/print_groups.sh: -------------------------------------------------------------------------------- 1 | id -Gn $FT_USER | tr ' ' ','| tr -d '\n' 2 | -------------------------------------------------------------------------------- /code/S00/ex08/clean: -------------------------------------------------------------------------------- 1 | find . -type f \( -name "#*#" -o -name "*~" \) -print -delete -------------------------------------------------------------------------------- /code/S01/ex02/find_sh.sh: -------------------------------------------------------------------------------- 1 | find . -type f -name "*.sh" -printf "%f\n" | sed "s/\.sh//" 2 | -------------------------------------------------------------------------------- /code/S01/ex07/r_dsswap.sh: -------------------------------------------------------------------------------- 1 | cat /etc/passwd | grep -v \# | awk 'NR%2==0' | cut -d ':' -f 1 | rev | sort -r | sed -n "$FT_LINE1,$FT_LINE2 p" | sed -z 's/\n/, /g' | sed 's/, $/./' 2 | -------------------------------------------------------------------------------- /code/BSQ/map1: -------------------------------------------------------------------------------- 1 | 10.ox 2 | ....o....o 3 | .......... 4 | ......o... 5 | .oo.o..... 6 | ....o..... 7 | ....o..o.o 8 | .......... 9 | ....o..... 10 | .......... 11 | ...o...... 12 | -------------------------------------------------------------------------------- /code/C09/ex00/libft_creator.sh: -------------------------------------------------------------------------------- 1 | gcc -Wall -Werror -Wextra -c ft_putchar.c ft_putstr.c ft_strcmp.c ft_strlen.c ft_swap.c 2 | ar -rc libft.a ft_putchar.o ft_putstr.o ft_strcmp.o ft_strlen.o ft_swap.o -------------------------------------------------------------------------------- /code/S01/ex08/add_chelou.sh: -------------------------------------------------------------------------------- 1 | FT1=$(echo $FT_NBR1 | tr \'\\\\\"\?\! 01234) 2 | FT2=$(echo $FT_NBR2 | tr mrdoc 01234) 3 | SUM=$(echo "obase=13; ibase=5; $FT1 + $FT2" | bc) 4 | echo $SUM | tr 0123456789ABC "gtaio luSnemf" 5 | -------------------------------------------------------------------------------- /code/C09/README.md: -------------------------------------------------------------------------------- 1 | ## C09 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | libft_creator.sh | ✅ 7 | [Exercise 01:](ex01/) | Makefile | ✅ 8 | [Exercise 02:](ex02/) | ft_split.c | ✅ 9 | -------------------------------------------------------------------------------- /code/C06/README.md: -------------------------------------------------------------------------------- 1 | ## C06 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_print_program_name.c | ✅ 7 | [Exercise 01:](ex01/) | ft_print_params.c | ✅ 8 | [Exercise 02:](ex02/) | ft_rev_params.c | ✅ 9 | [Exercise 03:](ex03/) | ft_sort_params.c | ✅ -------------------------------------------------------------------------------- /code/BSQ/generator: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | use warnings; 3 | use strict; 4 | die "program x y density" unless (scalar(@ARGV) == 3); 5 | my ($x, $y, $density) = @ARGV; 6 | print "$y.ox\n"; 7 | for (my $i = 0; $i < $y; $i++) { 8 | for (my $j = 0; $j < $x; $j++) { 9 | if (int(rand($y) * 2) < $density) { 10 | print "o"; 11 | } 12 | else { 13 | print "."; 14 | } 15 | } 16 | print "\n"; 17 | } -------------------------------------------------------------------------------- /code/C08/README.md: -------------------------------------------------------------------------------- 1 | ## C08 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft.h | ✅ 7 | [Exercise 01:](ex01/) | ft_range.h | ✅ 8 | [Exercise 02:](ex02/) | ft_abs.h | ✅ 9 | [Exercise 03:](ex03/) | ft_point.h | ✅ 10 | [Exercise 04:](ex04/) | ft_strs_to_tab.c | ✅ 11 | [Exercise 05:](ex05/) | ft_show_tab.c | ✅ -------------------------------------------------------------------------------- /code/C03/README.md: -------------------------------------------------------------------------------- 1 | ## C03 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_strcmp.c | ✅ 7 | [Exercise 01:](ex01/) | ft_strncmp.c | ✅ 8 | [Exercise 02:](ex02/) | ft_strcat.c | ✅ 9 | [Exercise 03:](ex03/) | ft_strncat.c | ✅ 10 | [Exercise 04:](ex04/) | ft_strstr.c | ✅ 11 | [Exercise 05:](ex05/) | ft_strlcat.c | ✅ -------------------------------------------------------------------------------- /code/C04/README.md: -------------------------------------------------------------------------------- 1 | ## C04 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_strlen.c | ✅ 7 | [Exercise 01:](ex01/) | ft_putstr.c | ✅ 8 | [Exercise 02:](ex02/) | ft_putnbr.c | ✅ 9 | [Exercise 03:](ex03/) | ft_atoi.c | ✅ 10 | [Exercise 04:](ex04/) | ft_putnbr_base.c | ✅ 11 | [Exercise 05:](ex05/) | ft_atoi_base.c | ✅ -------------------------------------------------------------------------------- /code/C07/README.md: -------------------------------------------------------------------------------- 1 | ## C07 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_strdup.c | ✅ 7 | [Exercise 01:](ex01/) | ft_range.c | ✅ 8 | [Exercise 02:](ex02/) | ft_ultimate_range.c | ✅ 9 | [Exercise 03:](ex03/) | ft_strjoin.c | ❌ 10 | [Exercise 04:](ex04/) | ft_convert_base.c, ft_convert_base2.c | ❌ 11 | [Exercise 05:](ex05/) | ft_split.c | ✅ -------------------------------------------------------------------------------- /code/C10/ex00/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | FLAGS = -Wall -Wextra -Werror 3 | DEPS = includes 4 | OBJDIR = srcs 5 | 6 | TARGET = ft_atoi.o ft_ops.o ft_util.o do_op.o 7 | OBJS = ${addprefix $(OBJDIR)/, $(TARGET)} 8 | NAME = do-op 9 | 10 | %.o : %.c 11 | $(CC) $(FLAGS) -c $< -o $@ -I $(DEPS) 12 | 13 | all: $(NAME) 14 | 15 | clean: 16 | rm -f $(OBJS) 17 | 18 | fclean: clean 19 | rm -f $(NAME) 20 | 21 | re: fclean all 22 | 23 | $(NAME): $(OBJS) 24 | $(CC) $(FLAGS) main.c -o $(NAME) $(OBJS) -I $(DEPS) 25 | -------------------------------------------------------------------------------- /code/C11/README.md: -------------------------------------------------------------------------------- 1 | ## C11 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_foreach.c | ❔ 7 | [Exercise 01:](ex01/) | ft_map.c | ❔ 8 | [Exercise 02:](ex02/) | ft_any.c | ❔ 9 | [Exercise 03:](ex03/) | ft_count_if.c | ❔ 10 | [Exercise 04:](ex04/) | ft_is_sort.c | ❔ 11 | [Exercise 05:](ex05/) | do_op.c | ❔ 12 | [Exercise 06:](ex06/) | ft_sort_string_tab.c | ❔ 13 | [Exercise 07:](ex07/) | ft_advanced_sort_string_tab.c | ❔ -------------------------------------------------------------------------------- /code/C11/ex05/Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | FLAGS = -Wall -Wextra -Werror 3 | DEPS = includes 4 | OBJDIR = srcs 5 | 6 | TARGET = ft_atoi.o ft_ops.o ft_util.o do_op.o 7 | OBJS = ${addprefix $(OBJDIR)/, $(TARGET)} 8 | NAME = do-op 9 | 10 | %.o : %.c 11 | $(CC) $(FLAGS) -c $< -o $@ -I $(DEPS) 12 | 13 | all: $(NAME) 14 | 15 | clean: 16 | rm -f $(OBJS) 17 | 18 | fclean: clean 19 | rm -f $(NAME) 20 | 21 | re: fclean all 22 | 23 | $(NAME): $(OBJS) 24 | $(CC) $(FLAGS) main.c -o $(NAME) $(OBJS) -I $(DEPS) 25 | -------------------------------------------------------------------------------- /code/S01/README.md: -------------------------------------------------------------------------------- 1 | ## S00 2 | --------------------- 3 | 4 | Links | Exercise | Correct? 5 | ---------------------------|---------------------------|--------- 6 | [Exercise 01:](ex01/) | print_groups.sh | ✅ 7 | [Exercise 02:](ex02/) | find_sh.sh | ✅ 8 | [Exercise 03:](ex03/) | count_files.sh | ✅ 9 | [Exercise 04:](ex04/) | MAC.sh | ✅ 10 | [Exercise 05:](ex05/) | "\?$*’MaRViN’*$?\" | ✅ 11 | [Exercise 06:](ex06/) | skip.sh | ✅ 12 | [Exercise 07:](ex07/) | r_dsswap.sh | ❌ 13 | [Exercise 08:](ex08/) | add_chelou.sh | ✅ 14 | -------------------------------------------------------------------------------- /code/S00/README.md: -------------------------------------------------------------------------------- 1 | ## S00 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | z | ✅ 7 | [Exercise 01:](ex01/) | testShell00.tar | ✅ 8 | [Exercise 02:](ex02/) | exo2.tar | ✅ 9 | [Exercise 03:](ex03/) | id_rsa_pub | ✅ 10 | [Exercise 04:](ex04/) | midLS | ✅ 11 | [Exercise 05:](ex05/) | git_commit.sh | ✅ 12 | [Exercise 06:](ex06/) | git_ignore.sh | ✅ 13 | [Exercise 07:](ex07/) | b | ✅ 14 | [Exercise 08:](ex08/) | clean | ❔ 15 | [Exercise 09:](ex09/) | ft_magic | ✅ -------------------------------------------------------------------------------- /code/C01/README.md: -------------------------------------------------------------------------------- 1 | ## C01 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_ft.c | ✅ 7 | [Exercise 01:](ex01/) | ft_ultimate_ft.c | ✅ 8 | [Exercise 02:](ex02/) | ft_swap.c | ✅ 9 | [Exercise 03:](ex03/) | ft_div_mod.c | ✅ 10 | [Exercise 04:](ex04/) | ft_ultimate_div_mod.c | ✅ 11 | [Exercise 05:](ex05/) | ft_putstr.c | ✅ 12 | [Exercise 06:](ex06/) | ft_strlen.c | ✅ 13 | [Exercise 07:](ex07/) | ft_rev_int_tab.c | ✅ 14 | [Exercise 08:](ex08/) | ft_sort_int_tab.c | ✅ -------------------------------------------------------------------------------- /code/C00/README.md: -------------------------------------------------------------------------------- 1 | ## C00 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_putchar.c | ✅ 7 | [Exercise 01:](ex01/) | ft_print_alphabet.c | ✅ 8 | [Exercise 02:](ex02/) | ft_print_reverse_alphabet.c | ✅ 9 | [Exercise 03:](ex03/) | ft_print_numbers.c | ✅ 10 | [Exercise 04:](ex04/) | ft_is_negative.c | ✅ 11 | [Exercise 05:](ex05/) | ft_print_comb.c | ✅ 12 | [Exercise 06:](ex06/) | ft_print_comb2.c | ✅ 13 | [Exercise 07:](ex07/) | ft_putnbr.c | ✅ 14 | [Exercise 08:](ex08/) | ft_print_combn.c | ✅ -------------------------------------------------------------------------------- /code/S00/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 | -------------------------------------------------------------------------------- /code/C05/README.md: -------------------------------------------------------------------------------- 1 | ## C05 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_iterative_factorial.c | ✅ 7 | [Exercise 01:](ex01/) | ft_recursive_factorial.c | ✅ 8 | [Exercise 02:](ex02/) | ft_iterative_power.c | ✅ 9 | [Exercise 03:](ex03/) | ft_recursive_power.c | ✅ 10 | [Exercise 04:](ex04/) | ft_fibonacci.c | ✅ 11 | [Exercise 05:](ex05/) | ft_sqrt.c | ✅ 12 | [Exercise 06:](ex06/) | ft_is_prime.c | ✅ 13 | [Exercise 07:](ex07/) | ft_find_next_prime.c | ✅ 14 | [Exercise 08:](ex08/) | ft_ten_queens_puzzle.c | ✅ -------------------------------------------------------------------------------- /code/S00/ex03/id_rsa_pub: -------------------------------------------------------------------------------- 1 | ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC6J0PLKJ7HpZCy9PreDz55AiCQ2iAQOzdSRBNMNoED+k3IIVZrV9WzTj0okSAPARt8hfK4jHN/llWCUj5TV98rtdPCO1uSGAITM12DXfB5NZUd1F+NOY04R/EsA03jPPYkKBpuyFxRZ6X3GaLwQC4oBDr7OmsFZVWKLot3QP9V3qMXW4WKA5y2Ewa/mvGSYu04+5Lhta1F1dfo63EFuKVRmTa9aTpXKNSn9pZiImOORSUskfLP2ZLF4dpg6M5qDgj7EJ2c4J6d1SrpIn0+CpLEjR4yN7OvXIUC1p0pbMwxDD9PfSbOPrDUHxP+Qj7S4dz9yWwl9GYF+j746hPYd4P5HbqNh5oF+Xuk4XqreNs518HxcMeQXdjL3OXS57s1qjcWOCm1o26jkLjy7BOPNdsYZvirPfvbyjR1uCNhooIYzOQu0GisqcMYO3K4fJ5FAG5bst8sAdtL1nz7WBcmeDFidFd/zacUC4/FqCPLdTR/QSvtkh7k9NeDT5mDosCJ8ptzxzis6DWslgS/WVcTxXLioLulWY8eupA1dOFVY7g2Nee9tm/sYpiS93d8rURURngRFS1DA6BcJ+odp5VHTJkHtslHP78rIHd517UsYANd37yYoiy/RSUp4aziM9u7+ilhCFjeSZyAInPk3143hTVhtdBRXe2PkMjrg/PrmV9NSw== ncarvalh@student.42porto.com 2 | -------------------------------------------------------------------------------- /code/C02/README.md: -------------------------------------------------------------------------------- 1 | ## C02 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_strcpy.c | ✅ 7 | [Exercise 01:](ex01/) | ft_strncpy.c | ✅ 8 | [Exercise 02:](ex02/) | ft_str_is_alpha.c | ✅ 9 | [Exercise 03:](ex03/) | ft_str_is_numeric.c | ✅ 10 | [Exercise 04:](ex04/) | ft_str_is_lowercase.c | ✅ 11 | [Exercise 05:](ex05/) | ft_str_is_uppercase.c | ✅ 12 | [Exercise 06:](ex06/) | ft_str_is_printable.c | ✅ 13 | [Exercise 07:](ex07/) | ft_strupcase.c | ✅ 14 | [Exercise 08:](ex08/) | ft_strlowcase.c | ✅ 15 | [Exercise 09:](ex09/) | ft_strcapitalize.c | ✅ 16 | [Exercise 10:](ex10/) | ft_strlcpy.c | ✅ 17 | [Exercise 11:](ex11/) | ft_putstr_non_printable.c | ✅ 18 | [Exercise 12:](ex12/) | ft_print_memory.c | ❌ -------------------------------------------------------------------------------- /code/R02/ex00/dict_esp.dict: -------------------------------------------------------------------------------- 1 | 0: zero 2 | 1: uno 3 | 2: dos 4 | 3: tres 5 | 4: cuatro 6 | 5: cinco 7 | 6: seis 8 | 7: siete 9 | 8: ocho 10 | 9: nueve 11 | 10: diez 12 | 11: once 13 | 12: doce 14 | 13: trece 15 | 14: catorce 16 | 15: quince 17 | 16: dieciseis 18 | 17: diecisiete 19 | 18: dieciocho 20 | 19: diecinueve 21 | 20: veinte 22 | 30: treinta 23 | 40: cuarenta 24 | 50: cincuenta 25 | 60: sesenta 26 | 70: setenta 27 | 80: ochenta 28 | 90: noventa 29 | 100: cien 30 | 1000: mil 31 | 1000000: millon 32 | 1000000000: mil millon 33 | 1000000000000: billon 34 | 1000000000000000: cuatrillon 35 | 1000000000000000000: quintillon 36 | 1000000000000000000000: sextillon 37 | 1000000000000000000000000: setillon 38 | 1000000000000000000000000000: octillon 39 | 1000000000000000000000000000000: nonillon 40 | 1000000000000000000000000000000000: decillon 41 | 1000000000000000000000000000000000000: undecillon 42 | -------------------------------------------------------------------------------- /code/R02/ex00/dict_eng.dict: -------------------------------------------------------------------------------- 1 | 0: zero 2 | 1: one 3 | 2: two 4 | 3: three 5 | 4: four 6 | 5: five 7 | 6: six 8 | 7: seven 9 | 8: eight 10 | 9: nine 11 | 10: ten 12 | 11: eleven 13 | 12: twelve 14 | 13: thirteen 15 | 14: fourteen 16 | 15: fifteen 17 | 16: sixteen 18 | 17: seventeen 19 | 18: eighteen 20 | 19: nineteen 21 | 20: twenty 22 | 30: thirty 23 | 40: forty 24 | 50: fifty 25 | 60: sixty 26 | 70: seventy 27 | 80: eighty 28 | 90: ninety 29 | 100: hundred 30 | 1000: thousand 31 | 1000000: million 32 | 1000000000: billion 33 | 1000000000000: trillion 34 | 1000000000000000: quadrillion 35 | 1000000000000000000: quintillion 36 | 1000000000000000000000: sextillion 37 | 1000000000000000000000000: septillion 38 | 1000000000000000000000000000: octillion 39 | 1000000000000000000000000000000: nonillion 40 | 1000000000000000000000000000000000: decillion 41 | 1000000000000000000000000000000000000: undecillion 42 | -------------------------------------------------------------------------------- /code/C00/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 13:20:33 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 14:46:06 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /code/C09/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 19:20:54 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 19:25:15 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /code/C12/README.md: -------------------------------------------------------------------------------- 1 | ## C12 2 | --------------------- 3 | 4 | Links | Exercise | Validation 5 | ------|----------|------------ 6 | [Exercise 00:](ex00/) | ft_create_elem.c | ❔ 7 | [Exercise 01:](ex01/) | ft_list_push_front.c | ❔ 8 | [Exercise 02:](ex02/) | ft_list_size.c | ❔ 9 | [Exercise 03:](ex03/) | ft_list_last.c | ❔ 10 | [Exercise 04:](ex04/) | ft_list_push_back.c | ❔ 11 | [Exercise 05:](ex05/) | ft_list_push_strs.c | ❔ 12 | [Exercise 06:](ex06/) | ft_list_clear.c | ❔ 13 | [Exercise 07:](ex07/) | ft_list_at.c | ❔ 14 | [Exercise 08:](ex08/) | ft_list_reverse.c | ❔ 15 | [Exercise 09:](ex09/) | ft_list_foreach.c | ❔ 16 | [Exercise 10:](ex10/) | ft_list_foreach_if.c | ❔ 17 | [Exercise 11:](ex11/) | ft_list_find.c | ❔ 18 | [Exercise 12:](ex12/) | ft_list_remove_if.c | ❔ 19 | [Exercise 13:](ex13/) | ft_list_merge.c | ❔ 20 | [Exercise 14:](ex14/) | ft_list_sort.c | ❔ 21 | [Exercise 15:](ex15/) | ft_list_reverse_fun.c | ❔ 22 | [Exercise 16:](ex16/) | ft_sorted_list_insert.c | ❔ 23 | [Exercise 17:](ex17/) | ft_sorted_list_merge.c | ❔ -------------------------------------------------------------------------------- /code/R00/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: manda-si +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 19:16:10 by manda-si #+# #+# */ 9 | /* Updated: 2022/08/20 19:32:37 by manda-si ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | -------------------------------------------------------------------------------- /code/C09/ex00/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 19:21:22 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 19:25:40 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_swap(int *a, int *b) 14 | { 15 | int aux; 16 | 17 | aux = *a; 18 | *a = *b; 19 | *b = aux; 20 | } 21 | -------------------------------------------------------------------------------- /code/C01/ex00/ft_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 11:26:53 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 22:41:04 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_ft(int *nbr) 17 | { 18 | *nbr = 42; 19 | } 20 | z 21 | -------------------------------------------------------------------------------- /code/BSQ/map4: -------------------------------------------------------------------------------- 1 | 30.ox 2 | ............................o. 3 | ...o..o....o.................. 4 | .......o............o......... 5 | .o...........o................ 6 | ..o........................... 7 | ...............o.....o........ 8 | ..................o........... 9 | ....................o......... 10 | .............................. 11 | .......................o...... 12 | .............................. 13 | ...........................o.. 14 | .............................. 15 | ..........o................... 16 | .........o.................... 17 | ........................o..... 18 | ............................o. 19 | .............................. 20 | ................o............. 21 | .............................. 22 | ..................o........... 23 | .............o................ 24 | .............................. 25 | o......o...................... 26 | .......................o...... 27 | .............................o 28 | .o............................ 29 | .............................. 30 | ......................o.o..... 31 | ...o.......................... 32 | -------------------------------------------------------------------------------- /code/C08/ex02/ft_abs.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_abs.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 16:09:24 by ncarvalh #+# #+# */ 9 | /* Updated: 2023/08/15 15:16:50 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_ABS_H 14 | # define FT_ABS_H 15 | 16 | # define ABS(Value) ((Value) * (Value > 0) - (Value) * (Value < 0)) 17 | 18 | #endif -------------------------------------------------------------------------------- /code/C09/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 19:23:18 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 19:25:24 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | int ft_strlen(char *str) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str[i] != '\0') 19 | i++; 20 | return (i); 21 | } 22 | -------------------------------------------------------------------------------- /code/R00/ex00/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: manda-si +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 23:40:30 by manda-si #+# #+# */ 9 | /* Updated: 2022/08/21 16:05:48 by maricard ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void rush(int x, int y); 16 | 17 | int main(void) 18 | { 19 | rush (1, 5); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /code/R01/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putchar.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tlope-de +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/28 16:04:31 by tlope-de #+# #+# */ 9 | /* Updated: 2022/08/28 16:05:02 by tlope-de ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putchar(char c) 18 | { 19 | write(1, &c, 1); 20 | } 21 | -------------------------------------------------------------------------------- /code/C09/ex00/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 19:22:08 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 19:33:14 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | void ft_putchar(char c); 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | ft_putchar(str[i++]); 22 | } 23 | -------------------------------------------------------------------------------- /code/C09/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 19:23:59 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 19:25:13 by ncarvalh ### ########.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] != '\0') 19 | i++; 20 | return (s1[i] - s2[i]); 21 | } 22 | -------------------------------------------------------------------------------- /code/C10/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/15 09:37:03 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 09:38:11 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | int main(int argc, char **argv) 20 | { 21 | if(argc == 1) 22 | 23 | } -------------------------------------------------------------------------------- /code/C08/ex03/ft_point.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_point.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 16:22:42 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 18:38:04 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_POINT_H 14 | # define FT_POINT_H 15 | 16 | # include 17 | 18 | typedef struct s_point 19 | { 20 | int x; 21 | int y; 22 | } t_point; 23 | 24 | void set_point(t_point *point); 25 | 26 | #endif -------------------------------------------------------------------------------- /code/C12/ex00/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | #endif -------------------------------------------------------------------------------- /code/C12/ex01/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | #endif -------------------------------------------------------------------------------- /code/C12/ex02/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | #endif -------------------------------------------------------------------------------- /code/C12/ex03/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | #endif -------------------------------------------------------------------------------- /code/C08/ex00/ft.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 15:35:51 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 15:42:59 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_H 14 | # define FT_H 15 | 16 | void ft_putchar(char c); 17 | 18 | void ft_swap(int *a, int *b); 19 | 20 | void ft_putstr(char *str); 21 | 22 | int ft_strlen(char *str); 23 | 24 | int ft_strcmp(char *s1, char *s2); 25 | 26 | #endif -------------------------------------------------------------------------------- /code/C00/ex04/ft_is_negative.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_negative.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 13:56:58 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:41:37 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_is_negative(int n) 21 | { 22 | if (n < 0) 23 | { 24 | ft_putchar('N'); 25 | } 26 | else 27 | { 28 | ft_putchar('P'); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /code/C10/ft_utils.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_utils.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/15 09:38:26 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 09:40:06 by crypto ### ########.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 | void ft_putstr(char *str) 26 | { 27 | write(STDOUT_FILENO, str, ft_strlen(str)); 28 | } -------------------------------------------------------------------------------- /code/C00/ex03/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_numbers.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 13:54:09 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:39:47 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_numbers(void) 21 | { 22 | char number; 23 | 24 | number = '0'; 25 | while (number <= '9') 26 | { 27 | ft_putchar(number); 28 | number++; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /code/C12/ex04/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | t_list *ft_list_last(t_list *begin_list); 25 | 26 | #endif -------------------------------------------------------------------------------- /code/C00/ex01/ft_print_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 13:30:02 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:34:23 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_alphabet(void) 21 | { 22 | char letter; 23 | 24 | letter = 'a'; 25 | while (letter <= 'z') 26 | { 27 | ft_putchar(letter); 28 | letter++; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /code/C04/ex01/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/24 12:58:46 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 11:43:41 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putstr(char *str) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (str[i] != '\0') 26 | ft_putchar(str[i++]); 27 | } 28 | /* 29 | int main(){ 30 | ft_putstr("Hello\n"); 31 | } */ -------------------------------------------------------------------------------- /code/C00/ex02/ft_print_reverse_alphabet.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_reverse_alphabet.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 13:49:57 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:38:30 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_print_reverse_alphabet(void) 21 | { 22 | char letter; 23 | 24 | letter = 'z'; 25 | while (letter >= 'a') 26 | { 27 | ft_putchar(letter); 28 | letter--; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /code/C06/ex00/ft_print_program_name.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_program_name.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/29 13:36:31 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 13:44:12 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | write(1, &str[i++], 1); 22 | } 23 | 24 | int main(int argc, char **argv) 25 | { 26 | if (argc > 0) 27 | { 28 | ft_putstr(argv[0]); 29 | write(1, "\n", 1); 30 | } 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /code/C01/ex06/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 14:24:43 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 20:41:27 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | int ft_strlen(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | i++; 24 | } 25 | return (i); 26 | } 27 | 28 | /* int main(){ 29 | char string[] = "Hello World!"; 30 | printf("The size of the string is %d\n", ft_strlen(string)); 31 | } */ 32 | -------------------------------------------------------------------------------- /code/C01/ex02/ft_swap.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_swap.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 13:32:10 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 21:56:44 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_swap(int *a, int *b) 17 | { 18 | int aux; 19 | 20 | aux = *a; 21 | *a = *b; 22 | *b = aux; 23 | } 24 | /* 25 | int main(){ 26 | int a = 7, b = 3; 27 | 28 | printf("Sending a = %d and b = %d\n", a, b); 29 | ft_swap(&a, &b); 30 | printf("Returned a = %d and b = %d\n", a, b); 31 | } */ -------------------------------------------------------------------------------- /code/C01/ex05/ft_putstr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 13:58:44 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 21:42:03 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putstr(char *str) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (str[i] != '\0') 26 | { 27 | ft_putchar(str[i]); 28 | i++; 29 | } 30 | } 31 | 32 | /* int main(){ 33 | char string[] = "Hello World!"; 34 | ft_putstr(string); 35 | } */ 36 | -------------------------------------------------------------------------------- /code/C01/ex03/ft_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 13:48:13 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 21:54:11 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_div_mod(int a, int b, int *div, int *mod) 17 | { 18 | *div = a / b; 19 | *mod = a % b; 20 | } 21 | 22 | /* int main(){ 23 | int a = 1, b = 2, div = 0, mod = 0; 24 | 25 | printf("Sending a = %d and b = %d\n", a, b); 26 | ft_div_mod(a, b, &div, &mod); 27 | printf("Returned div = %d and mod = %d\n", div, mod); 28 | } */ -------------------------------------------------------------------------------- /code/C11/ex05/srcs/ft_ops.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ops.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 10:04:31 by crypto #+# #+# */ 9 | /* Updated: 2022/09/14 23:47:18 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "do_op.h" 14 | 15 | int ft_add(int n1, int n2) 16 | { 17 | return (n1 + n2); 18 | } 19 | 20 | int ft_sub(int n1, int n2) 21 | { 22 | return (n1 - n2); 23 | } 24 | 25 | int ft_mult(int n1, int n2) 26 | { 27 | return (n1 * n2); 28 | } 29 | 30 | int ft_div(int n1, int n2) 31 | { 32 | return (n1 / n2); 33 | } 34 | 35 | int ft_mod(int n1, int n2) 36 | { 37 | return (n1 % n2); 38 | } -------------------------------------------------------------------------------- /code/C00/ex07/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 14:28:14 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 18:43:37 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_putchar(char c) 17 | { 18 | write(1, &c, 1); 19 | } 20 | 21 | void ft_putnbr(int nb) 22 | { 23 | long int n; 24 | 25 | n = nb; 26 | if (nb < 0) 27 | { 28 | ft_putchar('-'); 29 | n = -n; 30 | } 31 | if (n < 10) 32 | { 33 | ft_putchar(n + '0'); 34 | } 35 | else 36 | { 37 | ft_putnbr(n / 10); 38 | ft_putchar(n % 10 + '0'); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /code/C08/ex01/ft_boolean.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_boolean.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/01 15:45:21 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 18:35:45 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef FT_BOOLEAN_H 14 | # define FT_BOOLEAN_H 15 | 16 | # include 17 | 18 | # define TRUE 1 19 | # define FALSE 0 20 | # define SUCCESS 0 21 | # define EVEN(i) i % 2 == 0 22 | # define EVEN_MSG "I have an even number of arguments.\n" 23 | # define ODD_MSG "I have an odd number of arguments.\n" 24 | 25 | typedef int t_bool; 26 | 27 | void ft_putstr(char *str); 28 | 29 | t_bool ft_is_even(int nbr); 30 | 31 | #endif -------------------------------------------------------------------------------- /code/C05/ex00/ft_iterative_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 15:48:44 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 12:33:02 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_iterative_factorial(int nb) 17 | { 18 | int number; 19 | 20 | number = 1; 21 | if (nb < 0) 22 | return (0); 23 | while (nb > 1) 24 | number = number * nb--; 25 | return (number); 26 | } 27 | 28 | /* int main(int argc, char **argv) 29 | { 30 | int n = atoi(argv[argc - 1]); 31 | printf("Sending n = %d\n", n); 32 | printf("Returning %d\n", ft_iterative_factorial(n)); 33 | } */ -------------------------------------------------------------------------------- /code/C02/ex07/ft_strupcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strupcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 01:34:57 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:54:12 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | char *ft_strupcase(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] >= 'a' && str[i] <= 'z') 24 | str[i] -= 'a' - 'A'; 25 | i++; 26 | } 27 | return (str); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "Zallo"; 32 | 33 | printf("Sending str1 = \"%s\" \n", str1); 34 | printf("Returning str1 = \"%s\" \n", ft_strupcase(str1)); 35 | } */ -------------------------------------------------------------------------------- /code/C02/ex08/ft_strlowcase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlowcase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 01:41:37 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:57:28 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | char *ft_strlowcase(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] >= 'A' && str[i] <= 'Z') 24 | str[i] += 'a' - 'A'; 25 | i++; 26 | } 27 | return (str); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "hello"; 32 | 33 | printf("Sending str1 = \"%s\" \n", str1); 34 | printf("Returning str1 = \"%s\" \n", ft_strlowcase(str1)); 35 | } */ -------------------------------------------------------------------------------- /code/C05/ex01/ft_recursive_factorial.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_factorial.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 15:58:27 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/02 12:30:49 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_recursive_factorial(int nb) 17 | { 18 | if (nb < 0) 19 | return (0); 20 | else if (nb == 0 || nb == 1) 21 | return (1); 22 | else 23 | return (nb * ft_recursive_factorial(nb - 1)); 24 | } 25 | /* 26 | int main(int argc, char **argv) 27 | { 28 | int n = atoi(argv[argc - 1]); 29 | printf("Sending n = %d\n", n); 30 | printf("Returning %d\n", ft_recursive_factorial(n)); 31 | } */ -------------------------------------------------------------------------------- /code/R02/ex00/rush.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/03 15:07:23 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/04 03:11:43 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef RUSH_H 14 | # define RUSH_H 15 | 16 | # include 17 | # include 18 | # include 19 | # include 20 | # include 21 | # include 22 | # define DEFAULT_FILE "dict_eng.dict" 23 | # define DEBUG 24 | 25 | typedef struct s_pair 26 | { 27 | unsigned int key; 28 | char *value; 29 | } t_pair; 30 | 31 | typedef struct s_vector 32 | { 33 | t_pair **array; 34 | int size; 35 | } t_vector; 36 | 37 | #endif -------------------------------------------------------------------------------- /code/C12/ex05/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | #endif -------------------------------------------------------------------------------- /code/C01/ex04/ft_ultimate_div_mod.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_div_mod.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 13:51:54 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 21:53:35 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_ultimate_div_mod(int *a, int *b) 17 | { 18 | int aux_a; 19 | int aux_b; 20 | 21 | aux_a = *a; 22 | aux_b = *b; 23 | *a = aux_a / aux_b; 24 | *b = aux_a % aux_b; 25 | } 26 | /* 27 | int main(){ 28 | int a = 7, b = 3; 29 | int *ptr1 = &a, *ptr2 = &b; 30 | 31 | printf("Sending a = %d and b = %d\n", a, b); 32 | ft_ultimate_div_mod(ptr1, ptr2); 33 | printf("Returned a = %d and b = %d\n", a, b); 34 | } */ -------------------------------------------------------------------------------- /code/C05/ex06/ft_is_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 20:02:41 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 12:57:35 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_is_prime(int nb) 17 | { 18 | int i; 19 | 20 | i = 2; 21 | if (nb <= 1) 22 | return (0); 23 | while (i < nb) 24 | { 25 | if (nb % i == 0) 26 | return (0); 27 | i++; 28 | } 29 | return (1); 30 | } 31 | /* 32 | int main(int argc, char **argv){ 33 | int n = atoi(argv[argc - 1]); 34 | if(ft_is_prime(n)) 35 | printf("%d is a prime number\n", n); 36 | else 37 | printf("%d is NOT a prime number\n", n); 38 | } */ -------------------------------------------------------------------------------- /code/C09/ex01/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncarvalh +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/09/07 08:17:59 by ncarvalh #+# #+# # 9 | # Updated: 2022/09/07 08:17:59 by ncarvalh ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC = gcc 14 | FLAGS = -Wall -Wextra -Werror 15 | DEPS = includes 16 | OBJDIR = srcs 17 | 18 | TARGET = ft_putchar.o ft_putstr.o ft_strcmp.o ft_strlen.o ft_swap.o 19 | OBJS = ${addprefix $(OBJDIR)/, $(TARGET)} 20 | 21 | %.o : %.c 22 | $(CC) $(FLAGS) -c $< -o $@ -I $(DEPS) 23 | 24 | all: libft.a 25 | 26 | clean: 27 | rm -f $(OBJS) 28 | 29 | fclean: clean 30 | rm -f libft.a 31 | 32 | re: fclean all 33 | 34 | libft.a: $(OBJS) 35 | ar -rc libft.a $^ 36 | -------------------------------------------------------------------------------- /code/R01/ex00/in_row_column.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* in_row_column.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: tlope-de +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/28 16:06:37 by tlope-de #+# #+# */ 9 | /* Updated: 2022/08/28 16:06:41 by tlope-de ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int in_row(char **board, int row, int col, int digit) 18 | { 19 | int i; 20 | 21 | i = 1; 22 | while (i < col) 23 | if (board[row][i++] == digit + '0') 24 | return (1); 25 | return (0); 26 | } 27 | 28 | int in_column(char **board, int row, int col, int digit) 29 | { 30 | int i; 31 | 32 | i = 1; 33 | while (i < row) 34 | if (board[i++][col] == digit + '0') 35 | return (1); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /code/C02/ex03/ft_str_is_numeric.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_numeric.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 22:56:45 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/26 14:52:36 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_str_is_numeric(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] < '0' || str[i] > '9') 24 | return (0); 25 | i++; 26 | } 27 | return (1); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "1231415"; 32 | 33 | if (fr_str_is_numeric(str1)) 34 | printf("The string \"%s\" is numeric.\n", str1); 35 | else 36 | printf("The string \"%s\" is not numeric.\n", str1); 37 | } */ -------------------------------------------------------------------------------- /code/C06/ex01/ft_print_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/29 15:20:27 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/30 09:26:18 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | write(1, &str[i++], 1); 22 | } 23 | 24 | void print_params(int argc, char **argv) 25 | { 26 | int i; 27 | 28 | i = 1; 29 | while (i < argc) 30 | { 31 | ft_putstr(argv[i++]); 32 | write(1, "\n", 1); 33 | } 34 | } 35 | 36 | int main(int argc, char **argv) 37 | { 38 | if (argc <= 0) 39 | return (0); 40 | print_params(argc, argv); 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /code/C02/ex04/ft_str_is_lowercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_lowercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 23:06:12 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/26 14:52:39 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_str_is_lowercase(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] < 'a' || str[i] > 'z') 24 | return (0); 25 | i++; 26 | } 27 | return (1); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "hello"; 32 | 33 | if (fr_str_is_lowercase(str1)) 34 | printf("The string \"%s\" is lowercase.\n", str1); 35 | else 36 | printf("The string \"%s\" is not lowercase.\n", str1); 37 | } */ -------------------------------------------------------------------------------- /code/C02/ex05/ft_str_is_uppercase.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_uppercase.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 23:06:12 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/26 14:52:42 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_str_is_uppercase(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] < 'A' || str[i] > 'Z') 24 | return (0); 25 | i++; 26 | } 27 | return (1); 28 | } 29 | 30 | /* int main(){ 31 | char str1[] = "HELLO"; 32 | 33 | if (fr_str_is_uppercase(str1)) 34 | printf("The string \"%s\" is uppercase.\n", str1); 35 | else 36 | printf("The string \"%s\" is not uppercase.\n", str1); 37 | } */ -------------------------------------------------------------------------------- /code/C05/ex04/ft_fibonacci.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_fibonacci.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 16:21:48 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 12:52:38 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_fibonacci(int index) 17 | { 18 | if (index < 0) 19 | return (-1); 20 | else if (index == 0) 21 | return (0); 22 | else if (index == 1) 23 | return (1); 24 | else 25 | return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); 26 | } 27 | /* 28 | int main(int argc, char **argv) 29 | { 30 | int index = atoi(argv[argc - 1]); 31 | 32 | printf("Sending index = %d\n", index); 33 | printf("Returning %d\n", ft_fibonacci(index)); 34 | } */ -------------------------------------------------------------------------------- /code/C06/ex02/ft_rev_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/29 15:32:19 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/30 09:39:47 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | write(1, &str[i++], 1); 22 | } 23 | 24 | void print_params(int argc, char **argv) 25 | { 26 | int i; 27 | 28 | i = argc - 1; 29 | while (i >= 1) 30 | { 31 | ft_putstr(argv[i--]); 32 | write(1, "\n", 1); 33 | } 34 | } 35 | 36 | int main(int argc, char **argv) 37 | { 38 | if (argc <= 0) 39 | return (0); 40 | print_params(argc, argv); 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /code/R01/ex00/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/28 16:06:53 by tlope-de #+# #+# */ 9 | /* Updated: 2022/08/28 19:31:04 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void rush(int n, char **conds); 18 | 19 | int verify_params(int n, char **argv); 20 | 21 | void print_error(void); 22 | 23 | char **create_conds(int n, char *str); 24 | 25 | int main(int argc, char **argv) 26 | { 27 | int dim; 28 | char **conds; 29 | 30 | dim = verify_params(argc, argv); 31 | conds = create_conds(dim, argv[1]); 32 | if (!dim || argc != 2) 33 | print_error(); 34 | else 35 | rush(dim, conds); 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /code/C02/ex06/ft_str_is_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 23:06:12 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:52:08 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_str_is_printable(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (str[i] < 32 || str[i] > 126) 24 | return (0); 25 | i++; 26 | } 27 | return (1); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "abcdeghijklmnopqrstuvwxyz"; 32 | 33 | if (ft_str_is_printable(str1)) 34 | printf("The string \"%s\" is printable.\n", str1); 35 | else 36 | printf("The string \"%s\" is not printable.\n", str1); 37 | } */ -------------------------------------------------------------------------------- /code/C04/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlen.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/24 12:39:53 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 11:44:16 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_strlen(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | i++; 23 | return (i); 24 | } 25 | /* 26 | int main(){ 27 | char string[] = "Hello"; 28 | 29 | printf("*********** TEST WITH strlen() ***********\n\n"); 30 | printf("Length of \"%s\" = %ld\n\n", string, strlen(string)); 31 | 32 | printf("*********** TEST WITH ft_strlen() ***********\n\n"); 33 | printf("Length of \"%s\" = %d\n\n", string, ft_strlen(string)); 34 | } */ 35 | -------------------------------------------------------------------------------- /code/BSQ/Makefile: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # Makefile :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: ncarvalh +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2022/09/07 16:48:28 by ncarvalh #+# #+# # 9 | # Updated: 2022/09/07 16:58:53 by ncarvalh ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | CC = gcc 14 | FLAGS = -Wall -Wextra -Werror 15 | DEPS = includes 16 | OBJDIR = srcs 17 | EXEC = bsq 18 | 19 | TARGET = ft_bsq.o ft_file_parser_1.o ft_file_parser_2.o ft_helper_1.o ft_helper_2.o ft_integer.o ft_string_1.o ft_string_2.o 20 | OBJS = ${addprefix $(OBJDIR)/, $(TARGET)} 21 | 22 | %.o : %.c 23 | $(CC) $(FLAGS) -c $< -o $@ -I $(DEPS) 24 | 25 | all: $(OBJS) 26 | $(CC) $(FLAGS) main.c -o $(EXEC) $(OBJS) 27 | 28 | clean: 29 | rm -f $(OBJS) 30 | 31 | fclean: clean 32 | rm -f $(EXEC) 33 | 34 | re: fclean all 35 | 36 | 37 | -------------------------------------------------------------------------------- /code/C11/ex05/srcs/do_op.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* do_op.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 10:03:04 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 00:22:28 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "do_op.h" 15 | 16 | void do_op(int n1, int n2, int op) 17 | { 18 | int (*array[5])(int, int); 19 | 20 | array[ADD] = ft_add; 21 | array[SUB] = ft_sub; 22 | array[MULT] = ft_mult; 23 | array[DIV] = ft_div; 24 | array[MOD] = ft_mod; 25 | 26 | if(op == DIV && n2 == 0) 27 | ft_putstr("Stop : division by zero\n"); 28 | else if(op == MOD && n2 == 0) 29 | ft_putstr("Stop : modulo by zero\n"); 30 | else 31 | ft_putnbr(array[op](n1, n2)); 32 | } -------------------------------------------------------------------------------- /code/C12/ex06/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | #endif -------------------------------------------------------------------------------- /code/C02/ex02/ft_str_is_alpha.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_str_is_alpha.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 22:44:46 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:31:35 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_str_is_alpha(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if ((str[i] < 'a' || str[i] > 'z') && (str[i] < 'A' || str[i] > 'Z')) 24 | return (0); 25 | i++; 26 | } 27 | return (1); 28 | } 29 | /* 30 | int main(){ 31 | char str1[] = "HelloWorld"; 32 | 33 | if (ft_str_is_alpha(str1)) 34 | printf("The string \"%s\" is alphabetic.\n", str1); 35 | else 36 | printf("The string \"%s\" is not alphabetic.\n", str1); 37 | } */ -------------------------------------------------------------------------------- /code/C05/ex07/ft_find_next_prime.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_find_next_prime.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 20:18:55 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/06 09:41:48 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_is_prime(int nb) 17 | { 18 | int i; 19 | 20 | i = 2; 21 | if (nb <= 1) 22 | return (0); 23 | while (i <= nb / 2) 24 | { 25 | if (nb % i == 0) 26 | return (0); 27 | i++; 28 | } 29 | return (1); 30 | } 31 | 32 | int ft_find_next_prime(int nb) 33 | { 34 | while (nb < 2147483647 && !ft_is_prime(nb)) 35 | nb++; 36 | return (nb); 37 | } 38 | 39 | int main(int argc, char **argv){ 40 | int n = atoi(argv[argc - 1]); 41 | printf("The closest prime to %d is %d\n", n, ft_find_next_prime(n)); 42 | } -------------------------------------------------------------------------------- /code/C05/ex03/ft_recursive_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_recursive_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 16:10:18 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 12:48:14 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_recursive_power(int nb, int power) 17 | { 18 | if (power < 0) 19 | return (0); 20 | else if (power == 0) 21 | return (1); 22 | else if (power == 1) 23 | return (nb); 24 | else 25 | return (nb * ft_recursive_power(nb, power - 1)); 26 | } 27 | 28 | /* 29 | int main(int argc, char **argv) 30 | { 31 | int n = atoi(argv[argc - 2]); 32 | int power = atoi(argv[argc - 1]); 33 | 34 | printf("Sending n = %d and power = %d\n", n, power); 35 | printf("Returning %d\n", ft_recursive_power(n, power)); 36 | } */ -------------------------------------------------------------------------------- /code/C11/ex05/includes/do_op.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* do_op.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 09:50:30 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 00:21:03 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #ifndef DO_OP_H 14 | # define DO_OP_H 15 | 16 | # define ADD 0 17 | # define SUB 1 18 | # define MULT 2 19 | # define DIV 3 20 | # define MOD 4 21 | 22 | int ft_atoi(char *str); 23 | 24 | void ft_putchar(char c); 25 | 26 | int ft_strlen(char *str); 27 | 28 | void do_op(int n1, int n2, int op); 29 | 30 | void ft_putnbr(long int n); 31 | 32 | void ft_putstr(char *str); 33 | 34 | int ft_add(int n1, int n2); 35 | 36 | int ft_sub(int n1, int n2); 37 | 38 | int ft_mult(int n1, int n2); 39 | 40 | int ft_div(int n1, int n2); 41 | 42 | int ft_mod(int n1, int n2); 43 | 44 | 45 | #endif -------------------------------------------------------------------------------- /code/C05/ex02/ft_iterative_power.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_iterative_power.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 16:03:01 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 12:45:52 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_iterative_power(int nb, int power) 17 | { 18 | int i; 19 | int number; 20 | 21 | i = 0; 22 | number = 1; 23 | if (power == 0) 24 | return (1); 25 | else if (power < 0) 26 | return (0); 27 | while (i++ < power) 28 | number *= nb; 29 | return (number); 30 | } 31 | /* 32 | int main(int argc, char **argv) 33 | { 34 | int n = atoi(argv[argc - 2]); 35 | int power = atoi(argv[argc - 1]); 36 | 37 | printf("Sending n = %d and power = %d\n", n, power); 38 | printf("Returning %d\n", ft_iterative_power(n, power)); 39 | } */ -------------------------------------------------------------------------------- /code/R00/ex00/rush03.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush03.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 19:17:17 by manda-si #+# #+# */ 9 | /* Updated: 2022/08/20 19:58:49 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c); 16 | 17 | void rush(int x, int y) 18 | { 19 | int x1; 20 | int y1; 21 | 22 | y1 = 1; 23 | while (y1 <= y && x > 0) 24 | { 25 | x1 = 1; 26 | while (x1 <= x) 27 | { 28 | if ((x1 == 1 && y1 == 1) || (x1 == 1 && y1 == y)) 29 | ft_putchar('A'); 30 | else if ((x1 == x && y1 == 1) || (x1 == x && y1 == y)) 31 | ft_putchar('C'); 32 | else if ((x1 == 1) || (x1 == x) || (y1 == 1) || (y1 == y)) 33 | ft_putchar('B'); 34 | else 35 | ft_putchar(' '); 36 | x1++; 37 | } 38 | ft_putchar('\n'); 39 | y1++; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /code/C12/ex00/ft_create_elem.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_create_elem.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:59:24 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:59:24 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | t_list *ft_create_elem(void *data) 18 | { 19 | t_list *elem; 20 | 21 | elem = malloc(sizeof(t_list)); 22 | if (!elem) 23 | return (NULL); 24 | elem->data = data; 25 | elem->next = NULL; 26 | return (elem); 27 | } 28 | /* 29 | int main() 30 | { 31 | int a; 32 | t_list *list; 33 | 34 | a = 42; 35 | list = ft_create_elem(&a); 36 | if (!list) 37 | return (EXIT_FAILURE); 38 | 39 | printf("Value of elem->data: %d\n", *(int *)list->data); 40 | free(list); 41 | } 42 | */ -------------------------------------------------------------------------------- /code/C11/ex05/srcs/ft_util.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_util.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 09:56:09 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 00:18:26 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include "do_op.h" 15 | 16 | void ft_putchar(char c) 17 | { 18 | write(STDOUT_FILENO, &c, 1); 19 | } 20 | 21 | void ft_putnbr(long int n) 22 | { 23 | if(n < 0) 24 | n = -n; 25 | if(n < 10) 26 | ft_putchar(n + '0'); 27 | else 28 | { 29 | ft_putnbr(n / 10); 30 | ft_putnbr(n % 10); 31 | } 32 | } 33 | 34 | void ft_putstr(char *str) 35 | { 36 | write(1, str, ft_strlen(str)); 37 | } 38 | 39 | int ft_strlen(char *str) 40 | { 41 | int i; 42 | 43 | i = 0; 44 | while (str[i]) 45 | i++; 46 | return (i); 47 | } -------------------------------------------------------------------------------- /code/C12/ex07/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | #endif -------------------------------------------------------------------------------- /code/BSQ/srcs/ft_helper_1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_helper_1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 17:21:41 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 21:41:14 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../includes/ft_bsq.h" 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | int ft_min_2(int n1, int n2) 21 | { 22 | if (n1 < n2) 23 | return (n1); 24 | return (n2); 25 | } 26 | 27 | int ft_min_3(int n1, int n2, int n3) 28 | { 29 | return (ft_min_2(n1, ft_min_2(n2, n3))); 30 | } 31 | 32 | void ft_print_error(char *message) 33 | { 34 | write(STDERR_FILENO, message, ft_strlen(message)); 35 | } 36 | 37 | void ft_assert(int condition, char *message) 38 | { 39 | if (!condition) 40 | { 41 | if (message != NULL) 42 | ft_print_error(message); 43 | exit(EXIT_FAILURE); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /code/C11/ex04/ft_is_sort.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_is_sort.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 07:50:04 by crypto #+# #+# */ 9 | /* Updated: 2022/09/14 09:27:21 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int is_bigger(int n1, int n2) 17 | { 18 | return (n1 - n2); 19 | } 20 | 21 | int ft_is_sort(int *tab, int length, int (*f)(int, int)) 22 | { 23 | int i; 24 | 25 | i = 0; 26 | if(tab == NULL || length == 0 || f == NULL) 27 | return (0); 28 | while(i < length - 1) 29 | { 30 | if (f(tab[i], tab[i + 1]) > 0) 31 | return (0); 32 | i++; 33 | } 34 | return (1); 35 | } 36 | 37 | int main(void) 38 | { 39 | int array[] = {3, 3}; 40 | int size = 2; 41 | 42 | printf("%d\n", ft_is_sort(array, size, &is_bigger)); 43 | } -------------------------------------------------------------------------------- /code/C01/ex07/ft_rev_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_rev_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 14:29:43 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 16:44:01 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_rev_int_tab(int *tab, int size) 17 | { 18 | int i; 19 | int aux; 20 | 21 | i = 0; 22 | while (i < size / 2) 23 | { 24 | aux = tab[size - i - 1]; 25 | tab[size - i - 1] = tab[i]; 26 | tab[i] = aux; 27 | i++; 28 | } 29 | } 30 | /* 31 | void print_array(int array[], int size){ 32 | for(int i = 0; i < size; i++){ 33 | printf("%d ", array[i]); 34 | } 35 | printf("\n"); 36 | } 37 | 38 | int main() 39 | { 40 | int array[] = {1, 2, 3, 4, 5}; 41 | int size = 5; 42 | 43 | ft_rev_int_tab(array, size); 44 | print_array(array, size); 45 | 46 | return 0; 47 | } */ 48 | -------------------------------------------------------------------------------- /code/C01/ex01/ft_ultimate_ft.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ultimate_ft.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 11:29:07 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 22:02:39 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | //#include 15 | 16 | void ft_ultimate_ft(int *********nbr) 17 | { 18 | *********nbr = 42; 19 | } 20 | /* 21 | int main(){ 22 | int a = 0; 23 | int *ptr1; 24 | int **ptr2; 25 | int ***ptr3; 26 | int ****ptr4; 27 | int *****ptr5; 28 | int ******ptr6; 29 | int *******ptr7; 30 | int ********ptr8; 31 | int *********ptr9; 32 | 33 | ptr1 = &a; 34 | ptr2 = &ptr1; 35 | ptr3 = &ptr2; 36 | ptr4 = &ptr3; 37 | ptr5 = &ptr4; 38 | ptr6 = &ptr5; 39 | ptr7 = &ptr6; 40 | ptr8 = &ptr7; 41 | ptr9 = &ptr8; 42 | 43 | printf("Sending a = %d\n", a); 44 | ft_ultimate_ft(ptr9); 45 | printf("Returned a = %d\n", a); 46 | } */ 47 | -------------------------------------------------------------------------------- /code/BSQ/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 07:40:04 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 21:53:11 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "includes/ft_bsq.h" 14 | 15 | void execute(char *file) 16 | { 17 | t_map *map; 18 | 19 | map = ft_new_map(file); 20 | ft_bsq(map); 21 | ft_delete_map(map); 22 | free(file); 23 | } 24 | 25 | int main(int argc, char **argv) 26 | { 27 | char *file; 28 | int i; 29 | 30 | i = 1; 31 | if (argc == 1) 32 | { 33 | file = ft_parse_file(NULL, read_terminal()); 34 | if (file != NULL) 35 | execute(file); 36 | } 37 | else 38 | { 39 | while (i < argc) 40 | { 41 | file = ft_parse_file(argv[i], NULL); 42 | if (file != NULL) 43 | execute(file); 44 | if (i != argc - 1) 45 | write(1, "\n", 1); 46 | i++; 47 | } 48 | } 49 | return (0); 50 | } 51 | -------------------------------------------------------------------------------- /code/BSQ/srcs/ft_string_2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_string_2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 15:08:59 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 19:50:06 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../includes/ft_bsq.h" 14 | 15 | char *ft_strcat(char *dest, char *src) 16 | { 17 | int i; 18 | int k; 19 | 20 | k = 0; 21 | i = ft_strlen(dest); 22 | while (src[k] != '\0') 23 | { 24 | dest[i + k] = src[k]; 25 | k++; 26 | } 27 | dest[i + k] = '\0'; 28 | return (dest); 29 | } 30 | 31 | char *ft_strcpy(char *dest, char *src) 32 | { 33 | int i; 34 | 35 | i = 0; 36 | while (src[i]) 37 | { 38 | dest[i] = src[i]; 39 | i++; 40 | } 41 | dest[i] = '\0'; 42 | return (dest); 43 | } 44 | 45 | int ft_strlen_mod(char *str, char delim) 46 | { 47 | int i; 48 | 49 | i = 0; 50 | while (str[i] && str[i] != delim) 51 | i++; 52 | return (i); 53 | } 54 | -------------------------------------------------------------------------------- /code/C11/ex00/ft_foreach.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_foreach.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/08 09:23:23 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/11 13:33:00 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | /* void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void ft_putnbr(int nb) 21 | { 22 | long int n; 23 | 24 | n = nb; 25 | if (nb < 0) 26 | { 27 | ft_putchar('-'); 28 | n = -n; 29 | } 30 | if (n < 10) 31 | ft_putchar(n + '0'); 32 | else 33 | { 34 | ft_putnbr(n / 10); 35 | ft_putchar(n % 10 + '0'); 36 | } 37 | } */ 38 | 39 | void ft_foreach(int *tab, int length, void(*f)(int)) 40 | { 41 | int i; 42 | 43 | i = 0; 44 | while (i < length) 45 | f(tab[i++]); 46 | } 47 | /* 48 | int main() 49 | { 50 | int array[] = {4, 3, 1, 7, 4, 8}; 51 | int size = 6; 52 | ft_foreach(array, size, &ft_putnbr); 53 | } */ -------------------------------------------------------------------------------- /code/C05/ex05/ft_sqrt.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sqrt.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 16:43:54 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 17:57:38 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int ft_sqrt(int nb) 18 | { 19 | int i; 20 | int res; 21 | 22 | i = 0; 23 | res = 0; 24 | while (res < nb && i <= 46430) 25 | { 26 | res = i * i; 27 | i++; 28 | } 29 | if (res > nb || nb < 0 || nb == 0 || i == 46431) 30 | return (0); 31 | return (i - 1); 32 | } 33 | /* 34 | int main(int argc, char **argv){ 35 | int n = atoi(argv[argc - 1]); 36 | int res = ft_sqrt(n); 37 | 38 | printf("Sending n = %d\n", n); 39 | if(res) 40 | printf("The square root of %d is %d\n", n, res); 41 | else 42 | printf("The square root of %d is irrational, 43 | inexistent or 0 (in case of zero)\n", n); 44 | } */ -------------------------------------------------------------------------------- /code/C11/ex02/ft_any.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_any.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/11 13:34:10 by marvin #+# #+# */ 9 | /* Updated: 2022/09/11 13:34:10 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | /* int ft_strlen(char *str) 17 | { 18 | int i = 0; 19 | 20 | while(str[i]) 21 | i++; 22 | return (i); 23 | } */ 24 | 25 | int ft_any(char ** tab, int (*f)(char *)) 26 | { 27 | int i; 28 | 29 | i = 0; 30 | if (tab == NULL || f == NULL) 31 | return (0); 32 | while (tab[i]) 33 | { 34 | if(f(tab[i])) 35 | return (1); 36 | i++; 37 | } 38 | return (0); 39 | } 40 | 41 | /* int main(int argc, char **argv) 42 | { 43 | (void)argc; 44 | 45 | if(ft_any(argv + 1, &ft_strlen)) 46 | printf("Found a non-empty string\n"); 47 | else 48 | printf("All strings are empty\n"); 49 | } */ -------------------------------------------------------------------------------- /code/C04/ex02/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putnbr.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/24 13:03:26 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 11:43:45 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putchar(char c) 18 | { 19 | write(1, &c, 1); 20 | } 21 | 22 | void ft_putnbr(int nb) 23 | { 24 | long int n; 25 | 26 | n = nb; 27 | if (n < 0) 28 | { 29 | ft_putchar('-'); 30 | n = -n; 31 | } 32 | if (n < 10) 33 | { 34 | ft_putchar(n + '0'); 35 | } 36 | else 37 | { 38 | ft_putnbr(n / 10); 39 | ft_putchar(n % 10 + '0'); 40 | } 41 | } 42 | /* 43 | int main(){ 44 | ft_putnbr(42); 45 | printf("\n"); 46 | 47 | ft_putnbr(-42); 48 | printf("\n"); 49 | 50 | ft_putnbr(0); 51 | printf("\n"); 52 | 53 | ft_putnbr(INT_MAX); 54 | printf("\n"); 55 | 56 | ft_putnbr(INT_MIN); 57 | printf("\n"); 58 | } */ -------------------------------------------------------------------------------- /code/C03/ex02/ft_strcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/22 12:04:59 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/22 19:29:37 by ncarvalh ### ########.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] != '\0') 21 | { 22 | i++; 23 | } 24 | return (i); 25 | } 26 | 27 | char *ft_strcat(char *dest, char *src) 28 | { 29 | int i; 30 | int k; 31 | 32 | k = 0; 33 | i = ft_strlen(dest); 34 | while (src[k] != '\0') 35 | { 36 | dest[i + k] = src[k]; 37 | k++; 38 | } 39 | dest[i + k] = '\0'; 40 | return (dest); 41 | } 42 | /* 43 | int main(){ 44 | char str1[15] = "Hello"; 45 | char str2[] = " World!"; 46 | 47 | printf("Sending str1 = \"%s\" and str2 = \"%s\"\n", str1, str2); 48 | ft_strcat(str1, str2); 49 | printf("Returning str1 = \"%s\" and str2 = \"%s\"\n", str1, str2); 50 | } */ -------------------------------------------------------------------------------- /code/C11/ex03/ft_count_if.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_count_if.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/13 09:31:28 by crypto #+# #+# */ 9 | /* Updated: 2022/09/13 09:43:17 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 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 | int ft_count_if(char **tab, int length, int(*f)(char *)) 27 | { 28 | int i; 29 | int count; 30 | 31 | i = 0; 32 | count = 0; 33 | if (tab == NULL || f == NULL || length == 0) 34 | return (0); 35 | while (i < length) 36 | { 37 | if (f(tab[i])) 38 | count++; 39 | i++; 40 | } 41 | return (count); 42 | } 43 | /* 44 | int main(int argc, char **argv) 45 | { 46 | printf("%d\n", ft_count_if(argv + 1, argc - 1, &ft_strlen)); 47 | } */ -------------------------------------------------------------------------------- /code/C12/ex09/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | #endif -------------------------------------------------------------------------------- /code/BSQ/srcs/ft_integer.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_integer.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 08:08:57 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 19:50:44 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../includes/ft_bsq.h" 14 | 15 | int *ft_new_array(int n) 16 | { 17 | int *array; 18 | 19 | array = (int *)malloc(n * sizeof(int)); 20 | ft_assert(array != NULL, "Allocation failed on ft_new_array()\n"); 21 | return (array); 22 | } 23 | 24 | int **ft_new_matrix(int n1, int n2) 25 | { 26 | int i; 27 | int **array; 28 | 29 | i = 0; 30 | array = (int **)malloc(n1 * sizeof(int *)); 31 | ft_assert(array != NULL, "Allocation failed on ft_new_matrix()\n"); 32 | while (i < n1) 33 | array[i++] = ft_new_array(n2); 34 | return (array); 35 | } 36 | 37 | void ft_delete_matrix(int **matrix, unsigned int n1) 38 | { 39 | unsigned int i; 40 | 41 | i = 0; 42 | while (i < n1) 43 | free(matrix[i++]); 44 | free(matrix); 45 | } 46 | -------------------------------------------------------------------------------- /code/C03/ex03/ft_strncat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/22 12:18:24 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/22 19:30:53 by ncarvalh ### ########.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] != '\0') 21 | { 22 | i++; 23 | } 24 | return (i); 25 | } 26 | 27 | char *ft_strncat(char *dest, char *src, unsigned int nb) 28 | { 29 | unsigned int i; 30 | unsigned int k; 31 | 32 | k = 0; 33 | i = ft_strlen(dest); 34 | while (src[k] != '\0' && k < nb) 35 | { 36 | dest[i + k] = src[k]; 37 | k++; 38 | } 39 | dest[i + k] = '\0'; 40 | return (dest); 41 | } 42 | /* 43 | int main(){ 44 | char str1[10] = "Hello"; 45 | char str2[] = "World!"; 46 | 47 | printf("Sending str1 = \"%s\" and str2 = \"%s\"\n", str1, str2); 48 | ft_strncat(str1, str2, 3); 49 | printf("Returning str1 = \"%s\" and str2 = \"%s\"\n", str1, str2); 50 | } */ -------------------------------------------------------------------------------- /code/C02/ex00/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 22:19:41 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:24:52 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | char *ft_strcpy(char *dest, char *src) 18 | { 19 | int i; 20 | 21 | i = 0; 22 | while (src[i] != '\0') 23 | { 24 | dest[i] = src[i]; 25 | i++; 26 | } 27 | dest[i] = '\0'; 28 | return (dest); 29 | } 30 | /* 31 | int main(){ 32 | char src[] = "Hello"; 33 | char dest1[6] = ""; 34 | char dest2[6] = ""; 35 | 36 | printf("************* TESTING WITH strcpy() *************\n\n"); 37 | printf("Sending dest1 = \"%s\"\n", dest1); 38 | printf("Returning dest1 = \"%s\"\n\n", strcpy(dest1, src)); 39 | 40 | printf("************* TESTING WITH ft_strcpy() *************\n\n"); 41 | printf("Sending dest2 = \"%s\"\n", dest2); 42 | printf("Returning dest2 = \"%s\"\n\n", ft_strcpy(dest2, src)); 43 | } */ -------------------------------------------------------------------------------- /code/C11/ex05/srcs/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 09:31:33 by crypto #+# #+# */ 9 | /* Updated: 2022/09/14 10:02:44 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_is_space(char c) 17 | { 18 | return ((c >= '\t' && c <= '\r') || c == ' '); 19 | } 20 | 21 | int ft_is_signal(char c) 22 | { 23 | return (c == '-' || c == '+'); 24 | } 25 | 26 | int ft_is_digit(char c) 27 | { 28 | return (c >= '0' && c <= '9'); 29 | } 30 | 31 | int ft_atoi(char *str) 32 | { 33 | int i; 34 | int res; 35 | int signal; 36 | 37 | i = 0; 38 | res = 0; 39 | signal = 1; 40 | while (ft_is_space(str[i])) 41 | i++; 42 | while (ft_is_signal(str[i])) 43 | { 44 | if(str[i] == '-') 45 | signal = signal * -1; 46 | i++; 47 | } 48 | while(ft_is_digit(str[i])) 49 | res = res * 10 + str[i++] - '0'; 50 | return (res * signal); 51 | } -------------------------------------------------------------------------------- /code/C12/ex10/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | #endif -------------------------------------------------------------------------------- /code/BSQ/srcs/ft_helper_2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_helper_2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 17:22:21 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 19:46:43 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../includes/ft_bsq.h" 14 | 15 | int is_digit(char c) 16 | { 17 | return (c >= '0' && c <= '9'); 18 | } 19 | 20 | int is_printable(unsigned char c) 21 | { 22 | return (c >= 32 && c <= 126); 23 | } 24 | 25 | int ft_natoi(char *number, int n) 26 | { 27 | int res; 28 | int i; 29 | 30 | i = 0; 31 | res = 0; 32 | while (is_digit(number[i]) && i < n) 33 | res = res * 10 + number[i++] - '0'; 34 | return (res); 35 | } 36 | 37 | char *ft_realloc(char *str, int size) 38 | { 39 | char *copy; 40 | 41 | copy = ft_new_str(size); 42 | ft_assert(copy != NULL, NULL); 43 | copy[size - 1] = '\0'; 44 | copy = ft_strcpy(copy, str); 45 | free(str); 46 | return (copy); 47 | } 48 | 49 | void ft_delete_map(t_map *map) 50 | { 51 | ft_delete_str_array(map->buffer, map->lines); 52 | free(map); 53 | } 54 | -------------------------------------------------------------------------------- /code/C02/ex10/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 04:50:31 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/28 18:08:34 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | unsigned int ft_strlen(char *str) 16 | { 17 | unsigned int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | i++; 22 | return (i); 23 | } 24 | 25 | unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) 26 | { 27 | unsigned int i; 28 | 29 | i = 0; 30 | if (size > 0) 31 | { 32 | while (src[i] != '\0' && i < size - 1) 33 | { 34 | dest[i] = src[i]; 35 | i++; 36 | } 37 | dest[i] = '\0'; 38 | } 39 | return (ft_strlen(src)); 40 | } 41 | 42 | /* int main() 43 | { 44 | char src[] = "Hello!"; 45 | char dest[7] = "Nuno"; 46 | int size = 0; 47 | 48 | printf("Sending src = \"%s\" and dest = \"%s\" 49 | and size = %d\n", src, dest, size); 50 | printf("Returning dest = \"%s\" (length = %d) \n" 51 | , dest, ft_strlcpy(dest, src, size)); 52 | } */ -------------------------------------------------------------------------------- /code/C02/ex11/ft_putstr_non_printable.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_putstr_non_printable.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 06:25:50 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/30 16:19:32 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_putchar(unsigned char c) 17 | { 18 | write(1, &c, 1); 19 | } 20 | 21 | int is_non_printable(unsigned char c) 22 | { 23 | return (c < 32 || c > 126); 24 | } 25 | 26 | void print_hex(unsigned char c) 27 | { 28 | char *hexbase; 29 | 30 | hexbase = "0123456789abcdef"; 31 | ft_putchar('\\'); 32 | ft_putchar(hexbase[c / 16]); 33 | ft_putchar(hexbase[c % 16]); 34 | } 35 | 36 | void ft_putstr_non_printable(char *str) 37 | { 38 | int i; 39 | 40 | i = 0; 41 | while (str[i] != '\0') 42 | { 43 | if (is_non_printable(str[i])) 44 | print_hex(str[i]); 45 | else 46 | ft_putchar(str[i]); 47 | i++; 48 | } 49 | } 50 | /* 51 | int main(){ 52 | char string[] = "Coucou\ntu vas bien ?"; 53 | 54 | ft_putstr_non_printable(string); 55 | } */ -------------------------------------------------------------------------------- /code/C00/ex05/ft_print_comb.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 14:03:12 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:44:09 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void print_three_numbers(char first, char second, char third) 21 | { 22 | ft_putchar(first); 23 | ft_putchar(second); 24 | ft_putchar(third); 25 | if (first != '7' | second != '8' | third != '9') 26 | { 27 | ft_putchar(','); 28 | ft_putchar(' '); 29 | } 30 | } 31 | 32 | void ft_print_comb(void) 33 | { 34 | char first; 35 | char second; 36 | char third; 37 | 38 | first = '0'; 39 | second = '0'; 40 | third = '0'; 41 | while (first <= '9') 42 | { 43 | second = first + 1; 44 | while (second <= '9') 45 | { 46 | third = second + 1; 47 | while (third <= '9') 48 | { 49 | print_three_numbers(first, second, third); 50 | third++; 51 | } 52 | second++; 53 | } 54 | first++; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /code/C02/ex01/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncpy.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/20 22:29:29 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 11:27:37 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | char *ft_strncpy(char *dest, char *src, unsigned int n) 18 | { 19 | unsigned int i; 20 | 21 | i = 0; 22 | while (i < n && src[i] != '\0') 23 | { 24 | dest[i] = src[i]; 25 | i++; 26 | } 27 | while (i < n) 28 | { 29 | dest[i] = '\0'; 30 | i++; 31 | } 32 | return (dest); 33 | } 34 | /* 35 | int main(){ 36 | char src[] = ""; 37 | char dest1[6] = ""; 38 | char dest2[6] = ""; 39 | int size = 3; 40 | 41 | printf("************* TESTING WITH strncpy() *************\n\n"); 42 | printf("Sending dest1 = \"%s\"\n", dest1); 43 | printf("Returning dest1 = \"%s\"\n\n", strncpy(dest1, src, size)); 44 | 45 | printf("************* TESTING WITH ft_strncpy() *************\n\n"); 46 | printf("Sending dest2 = \"%s\"\n", dest2); 47 | printf("Returning dest2 = \"%s\"\n\n", ft_strncpy(dest2, src, size)); 48 | } */ -------------------------------------------------------------------------------- /code/R01/ex00/print.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* print.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/28 16:08:58 by tlope-de #+# #+# */ 9 | /* Updated: 2022/08/28 19:31:40 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putchar(char c); 18 | 19 | void print_error(void) 20 | { 21 | write(1, "Error\n", 6); 22 | } 23 | 24 | void print_solution(char **board, int n) 25 | { 26 | int i; 27 | int k; 28 | 29 | i = 1; 30 | if (board[0][0] == '1') 31 | return ; 32 | board[0][0] = '1'; 33 | while (i <= n) 34 | { 35 | k = 1; 36 | while (k <= n) 37 | { 38 | ft_putchar(board[i][k++]); 39 | if (k != n + 1) 40 | ft_putchar(' '); 41 | } 42 | ft_putchar('\n'); 43 | i++; 44 | } 45 | } 46 | /* 47 | void print_board(char **board, int n) 48 | { 49 | int i; 50 | int k; 51 | 52 | i = 0; 53 | while (i < n + 2) 54 | { 55 | k = 0; 56 | while (k < n + 2) 57 | { 58 | ft_putchar(board[i][k++]); 59 | if (k != n + 2) 60 | ft_putchar(' '); 61 | } 62 | ft_putchar('\n'); 63 | i++; 64 | } 65 | } */ 66 | -------------------------------------------------------------------------------- /code/C11/ex01/ft_map.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_map.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/08 10:07:40 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/11 13:32:29 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | /* 16 | int ft_square(int n) 17 | { 18 | return n * n; 19 | } */ 20 | 21 | int *ft_map(int *tab, int length, int(*f)(int)) 22 | { 23 | int i; 24 | int *array; 25 | 26 | if (tab == NULL || f == NULL) 27 | return (NULL); 28 | i = 0; 29 | array = (int *)malloc(length * sizeof(int)); 30 | if (array == NULL) 31 | return (NULL); 32 | while (i < length) 33 | { 34 | array[i] = f(tab[i]); 35 | i++; 36 | } 37 | return (array); 38 | } 39 | /* 40 | void ft_print(int *array, int size) 41 | { 42 | if(array == NULL) 43 | printf("NULL ARRAY\n"); 44 | else 45 | { 46 | for(int i = 0; i < size; i++) 47 | printf("%d ", array[i]); 48 | printf("\n"); 49 | } 50 | } 51 | 52 | int main() 53 | { 54 | int array[] = {2, 3, 20, 16, 25}; 55 | int size = 0; 56 | 57 | int *new = ft_map(array, size, &ft_square); 58 | ft_print(new, size); 59 | } */ -------------------------------------------------------------------------------- /code/C00/ex08/ft_print_combn.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_combn.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 14:30:52 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/24 09:18:52 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_putchar(char c) 17 | { 18 | write(1, &c, 1); 19 | } 20 | 21 | void print_number(int digits[], int n) 22 | { 23 | int i; 24 | 25 | i = 0; 26 | while (i < n) 27 | { 28 | ft_putchar(digits[i] + '0'); 29 | i++; 30 | } 31 | if (digits[0] != 9 - n + 1) 32 | { 33 | ft_putchar(','); 34 | ft_putchar(' '); 35 | } 36 | } 37 | 38 | void ft_print_combn_recursive(int pos, int digits[], int n, int prev) 39 | { 40 | int i; 41 | 42 | if (pos == n) 43 | { 44 | return ; 45 | } 46 | i = prev + 1; 47 | while (i <= 9) 48 | { 49 | digits[pos] = i; 50 | ft_print_combn_recursive(pos + 1, digits, n, digits[pos]); 51 | if (pos == n - 1) 52 | { 53 | print_number(digits, n); 54 | } 55 | i++; 56 | } 57 | } 58 | 59 | void ft_print_combn(int n) 60 | { 61 | int digits[10]; 62 | 63 | ft_print_combn_recursive(0, digits, n, -1); 64 | } 65 | -------------------------------------------------------------------------------- /code/C12/ex11/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | #endif -------------------------------------------------------------------------------- /code/C00/ex06/ft_print_comb2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_print_comb2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/18 14:19:32 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/18 15:48:10 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c) 16 | { 17 | write(1, &c, 1); 18 | } 19 | 20 | void print_two_digit_number(int number) 21 | { 22 | if (number < 10) 23 | { 24 | ft_putchar('0'); 25 | ft_putchar(number + '0'); 26 | } 27 | else 28 | { 29 | ft_putchar(number / 10 + '0'); 30 | ft_putchar(number % 10 + '0'); 31 | } 32 | } 33 | 34 | void print_two_numbers(int first, int second) 35 | { 36 | print_two_digit_number(first); 37 | ft_putchar(' '); 38 | print_two_digit_number(second); 39 | if (first != 98 || second != 99) 40 | { 41 | ft_putchar(','); 42 | ft_putchar(' '); 43 | } 44 | } 45 | 46 | void ft_print_comb2(void) 47 | { 48 | int first; 49 | int second; 50 | 51 | first = 0; 52 | second = 0; 53 | while (first <= 99) 54 | { 55 | second = first + 1; 56 | while (second <= 99) 57 | { 58 | print_two_numbers(first, second); 59 | second++; 60 | } 61 | first++; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /code/C01/ex08/ft_sort_int_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_int_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/19 14:50:41 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/20 22:06:40 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void swap(int *a, int *b) 18 | { 19 | int aux; 20 | 21 | aux = *a; 22 | *a = *b; 23 | *b = aux; 24 | } 25 | 26 | void ft_sort_int_tab(int *tab, int size) 27 | { 28 | int min; 29 | int pos_min; 30 | int i; 31 | int k; 32 | 33 | i = 0; 34 | k = 1; 35 | pos_min = 0; 36 | while (i < size - 1) 37 | { 38 | min = tab[i]; 39 | k = i + 1; 40 | while (k < size) 41 | { 42 | if (tab[k] < min) 43 | { 44 | min = tab[k]; 45 | pos_min = k; 46 | } 47 | k++; 48 | } 49 | if (min != tab[i]) 50 | swap(&tab[pos_min], &tab[i]); 51 | i++; 52 | } 53 | } 54 | 55 | /* void print_array(int array[], int size){ 56 | for(int i = 0; i < size; i++){ 57 | printf("%d ", array[i]); 58 | } 59 | printf("\n"); 60 | } 61 | 62 | int main(){ 63 | int array[] = {1, -1, 0}; 64 | int size = 3; 65 | 66 | ft_sort_int_tab(array, size); 67 | print_array(array, size); 68 | } */ -------------------------------------------------------------------------------- /code/C12/ex12/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | #endif -------------------------------------------------------------------------------- /code/C03/ex05/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strlcat.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/22 14:17:20 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/23 12:56:26 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | unsigned int ft_strlen(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | i++; 24 | } 25 | return (i); 26 | } 27 | 28 | unsigned int ft_strlcat(char *dest, char *src, unsigned int size) 29 | { 30 | unsigned int dest_len; 31 | unsigned int src_len; 32 | unsigned int k; 33 | 34 | k = 0; 35 | dest_len = ft_strlen(dest); 36 | src_len = ft_strlen(src); 37 | if (dest_len >= size) 38 | return (size + ft_strlen(src)); 39 | while (src[k] != '\0' && k < size - dest_len - 1) 40 | { 41 | dest[dest_len + k] = src[k]; 42 | k++; 43 | } 44 | dest[dest_len + k] = '\0'; 45 | return (dest_len + src_len); 46 | } 47 | /* 48 | int main(){ 49 | char dest[10] = "Hello"; 50 | char src[] = "World"; 51 | 52 | printf("Sending str1 = \"%s\" and str2 = \"%s\"\n", dest, src); 53 | int res = ft_strlcat(dest, src, 10); 54 | printf("Returning str1 = \"%s\" 55 | (attempted length = %d) and str2 = \"%s\"\n", dest, res, src); 56 | } */ -------------------------------------------------------------------------------- /code/C06/ex03/ft_sort_params.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_params.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/29 15:36:07 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/30 11:38:01 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | write(1, &str[i++], 1); 22 | } 23 | 24 | int ft_strcmp(char *s1, char *s2) 25 | { 26 | int i; 27 | 28 | i = 0; 29 | while (s1[i] == s2[i] && s1[i] != '\0') 30 | i++; 31 | return (s1[i] - s2[i]); 32 | } 33 | 34 | void print_params(int argc, char **argv) 35 | { 36 | int i; 37 | 38 | i = 1; 39 | while (i < argc) 40 | { 41 | ft_putstr(argv[i++]); 42 | write(1, "\n", 1); 43 | } 44 | } 45 | 46 | void sort_params(int argc, char **argv) 47 | { 48 | int i; 49 | char *str; 50 | 51 | i = 1; 52 | while (i < argc - 1) 53 | { 54 | if (ft_strcmp(argv[i], argv[i + 1]) > 0) 55 | { 56 | str = argv[i]; 57 | argv[i] = argv[i + 1]; 58 | argv[i + 1] = str; 59 | i = 1; 60 | } 61 | else 62 | i++; 63 | } 64 | } 65 | 66 | int main(int argc, char **argv) 67 | { 68 | if (argc <= 0) 69 | return (0); 70 | sort_params(argc, argv); 71 | print_params(argc, argv); 72 | return (argc); 73 | } 74 | -------------------------------------------------------------------------------- /code/C04/ex03/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/24 13:07:07 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/14 09:36:16 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int ft_is_space(char c) 18 | { 19 | return (c == ' ' || c == '\f' 20 | || c == '\n' || c == '\r' 21 | || c == '\t' || c == '\v'); 22 | } 23 | 24 | int is_signal(char c) 25 | { 26 | return (c == '-' || c == '+'); 27 | } 28 | 29 | int is_number(char c) 30 | { 31 | return (c >= '0' && c <= '9'); 32 | } 33 | 34 | int ft_atoi(char *str) 35 | { 36 | int i; 37 | int is_negative; 38 | int number; 39 | 40 | i = 0; 41 | number = 0; 42 | is_negative = 0; 43 | while (ft_is_space(str[i])) 44 | i++; 45 | while (is_signal(str[i])) 46 | { 47 | if (str[i++] == '-') 48 | is_negative = !is_negative; 49 | } 50 | while (is_number(str[i]) && str[i] != '\0') 51 | number = 10 * number + str[i++] - '0'; 52 | if (is_negative) 53 | return (-number); 54 | return (number); 55 | } 56 | 57 | /* int main() 58 | { 59 | char string[] = " \f\n\r\t\v-+-1234"; 60 | 61 | printf("Sending string = \"%s\"\n", string); 62 | printf("Returning %d\n", ft_atoi(string)); 63 | } */ 64 | -------------------------------------------------------------------------------- /code/C11/ex06/ft_sort_string_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_sort_string_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/15 08:30:19 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 08:40:59 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int ft_strcmp(char *s1, char *s2) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (s1[i] == s2[i] && s1[i]) 22 | i++; 23 | return (s1[i] - s2[i]); 24 | } 25 | 26 | void ft_sort_string_tab(char **tab) 27 | { 28 | int i; 29 | char *aux; 30 | 31 | if (tab == NULL || tab[0] == NULL) 32 | return ; 33 | i = 0; 34 | while (tab[i + 1] != NULL) 35 | { 36 | if (ft_strcmp(tab[i], tab[i + 1]) > 0) 37 | { 38 | aux = tab[i]; 39 | tab[i] = tab[i + 1]; 40 | tab[i + 1] = aux; 41 | i = 0; 42 | } 43 | else 44 | i++; 45 | } 46 | } 47 | /* 48 | void ft_print(char **argv) 49 | { 50 | for(int i = 0; argv[i] != NULL; i++) 51 | printf("%s\n", argv[i]); 52 | } 53 | 54 | int main(int argc, char **argv) 55 | { 56 | (void)argc; 57 | ft_print(argv); 58 | ft_sort_string_tab(argv); 59 | printf("----------------------------\n"); 60 | ft_print(argv); 61 | } */ -------------------------------------------------------------------------------- /code/C03/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/22 11:31:55 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/23 13:03:23 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | //#include 14 | //#include 15 | 16 | int ft_strcmp(char *s1, char *s2) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (s1[i] == s2[i] && s1[i] != '\0') 22 | { 23 | i++; 24 | } 25 | return (s1[i] - s2[i]); 26 | } 27 | /* 28 | int main() 29 | { 30 | char str1[] = "abd"; 31 | char str2[] = "abcd"; 32 | 33 | int res = strcmp(str1, str2); 34 | printf("************** USING STRCMP **************\n\n"); 35 | 36 | if(res < 0) 37 | printf("The string of \"%s\" is less than \"%s\"\n", str1, str2); 38 | else if(res > 0) 39 | printf("The string of \"%s\" is greater than \"%s\"\n", str1, str2); 40 | else 41 | printf("The string of \"%s\" and \"%s\" are the same\n", str1, str2); 42 | 43 | res = ft_strcmp(str1, str2); 44 | printf("************** USING FT_STRCMP **************\n\n"); 45 | 46 | if(res < 0) 47 | printf("The string of \"%s\" is less than \"%s\"\n", str1, str2); 48 | else if(res > 0) 49 | printf("The string of \"%s\" is greater than \"%s\"\n", str1, str2); 50 | else 51 | printf("The string of \"%s\" and \"%s\" are the same\n", str1, str2); 52 | } */ -------------------------------------------------------------------------------- /code/C12/ex01/ft_list_push_front.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_front.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:05:07 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:05:07 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | void ft_list_push_front(t_list **begin_list, void *data) 18 | { 19 | t_list *node; 20 | 21 | if (!begin_list) 22 | return ; 23 | node = ft_create_elem(data); 24 | if (!node) 25 | return ; 26 | if (*begin_list) 27 | node->next = *begin_list; 28 | *begin_list = node; 29 | } 30 | /* 31 | t_list *ft_create_elem(void *data) 32 | { 33 | t_list *elem; 34 | 35 | elem = malloc(sizeof(t_list)); 36 | if (!elem) 37 | return (NULL); 38 | elem->data = data; 39 | elem->next = NULL; 40 | return (elem); 41 | } 42 | 43 | void ft_list_print(t_list *list) 44 | { 45 | t_list *aux; 46 | 47 | while (list) 48 | { 49 | aux = list; 50 | printf("%s->", aux->data); 51 | list = list->next; 52 | free(aux); 53 | } 54 | printf("NULL\n"); 55 | } 56 | 57 | int main(int argc, char **argv) 58 | { 59 | t_list *list; 60 | 61 | list = NULL; 62 | for (int i = 1; i < argc; i++) 63 | ft_list_push_front(&list, argv[i]); 64 | ft_list_print(list); 65 | } 66 | */ 67 | -------------------------------------------------------------------------------- /code/C12/ex13/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | void ft_list_remove_if(t_list **begin_list, void *data_ref, \ 48 | int (*cmp)(), void (*free_fct)(void *)); 49 | 50 | #endif -------------------------------------------------------------------------------- /code/C11/ex07/ft_advanced_sort_string_tab.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_advanced_sort_string_tab.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/15 08:40:42 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 08:44:01 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | /* 16 | int ft_strcmp(char *s1, char *s2) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (s1[i] == s2[i] && s1[i]) 22 | i++; 23 | return (s1[i] - s2[i]); 24 | } */ 25 | 26 | void ft_advanced_sort_string_tab(char **tab, int(*cmp)(char *, char *)) 27 | { 28 | int i; 29 | char *aux; 30 | 31 | if (tab == NULL || tab[0] == NULL) 32 | return ; 33 | i = 0; 34 | while (tab[i + 1] != NULL) 35 | { 36 | if (cmp(tab[i], tab[i + 1]) > 0) 37 | { 38 | aux = tab[i]; 39 | tab[i] = tab[i + 1]; 40 | tab[i + 1] = aux; 41 | i = 0; 42 | } 43 | else 44 | i++; 45 | } 46 | } 47 | /* 48 | void ft_print(char **argv) 49 | { 50 | for(int i = 0; argv[i] != NULL; i++) 51 | printf("%s\n", argv[i]); 52 | } 53 | 54 | int main(int argc, char **argv) 55 | { 56 | (void)argc; 57 | ft_print(argv); 58 | ft_advanced_sort_string_tab(argv, &ft_strcmp); 59 | printf("----------------------------\n"); 60 | ft_print(argv); 61 | } */ -------------------------------------------------------------------------------- /code/C11/ex05/main.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* main.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: crypto +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/14 09:30:11 by crypto #+# #+# */ 9 | /* Updated: 2022/09/15 00:17:22 by crypto ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include "do_op.h" 16 | 17 | //NEED TO CHANGE THIS SINCE IT MUST RECEIVE A STRING 18 | int ft_is_valid(char *str) 19 | { 20 | if(ft_strlen(str) != 1) 21 | return (0); 22 | return (str[0] == '+' || str[0] == '-' || str[0] == '*' 23 | || str[0] == '%' || str[0] == '/'); 24 | } 25 | 26 | int ft_valid_args(char **argv, int *n1, int *n2) 27 | { 28 | if (!ft_is_valid(argv[2])) 29 | return (-1); 30 | *n1 = ft_atoi(argv[1]); 31 | *n2 = ft_atoi(argv[3]); 32 | if(argv[2][0] == '+') 33 | return ADD; 34 | else if(argv[2][0] == '-') 35 | return SUB; 36 | else if(argv[2][0] == '*') 37 | return MULT; 38 | else if(argv[2][0] == '/') 39 | return DIV; 40 | else 41 | return MOD; 42 | } 43 | 44 | int main(int argc, char **argv) 45 | { 46 | int n1; 47 | int n2; 48 | int op; 49 | 50 | if(argc == 4) 51 | { 52 | op = ft_valid_args(argv, &n1, &n2); 53 | if (op != -1) 54 | do_op(n1, n2, op); 55 | else 56 | ft_putchar('0'); 57 | } 58 | return (0); 59 | } -------------------------------------------------------------------------------- /code/C02/ex09/ft_strcapitalize.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcapitalize.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 04:04:38 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/01 16:38:20 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | void ft_toupper(char *c) 17 | { 18 | if (*c >= 'a' && *c <= 'z') 19 | *c += 'A' - 'a'; 20 | } 21 | 22 | void ft_tolower(char *c) 23 | { 24 | if (*c >= 'A' && *c <= 'Z') 25 | *c -= 'A' - 'a'; 26 | } 27 | 28 | int ft_is_alphanumeric(char *c) 29 | { 30 | return ((*c >= 'a' && *c <= 'z') 31 | || (*c >= 'A' && *c <= 'Z') 32 | || (*c >= '0' && *c <= '9')); 33 | } 34 | 35 | char *ft_strcapitalize(char *str) 36 | { 37 | int i; 38 | int is_capitalized; 39 | 40 | i = 0; 41 | is_capitalized = 0; 42 | while (str[i] != '\0') 43 | { 44 | if (is_capitalized && ft_is_alphanumeric(&str[i])) 45 | ft_tolower(&str[i]); 46 | else if (!is_capitalized && ft_is_alphanumeric(&str[i])) 47 | { 48 | ft_toupper(&str[i]); 49 | is_capitalized = 1; 50 | } 51 | else if (!ft_is_alphanumeric(&str[i])) 52 | is_capitalized = 0; 53 | i++; 54 | } 55 | return (str); 56 | } 57 | /* 58 | int main(){ 59 | char string[] = "salut, comment tu vas ? 42mots quarante-deux; cinquante+et+un"; 60 | 61 | printf("Before: %s\n", string); 62 | printf("After: %s\n", ft_strcapitalize(string)); 63 | } */ 64 | -------------------------------------------------------------------------------- /code/C07/ex00/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/30 10:25:39 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/05 10:06:49 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | int ft_strlen(char *str) 18 | { 19 | int i; 20 | 21 | i = 0; 22 | while (str[i] != '\0') 23 | i++; 24 | return (i); 25 | } 26 | 27 | void ft_strcpy(char *dest, char *src) 28 | { 29 | int i; 30 | 31 | i = 0; 32 | while (src[i] != '\0') 33 | { 34 | dest[i] = src[i]; 35 | i++; 36 | } 37 | dest[i] = '\0'; 38 | } 39 | 40 | char *ft_strdup(char *src) 41 | { 42 | int n; 43 | char *dest; 44 | 45 | n = ft_strlen(src); 46 | dest = (char *)malloc((n + 1) * sizeof(char)); 47 | if (dest == NULL) 48 | return (NULL); 49 | ft_strcpy(dest, src); 50 | return (dest); 51 | } 52 | /* 53 | int main(int argc, char **argv) 54 | { 55 | if(argc != 2) 56 | return (0); 57 | printf("*************** TESTING WITH strdup() ***************\n\n"); 58 | 59 | printf("Sending src = \"%s\"\n", argv[1]); 60 | printf("Returning \"%s\"\n\n", strdup(argv[1])); 61 | 62 | printf("*************** TESTING WITH ft_strdup() ***************\n\n"); 63 | 64 | printf("Sending src = \"%s\"\n", argv[1]); 65 | printf("Returning \"%s\"\n\n", ft_strdup(argv[1])); 66 | 67 | return (0); 68 | } */ -------------------------------------------------------------------------------- /code/C07/ex01/ft_range.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_range.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/30 10:49:36 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/05 10:16:02 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | 16 | int get_range(int min, int max) 17 | { 18 | if (max < 0 && min > 0) 19 | return (min - max); 20 | else 21 | return (max - min); 22 | } 23 | 24 | void fill_array(int *array, int range, int min) 25 | { 26 | int i; 27 | 28 | i = 0; 29 | while (i < range) 30 | { 31 | array[i] = min + i; 32 | i++; 33 | } 34 | } 35 | 36 | int *ft_range(int min, int max) 37 | { 38 | int *array; 39 | int n; 40 | 41 | if (min >= max) 42 | return (NULL); 43 | n = get_range(min, max); 44 | array = (int *)malloc(n * sizeof(int)); 45 | if (array == NULL) 46 | return (NULL); 47 | fill_array(array, n, min); 48 | return (array); 49 | } 50 | /* 51 | void print_array(int *array, int n) 52 | { 53 | int i; 54 | 55 | i = 0; 56 | while (i < n) 57 | printf("%d ", array[i++]); 58 | printf("\n"); 59 | } 60 | 61 | int main(int argc, char **argv) 62 | { 63 | if(argc != 3) 64 | return (0); 65 | 66 | int min = atoi(argv[argc - 2]); 67 | int max = atoi(argv[argc - 1]); 68 | int *array = ft_range(min, max); 69 | 70 | if(!array) 71 | printf("Min >= Max (%d >= %d)\n", min, max); 72 | else 73 | print_array(array, max - min); 74 | } */ -------------------------------------------------------------------------------- /code/R00/ex00/rush00.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush00.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: maricard +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 13:18:24 by maricard #+# #+# */ 9 | /* Updated: 2022/08/21 13:28:27 by maricard ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c); 16 | 17 | void ft_first_line(int x) 18 | { 19 | int x_contador; 20 | 21 | x_contador = 0; 22 | ft_putchar('o'); 23 | while (x_contador < x - 2) 24 | { 25 | ft_putchar('-'); 26 | x_contador++; 27 | } 28 | if (x > 1) 29 | { 30 | ft_putchar('o'); 31 | } 32 | ft_putchar('\n'); 33 | } 34 | 35 | void ft_second_line(int x, int y) 36 | { 37 | int k; 38 | int i; 39 | 40 | i = 0; 41 | k = 0; 42 | while (i < y - 2) 43 | { 44 | ft_putchar('|'); 45 | k = 0; 46 | while (k < x - 2) 47 | { 48 | ft_putchar(' '); 49 | k++; 50 | } 51 | if (x > 1) 52 | { 53 | ft_putchar('|'); 54 | } 55 | i++; 56 | ft_putchar('\n'); 57 | } 58 | } 59 | 60 | void ft_last_line(int x, int y) 61 | { 62 | int x_contador; 63 | 64 | x_contador = 0; 65 | if (y > 1) 66 | { 67 | ft_putchar('o'); 68 | while (x_contador < x - 2) 69 | { 70 | ft_putchar('-'); 71 | x_contador++; 72 | } 73 | if (x > 1) 74 | { 75 | ft_putchar('o'); 76 | } 77 | ft_putchar('\n'); 78 | } 79 | } 80 | 81 | void rush(int x, int y) 82 | { 83 | ft_first_line(x); 84 | ft_second_line(x, y); 85 | ft_last_line(x, y); 86 | } 87 | -------------------------------------------------------------------------------- /code/R00/ex00/rush02.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush02.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: maricard +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/21 12:51:23 by maricard #+# #+# */ 9 | /* Updated: 2022/08/21 15:54:44 by maricard ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | void ft_putchar(char c); 16 | 17 | void ft_first_line(int x) 18 | { 19 | int x_contador; 20 | 21 | x_contador = 0; 22 | ft_putchar('A'); 23 | while (x_contador < x - 2) 24 | { 25 | ft_putchar('B'); 26 | x_contador++; 27 | } 28 | if (x > 1) 29 | { 30 | ft_putchar('A'); 31 | } 32 | ft_putchar('\n'); 33 | } 34 | 35 | void ft_second_line(int x, int y) 36 | { 37 | int k; 38 | int i; 39 | 40 | i = 0; 41 | k = 0; 42 | while (i < y - 2) 43 | { 44 | ft_putchar('B'); 45 | k = 0; 46 | while (k < x - 2) 47 | { 48 | ft_putchar(' '); 49 | k++; 50 | } 51 | if (x > 1) 52 | { 53 | ft_putchar('B'); 54 | } 55 | i++; 56 | ft_putchar('\n'); 57 | } 58 | } 59 | 60 | void ft_last_line(int x, int y) 61 | { 62 | int x_contador; 63 | 64 | x_contador = 0; 65 | if (y > 1) 66 | { 67 | ft_putchar('C'); 68 | while (x_contador < x - 2) 69 | { 70 | ft_putchar('B'); 71 | x_contador++; 72 | } 73 | if (x > 1) 74 | { 75 | ft_putchar('C'); 76 | } 77 | ft_putchar('\n'); 78 | } 79 | } 80 | 81 | void rush(int x, int y) 82 | { 83 | ft_first_line(x); 84 | ft_second_line(x, y); 85 | ft_last_line(x, y); 86 | } 87 | -------------------------------------------------------------------------------- /code/C12/ex14/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | void ft_list_remove_if(t_list **begin_list, void *data_ref, \ 48 | int (*cmp)(), void (*free_fct)(void *)); 49 | 50 | void ft_list_merge(t_list **begin_list1, t_list *begin_list2); 51 | 52 | #endif -------------------------------------------------------------------------------- /code/BSQ/srcs/ft_string_1.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_string_1.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/06 15:08:55 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/07 19:49:39 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "../includes/ft_bsq.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 | char *ft_new_str(int n) 26 | { 27 | char *str; 28 | 29 | str = (char *)malloc(n * sizeof(char)); 30 | ft_assert(str != NULL, "Allocation failed on ft_new_str()\n"); 31 | return (str); 32 | } 33 | 34 | char **ft_new_str_array(unsigned int n1, unsigned int n2) 35 | { 36 | unsigned int i; 37 | char **array; 38 | 39 | i = 0; 40 | array = (char **)malloc(n1 * sizeof(char *)); 41 | ft_assert(array != NULL, "Allocation failed on ft_new_str_array()\n"); 42 | while (i < n1) 43 | array[i++] = ft_new_str(n2); 44 | return (array); 45 | } 46 | 47 | void ft_delete_str_array(char **matrix, unsigned int n1) 48 | { 49 | unsigned int i; 50 | 51 | i = 0; 52 | while (i < n1) 53 | free(matrix[i++]); 54 | free(matrix); 55 | } 56 | 57 | void ft_print_str_array(char **matrix, unsigned int n1, unsigned int n2) 58 | { 59 | unsigned int i; 60 | unsigned int k; 61 | 62 | i = 0; 63 | k = 0; 64 | while (i < n1) 65 | { 66 | k = 0; 67 | while (k < n2) 68 | { 69 | ft_putchar(matrix[i][k]); 70 | k++; 71 | } 72 | ft_putchar('\n'); 73 | i++; 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /code/C12/ex15/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | void ft_list_remove_if(t_list **begin_list, void *data_ref, \ 48 | int (*cmp)(), void (*free_fct)(void *)); 49 | 50 | void ft_list_merge(t_list **begin_list1, t_list *begin_list2); 51 | 52 | void ft_list_sort(t_list **begin_list, int (*cmp)()); 53 | 54 | #endif -------------------------------------------------------------------------------- /code/R02/ex00/state.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* state.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/09/03 23:18:24 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/09/03 23:18:35 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "rush.h" 14 | 15 | t_state read_number_handler(unsigned char c, int *res) 16 | { 17 | if (is_digit(c)) 18 | *res = *res * 10 + c - '0'; 19 | else if (c == ' ') 20 | return (READ_SPACES1); 21 | else 22 | return (ERROR); 23 | return (READ_NUMBER); 24 | } 25 | 26 | t_state read_spaces1_handler(unsigned char c) 27 | { 28 | if (c == ':') 29 | return (READ_SPACES2); 30 | else if (c == ' ') 31 | return (READ_SPACES1); 32 | return (ERROR); 33 | } 34 | 35 | t_state read_spaces2_handler(unsigned char c) 36 | { 37 | if (c == ' ') 38 | return (READ_SPACES2); 39 | else if(!is_printable(c)) 40 | return (READ_CHARS); 41 | return (ERROR); 42 | } 43 | 44 | t_state read_chars_handler(unsigned char c, int *res) 45 | { 46 | if(is_printable(c)) 47 | return (READ_CHARS); 48 | else if (c == '\0') 49 | return (END); 50 | return (ERROR); 51 | } 52 | 53 | t_state multiplexer(unsigned char c, int *res, t_state state, t_pair** dict) 54 | { 55 | if(state == READ_NUMBER) 56 | return (read_number_handler(c, res)); 57 | else if(state == READ_SPACES1) 58 | return (read_spaces1_handler(c, res)); 59 | else if(state == READ_SPACES2) 60 | return (read_spaces2_handler(c, res)); 61 | else if(state == READ_CHARS) 62 | return (read_chars_handler(c, res, dict)); 63 | return (ERROR); 64 | } -------------------------------------------------------------------------------- /code/C03/ex01/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strncmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/22 11:40:31 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/23 17:03:51 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | //#include 14 | //#include 15 | 16 | int ft_strncmp(char *s1, char *s2, unsigned int n) 17 | { 18 | unsigned int i; 19 | 20 | i = 0; 21 | while (s1[i] == s2[i] && s1[i] != '\0') 22 | { 23 | i++; 24 | } 25 | if (i >= n) 26 | return (0); 27 | return (s1[i] - s2[i]); 28 | } 29 | /* 30 | int main() 31 | { 32 | int size = 1; 33 | char str1[] = "abc"; 34 | char str2[] = "ab"; 35 | 36 | printf("************** USING STRNCMP **************\n\n"); 37 | int res = strncmp(str1, str2, size); 38 | if(res < 0) 39 | printf("The first %d bytes of \"%s\" 40 | are less than \"%s\"\n", size, str1, str2); 41 | else if(res > 0) 42 | printf("The first %d bytes of \"%s\" 43 | are greater than \"%s\"\n", size, str1, str2); 44 | else 45 | printf("The first %d bytes of \"%s\" 46 | and \"%s\" are the same\n", size, str1, str2); 47 | 48 | printf("************** USING FT_STRNCMP **************\n\n"); 49 | res = ft_strncmp(str1, str2, size); 50 | if(res < 0) 51 | printf("The first %d bytes of \"%s\" 52 | are less than \"%s\"\n", size, str1, str2); 53 | else if(res > 0) 54 | printf("The first %d bytes of \"%s\" 55 | are greater than \"%s\"\n", size, str1, str2); 56 | else 57 | printf("The first %d bytes of \"%s\" 58 | and \"%s\" are the same\n", size, str1, str2); 59 | } */ -------------------------------------------------------------------------------- /code/C12/ex05/ft_list_push_strs.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_strs.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:30:48 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:30:48 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | void ft_list_push_front(t_list **begin_list, void *data) 18 | { 19 | t_list *node; 20 | 21 | if (!begin_list) 22 | return ; 23 | node = ft_create_elem(data); 24 | if (!node) 25 | return ; 26 | if (*begin_list) 27 | node->next = *begin_list; 28 | *begin_list = node; 29 | } 30 | 31 | t_list *ft_list_push_strs(int size, char **strs) 32 | { 33 | int i; 34 | t_list *list; 35 | 36 | i = 0; 37 | list = NULL; 38 | while (i < size) 39 | ft_list_push_front(&list, strs[i++]); 40 | return (list); 41 | } 42 | /* 43 | 44 | t_list *ft_create_elem(void *data) 45 | { 46 | t_list *elem; 47 | 48 | elem = malloc(sizeof(t_list)); 49 | if (!elem) 50 | return (NULL); 51 | elem->data = data; 52 | elem->next = NULL; 53 | return (elem); 54 | } 55 | 56 | void ft_list_print(t_list *list) 57 | { 58 | t_list *aux; 59 | 60 | while (list) 61 | { 62 | aux = list; 63 | printf("%s->", aux->data); 64 | list = list->next; 65 | free(aux); 66 | } 67 | printf("NULL\n"); 68 | } 69 | 70 | int main(int argc, char **argv) 71 | { 72 | t_list *list; 73 | 74 | list = ft_list_push_strs(argc - 1, argv + 1); 75 | ft_list_print(list); 76 | } 77 | */ 78 | -------------------------------------------------------------------------------- /code/C12/ex16/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | void ft_list_remove_if(t_list **begin_list, void *data_ref, \ 48 | int (*cmp)(), void (*free_fct)(void *)); 49 | 50 | void ft_list_merge(t_list **begin_list1, t_list *begin_list2); 51 | 52 | void ft_list_sort(t_list **begin_list, int (*cmp)()); 53 | 54 | void ft_list_reverse_fun(t_list *begin_list); 55 | 56 | #endif -------------------------------------------------------------------------------- /code/C12/ex04/ft_list_push_back.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_push_back.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:24:17 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:24:17 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | t_list *ft_list_last(t_list *begin_list) 18 | { 19 | if (!begin_list) 20 | return (NULL); 21 | while (begin_list->next) 22 | begin_list = begin_list->next; 23 | return (begin_list); 24 | } 25 | 26 | void ft_list_push_back(t_list **begin_list, void *data) 27 | { 28 | t_list *node; 29 | 30 | if (!begin_list) 31 | return ; 32 | node = ft_create_elem(data); 33 | if (!node) 34 | return; 35 | if (!(*begin_list)) 36 | *begin_list = node; 37 | else 38 | ft_list_last(*begin_list)->next = node; 39 | } 40 | /* 41 | 42 | t_list *ft_create_elem(void *data) 43 | { 44 | t_list *elem; 45 | 46 | elem = malloc(sizeof(t_list)); 47 | if (!elem) 48 | return (NULL); 49 | elem->data = data; 50 | elem->next = NULL; 51 | return (elem); 52 | } 53 | 54 | void ft_list_print(t_list *list) 55 | { 56 | t_list *aux; 57 | 58 | while (list) 59 | { 60 | aux = list; 61 | printf("%s->", aux->data); 62 | list = list->next; 63 | free(aux); 64 | } 65 | printf("NULL\n"); 66 | } 67 | 68 | int main(int argc, char **argv) 69 | { 70 | t_list *list; 71 | 72 | list = NULL; 73 | for (int i = 1; i < argc; i++) 74 | ft_list_push_back(&list, argv[i]); 75 | ft_list_print(list); 76 | } 77 | */ -------------------------------------------------------------------------------- /code/C05/ex08/ft_ten_queens_puzzle.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_ten_queens_puzzle.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/25 20:27:17 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/29 13:03:38 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | void ft_putchar(char c) 18 | { 19 | write(1, &c, 1); 20 | } 21 | 22 | void print_solution(int *solution) 23 | { 24 | int i; 25 | 26 | i = 0; 27 | while (i < 10) 28 | ft_putchar(solution[i++] + '0'); 29 | ft_putchar('\n'); 30 | } 31 | 32 | int can_attack(int *pos, int q) 33 | { 34 | int x; 35 | 36 | x = 0; 37 | while (x < q) 38 | { 39 | if (pos[x] == pos[q] && x != q) 40 | return (1); 41 | if (x != q) 42 | { 43 | if (pos[x] == pos[q] - (q - x) 44 | || pos[x] == pos[q] + (q - x)) 45 | return (1); 46 | } 47 | x++; 48 | } 49 | return (0); 50 | } 51 | 52 | void ft_ten_queens_puzzle_recursive(int positions[], int pos, int *sols) 53 | { 54 | int i; 55 | 56 | i = 0; 57 | if (pos == 10) 58 | { 59 | print_solution(positions); 60 | (*sols)++; 61 | } 62 | else 63 | { 64 | while (i <= 9) 65 | { 66 | positions[pos] = i; 67 | if (!can_attack(positions, pos)) 68 | ft_ten_queens_puzzle_recursive(positions, pos + 1, sols); 69 | i++; 70 | } 71 | } 72 | } 73 | 74 | int ft_ten_queens_puzzle(void) 75 | { 76 | int positions[10]; 77 | int sols; 78 | 79 | sols = 0; 80 | ft_ten_queens_puzzle_recursive(positions, 0, &sols); 81 | return (sols); 82 | } 83 | /* 84 | int main() 85 | { 86 | return ft_ten_queens_puzzle(); 87 | } */ -------------------------------------------------------------------------------- /code/R01/ex00/conditions.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* conditions.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: ncarvalh +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2022/08/28 19:29:42 by ncarvalh #+# #+# */ 9 | /* Updated: 2022/08/28 19:58:35 by ncarvalh ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | char **new_matrix(int n1, int n2); 18 | 19 | int ft_strlen(char *str) 20 | { 21 | int i; 22 | 23 | i = 0; 24 | while (str[i] != '\0') 25 | i++; 26 | return (i); 27 | } 28 | 29 | int test_dimensions(int n, int max, char *str) 30 | { 31 | return (n % 4 == 0 && n / 4 >= max 32 | && n / 4 <= 9 && 8 * (n / 4) - 1 == ft_strlen(str)); 33 | } 34 | 35 | int verify_params(int n, char **argv) 36 | { 37 | int i; 38 | int counter; 39 | char max; 40 | 41 | i = 0; 42 | max = '1'; 43 | counter = 0; 44 | while (argv[n - 1][i] != '\0') 45 | { 46 | if (argv[n - 1][i] >= '1' && argv[n - 1][i] <= '9' && i % 2 == 0) 47 | { 48 | counter++; 49 | if (argv[n - 1][i] > max) 50 | max = argv[n - 1][i]; 51 | } 52 | else if (argv[n - 1][i] != ' ') 53 | return (0); 54 | i++; 55 | } 56 | if (test_dimensions(counter, max - '0', argv[1])) 57 | return (counter / 4); 58 | return (0); 59 | } 60 | 61 | char **create_conds(int n, char *str) 62 | { 63 | char **conds; 64 | int i; 65 | int k; 66 | 67 | i = 0; 68 | k = 0; 69 | conds = new_matrix(4, n); 70 | while (k < n) 71 | { 72 | conds[0][k] = str[i]; 73 | conds[1][k] = str[i + 2 * n]; 74 | conds[2][k] = str[i + 4 * n]; 75 | conds[3][k++] = str[i + 6 * n]; 76 | i += 2; 77 | } 78 | return (conds); 79 | } 80 | -------------------------------------------------------------------------------- /code/C12/ex06/ft_list_clear.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_clear.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:39:16 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:39:16 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)) 18 | { 19 | t_list *aux; 20 | 21 | while (begin_list) 22 | { 23 | aux = begin_list; 24 | begin_list = begin_list->next; 25 | if (*free_fct) 26 | (*free_fct)(aux->data); 27 | free(aux); 28 | } 29 | } 30 | /* 31 | void ft_list_push_front(t_list **begin_list, void *data) 32 | { 33 | t_list *node; 34 | 35 | if (!begin_list) 36 | return ; 37 | node = ft_create_elem(data); 38 | if (!node) 39 | return ; 40 | if (*begin_list) 41 | node->next = *begin_list; 42 | *begin_list = node; 43 | } 44 | 45 | t_list *ft_create_elem(void *data) 46 | { 47 | t_list *elem; 48 | 49 | elem = malloc(sizeof(t_list)); 50 | if (!elem) 51 | return (NULL); 52 | elem->data = data; 53 | elem->next = NULL; 54 | return (elem); 55 | } 56 | 57 | void ft_list_print(t_list *list) 58 | { 59 | while (list) 60 | { 61 | printf("%s->", list->data); 62 | list = list->next; 63 | } 64 | printf("NULL\n"); 65 | } 66 | 67 | int main(int argc, char **argv) 68 | { 69 | t_list *list; 70 | 71 | list = NULL; 72 | for (int i = 1; i < argc; i++) 73 | ft_list_push_front(&list, argv[i]); 74 | ft_list_print(list); 75 | ft_list_clear(list, NULL); 76 | } 77 | */ -------------------------------------------------------------------------------- /code/C12/ex02/ft_list_size.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_size.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:15:45 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:15:45 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | int ft_list_size(t_list *begin_list) 18 | { 19 | int size; 20 | 21 | size = 0; 22 | while (begin_list) 23 | { 24 | size++; 25 | begin_list = begin_list->next; 26 | } 27 | return (size); 28 | } 29 | /* 30 | void ft_list_push_front(t_list **begin_list, void *data) 31 | { 32 | t_list *node; 33 | 34 | if (!begin_list) 35 | return ; 36 | node = ft_create_elem(data); 37 | if (!node) 38 | return ; 39 | if (*begin_list) 40 | node->next = *begin_list; 41 | *begin_list = node; 42 | } 43 | 44 | t_list *ft_create_elem(void *data) 45 | { 46 | t_list *elem; 47 | 48 | elem = malloc(sizeof(t_list)); 49 | if (!elem) 50 | return (NULL); 51 | elem->data = data; 52 | elem->next = NULL; 53 | return (elem); 54 | } 55 | 56 | void ft_list_print(t_list *list) 57 | { 58 | t_list *aux; 59 | 60 | while (list) 61 | { 62 | aux = list; 63 | printf("%s->", aux->data); 64 | list = list->next; 65 | free(aux); 66 | } 67 | printf("NULL\n"); 68 | } 69 | 70 | int main(int argc, char **argv) 71 | { 72 | t_list *list; 73 | 74 | list = NULL; 75 | for (int i = 1; i < argc; i++) 76 | ft_list_push_front(&list, argv[i]); 77 | printf("List size %d\n", ft_list_size(list)); 78 | ft_list_print(list); 79 | } 80 | */ -------------------------------------------------------------------------------- /code/C12/ex03/ft_list_last.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_last.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:19:41 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:19:41 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | t_list *ft_list_last(t_list *begin_list) 18 | { 19 | if (!begin_list) 20 | return (NULL); 21 | while (begin_list->next) 22 | begin_list = begin_list->next; 23 | return (begin_list); 24 | } 25 | /* 26 | void ft_list_push_front(t_list **begin_list, void *data) 27 | { 28 | t_list *node; 29 | 30 | if (!begin_list) 31 | return ; 32 | node = ft_create_elem(data); 33 | if (!node) 34 | return ; 35 | if (*begin_list) 36 | node->next = *begin_list; 37 | *begin_list = node; 38 | } 39 | 40 | t_list *ft_create_elem(void *data) 41 | { 42 | t_list *elem; 43 | 44 | elem = malloc(sizeof(t_list)); 45 | if (!elem) 46 | return (NULL); 47 | elem->data = data; 48 | elem->next = NULL; 49 | return (elem); 50 | } 51 | 52 | void ft_list_print(t_list *list) 53 | { 54 | t_list *aux; 55 | 56 | while (list) 57 | { 58 | aux = list; 59 | printf("%s->", aux->data); 60 | list = list->next; 61 | free(aux); 62 | } 63 | printf("NULL\n"); 64 | } 65 | 66 | int main(int argc, char **argv) 67 | { 68 | t_list *list; 69 | 70 | list = NULL; 71 | for (int i = 1; i < argc; i++) 72 | ft_list_push_front(&list, argv[i]); 73 | printf("Last element \"%s\"\n", (char *)ft_list_last(list)->data); 74 | ft_list_print(list); 75 | } 76 | */ -------------------------------------------------------------------------------- /code/C12/ex17/ft_list.h: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list.h :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 22:57:54 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 22:57:54 by marvin ### ########.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 | 22 | t_list *ft_create_elem(void *data); 23 | 24 | void ft_list_push_front(t_list **begin_list, void *data); 25 | 26 | t_list *ft_list_last(t_list *begin_list); 27 | 28 | int ft_list_size(t_list *begin_list); 29 | 30 | void ft_list_push_back(t_list **begin_list, void *data); 31 | 32 | t_list *ft_list_push_strs(int size, char **strs); 33 | 34 | void ft_list_clear(t_list *begin_list, void (*free_fct)(void *)); 35 | 36 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr); 37 | 38 | void ft_list_reverse(t_list **begin_list); 39 | 40 | void ft_list_foreach(t_list *begin_list, void (*f)(void *)); 41 | 42 | void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), \ 43 | void *data_ref, int (*cmp)()); 44 | 45 | t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()); 46 | 47 | void ft_list_remove_if(t_list **begin_list, void *data_ref, \ 48 | int (*cmp)(), void (*free_fct)(void *)); 49 | 50 | void ft_list_merge(t_list **begin_list1, t_list *begin_list2); 51 | 52 | void ft_list_sort(t_list **begin_list, int (*cmp)()); 53 | 54 | void ft_list_reverse_fun(t_list *begin_list); 55 | 56 | void ft_sorted_list_insert(t_list **begin_list, void *data, int (*cmp)()); 57 | 58 | #endif -------------------------------------------------------------------------------- /code/C12/ex07/ft_list_at.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_list_at.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: marvin +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/02/01 23:50:55 by marvin #+# #+# */ 9 | /* Updated: 2023/02/01 23:50:55 by marvin ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include "ft_list.h" 14 | #include 15 | #include 16 | 17 | t_list *ft_list_at(t_list *begin_list, unsigned int nbr) 18 | { 19 | while (begin_list && nbr--) 20 | begin_list = begin_list->next; 21 | return (begin_list); 22 | } 23 | /* 24 | void ft_list_push_front(t_list **begin_list, void *data) 25 | { 26 | t_list *node; 27 | 28 | if (!begin_list) 29 | return ; 30 | node = ft_create_elem(data); 31 | if (!node) 32 | return ; 33 | if (*begin_list) 34 | node->next = *begin_list; 35 | *begin_list = node; 36 | } 37 | 38 | t_list *ft_create_elem(void *data) 39 | { 40 | t_list *elem; 41 | 42 | elem = malloc(sizeof(t_list)); 43 | if (!elem) 44 | return (NULL); 45 | elem->data = data; 46 | elem->next = NULL; 47 | return (elem); 48 | } 49 | 50 | void ft_list_print(t_list *list) 51 | { 52 | t_list *aux; 53 | 54 | while (list) 55 | { 56 | aux = list; 57 | printf("%s->", aux->data); 58 | list = list->next; 59 | free(aux); 60 | } 61 | printf("NULL\n"); 62 | } 63 | 64 | int main(int argc, char **argv) 65 | { 66 | unsigned int i; 67 | t_list *list; 68 | 69 | i = 0; 70 | list = NULL; 71 | for (int i = 1; i < argc; i++) 72 | ft_list_push_front(&list, argv[i]); 73 | printf("Element of position %u : %s\n", i, (char *)ft_list_at(list, i)->data); 74 | ft_list_print(list); 75 | } 76 | */ 77 | --------------------------------------------------------------------------------