├── DAYS ├── C10 │ ├── ex02 │ │ ├── srcs │ │ │ ├── ft_puterr.c │ │ │ ├── ft_strlen.c │ │ │ ├── stdin_to_stdout.c │ │ │ ├── ft_strncpy.c │ │ │ ├── show_file_name.c │ │ │ ├── main.c │ │ │ ├── ft_atoi.c │ │ │ ├── get_tail_index.c │ │ │ ├── check_flag.c │ │ │ └── ft_tail.c │ │ ├── Makefile │ │ ├── includes │ │ │ └── ft_tail.h │ │ └── README.md │ ├── ex01 │ │ ├── srcs │ │ │ ├── ft_putchar.c │ │ │ ├── ft_putstr.c │ │ │ ├── ft_strlen.c │ │ │ ├── stdin_to_stdout.c │ │ │ ├── ft_strcmp.c │ │ │ ├── main.c │ │ │ └── ft_cat.c │ │ ├── includes │ │ │ └── ft_cat.h │ │ ├── Makefile │ │ └── README.md │ ├── ex00 │ │ ├── srcs │ │ │ ├── ft_puterr.c │ │ │ ├── display_file.c │ │ │ └── main.c │ │ ├── includes │ │ │ └── display_file.h │ │ ├── test │ │ │ └── test.c │ │ ├── Makefile │ │ └── README.md │ ├── ex03 │ │ ├── srcs │ │ │ ├── ft_putchar.c │ │ │ ├── ft_strlen.c │ │ │ ├── ft_strncpy.c │ │ │ ├── ft_hexdump.c │ │ │ ├── ft_putaddr.c │ │ │ ├── main.c │ │ │ ├── ft_puthex.c │ │ │ ├── ft_putstr.c │ │ │ ├── get_content.c │ │ │ └── check_flag.c │ │ ├── Makefile │ │ └── README.md │ └── ex04 │ │ ├── test │ │ ├── test1.c │ │ ├── main.c │ │ ├── test2.c │ │ └── maybe_working.c │ │ ├── Makefile │ │ └── srcs │ │ └── ft_last.c ├── Shell00 │ ├── ex00 │ │ ├── z │ │ └── README.md │ ├── ex06 │ │ ├── git_ignore.sh │ │ └── README.md │ ├── ex05 │ │ ├── git_commit │ │ └── README.md │ ├── ex03 │ │ ├── exo3.sh │ │ └── README.md │ ├── ex04 │ │ └── exo7.sh │ ├── ex08 │ │ ├── clean.sh │ │ └── README.md │ ├── ex09 │ │ └── README.md │ ├── ex07 │ │ └── README.md │ └── ex01 │ │ └── testDay00.sh ├── Shell01 │ ├── ex05 │ │ ├── $'MaRViN'$ │ │ └── README.md │ ├── ex06 │ │ ├── skip.sh │ │ └── README.md │ ├── ex01 │ │ └── print_groups.sh │ ├── ex02 │ │ └── find_sh.sh │ ├── ex03 │ │ ├── count_files.sh │ │ └── README.md │ ├── ex04 │ │ └── MAC.sh │ ├── ex08 │ │ └── add_chelou.sh │ └── ex07 │ │ ├── r_dwssap.sh │ │ └── README.md ├── C09 │ ├── ex00 │ │ ├── libft_creator.sh │ │ ├── ft_putchar.c │ │ ├── ft_swap.c │ │ ├── ft_putstr.c │ │ ├── ft_strlen.c │ │ ├── ft.h │ │ ├── ft_strcmp.c │ │ └── README.md │ └── ex01 │ │ ├── ft.h │ │ ├── makefile │ │ └── README.md ├── C01 │ ├── ex00 │ │ ├── ft_ft.c │ │ └── README.md │ ├── ex05 │ │ ├── README.md │ │ └── ft_putstr.c │ ├── ex06 │ │ ├── README.md │ │ └── ft_strlen.c │ ├── ex02 │ │ ├── README.md │ │ └── ft_swap.c │ ├── ex08 │ │ ├── README.md │ │ └── ft_sort_int_tab.c │ ├── ex01 │ │ ├── README.md │ │ └── ft_ultimate_ft.c │ ├── ex03 │ │ ├── README.md │ │ └── ft_div_mod.c │ ├── ex04 │ │ ├── README.md │ │ └── ft_ultimate_div_mod.c │ └── ex07 │ │ ├── README.md │ │ └── ft_rev_int_tab.c ├── C00 │ ├── ex00 │ │ ├── ft_putchar.c │ │ └── README.md │ ├── ex04 │ │ ├── ft_is_negative.c │ │ └── README.md │ ├── ex03 │ │ ├── ft_print_numbers.c │ │ └── README.md │ ├── ex01 │ │ ├── ft_print_alphabet.c │ │ └── README.md │ ├── ex02 │ │ ├── ft_print_reverse_alphabet.c │ │ └── README.md │ ├── ex06 │ │ ├── README.md │ │ └── ft_print_comb2.c │ ├── ex07 │ │ ├── ft_putnbr.c │ │ └── README.md │ ├── ex08 │ │ └── ft_print_combn.c │ └── ex05 │ │ ├── ft_print_comb.c │ │ └── README.md ├── C08 │ ├── ex02 │ │ ├── ft_abs.h │ │ └── README.md │ ├── ex03 │ │ ├── ft_point.h │ │ └── README.md │ ├── ex00 │ │ ├── ft.h │ │ └── README.md │ ├── ex01 │ │ ├── ft_boolean.h │ │ └── README.md │ ├── ex05 │ │ ├── README.md │ │ └── ft_show_tab.c │ └── ex04 │ │ ├── README.md │ │ └── ft_strs_to_tab.c ├── C04 │ ├── ex00 │ │ ├── README.md │ │ └── ft_strlen.C │ ├── ex01 │ │ ├── ft_putstr.c │ │ └── README.md │ ├── ex02 │ │ ├── README.md │ │ └── ft_putnbr.c │ ├── ex05 │ │ ├── README.md │ │ └── ft_atoi_base.c │ ├── ex04 │ │ └── ft_putnbr_base.c │ └── ex03 │ │ ├── ft_atoi.c │ │ └── README.md ├── C07 │ ├── ex00 │ │ ├── README.md │ │ └── ft_strdup.c │ ├── ex03 │ │ ├── README.md │ │ └── ft_strjoin.c │ ├── ex01 │ │ ├── ft_range.c │ │ └── README.md │ ├── ex02 │ │ ├── ft_ultimate_range.c │ │ └── README.md │ ├── ex05 │ │ ├── README.md │ │ └── ft_split.c │ └── ex04 │ │ ├── README.md │ │ └── ft_convert_base.c ├── C02 │ ├── ex07 │ │ ├── README.md │ │ └── ft_strupcase.c │ ├── ex08 │ │ ├── README.md │ │ └── ft_strlowcase.c │ ├── ex00 │ │ ├── ft_strcpy.c │ │ └── README.md │ ├── ex03 │ │ ├── README.md │ │ └── ft_str_is_numeric.c │ ├── ex02 │ │ ├── README.md │ │ └── ft_str_is_alpha.c │ ├── ex06 │ │ ├── README.md │ │ └── ft_str_is_printable.c │ ├── ex05 │ │ ├── README.md │ │ └── ft_str_is_uppercase.c │ ├── ex04 │ │ ├── README.md │ │ └── ft_str_is_lowercase.c │ ├── ex01 │ │ ├── ft_strncpy.c │ │ └── README.md │ ├── ex09 │ │ ├── README.md │ │ └── ft_strcapitalize.c │ ├── ex10 │ │ ├── ft_strlcpy.c │ │ └── README.md │ └── ex11 │ │ ├── ft_putstr_non_printable.c │ │ └── README.md ├── C05 │ ├── ex06 │ │ ├── ft_is_prime.c │ │ └── README.md │ ├── ex07 │ │ ├── README.md │ │ └── ft_find_next_prime.c │ ├── ex04 │ │ └── ft_fibonacci.c │ ├── ex03 │ │ ├── ft_recursive_power.c │ │ └── README.md │ ├── ex01 │ │ └── ft_recursive_factorial.c │ ├── ex02 │ │ ├── ft_iterative_power.c │ │ └── README.md │ ├── ex00 │ │ └── ft_iterative_factorial.c │ ├── ex05 │ │ ├── ft_sqrt.c │ │ └── README.md │ └── ex08 │ │ └── ft_ten_queens_puzzle.c.c ├── C03 │ ├── ex00 │ │ ├── ft_strcmp.c │ │ └── README.md │ ├── ex01 │ │ ├── ft_strncmp.c │ │ └── README.md │ ├── ex03 │ │ ├── ft_strncat.c │ │ └── README.md │ ├── ex04 │ │ └── ft_strstr.c │ ├── ex02 │ │ ├── ft_strcat.c │ │ └── README.md │ └── ex05 │ │ └── ft_strlcat.c └── C06 │ ├── ex00 │ ├── ft_print_program_name.c │ └── README.MD │ ├── ex02 │ ├── ft_rev_params.c │ └── README.md │ ├── ex01 │ ├── ft_print_params.c │ └── README.md │ └── ex03 │ ├── README.md │ └── ft_sort_params.c ├── how_to_push.pdf ├── EXAMS ├── LEVEL 0 │ ├── only_a │ │ ├── only_a.c │ │ └── README.md │ ├── only_z │ │ ├── only_z.c │ │ └── README.md │ ├── hello │ │ ├── hello.c │ │ └── README.md │ ├── ft_countdown │ │ ├── ft_countdown.c │ │ └── README.md │ ├── ft_print_numbers │ │ ├── ft_print_numbers.c │ │ └── README.md │ ├── aff_last_param │ │ ├── aff_last_param.c │ │ └── README.md │ ├── maff_revalpha │ │ ├── maff_revalpha.c │ │ └── README.md │ ├── maff_alpha │ │ ├── maff_alpha.c │ │ └── README.md │ ├── aff_z │ │ ├── aff_z.c │ │ └── README.md │ ├── aff_first_param │ │ ├── README.md │ │ └── aff_first_param.c │ └── aff_a │ │ ├── aff_a.c │ │ └── README.md ├── LEVEL 1 │ ├── ft_swap │ │ ├── ft_swap.c │ │ └── README.md │ ├── ft_putstr │ │ ├── ft_putstr.c │ │ └── README.md │ ├── ft_strcpy │ │ ├── ft_strcpy.c │ │ └── README.md │ ├── ft_strlen │ │ ├── ft_strlen.c │ │ └── README.md │ ├── rev_print │ │ ├── rev_print.c │ │ └── README.md │ ├── rotone │ │ ├── rotone.c │ │ └── README.md │ ├── ulstr │ │ ├── ulstr.c │ │ └── README.md │ ├── fizzbuzz │ │ ├── fizzbuzz.c │ │ └── README.md │ ├── search_and_replace │ │ ├── search_and_replace.c │ │ └── README.md │ ├── rot_13 │ │ ├── rot_13.c │ │ └── README.md │ ├── repeat_alpha │ │ ├── repeat_alpha.c │ │ └── README.md │ ├── last_word │ │ ├── last_word.c │ │ └── README.md │ └── first_word │ │ ├── README.md │ │ └── first_word.c └── LEVEL 2 │ ├── ft_strcmp │ ├── README.md │ └── ft_strcmp.c │ ├── ft_strdup │ ├── README.md │ └── ft_strdup.c │ ├── ft_strspn │ ├── README.md │ └── ft_strspn.c │ ├── ft_strrev │ ├── README.md │ └── ft_strrev.c │ ├── ft_atoi │ ├── README.md │ └── ft_atoi.c │ ├── inter │ ├── README.md │ └── inter.c │ ├── alpha_mirror │ ├── README.md │ └── alpha_mirror.c │ ├── last_word │ ├── README.md │ └── last_word.c │ ├── union │ ├── README.md │ └── union.c │ └── wdmatch │ ├── README.md │ ├── wdmatch.c │ └── wdmatch2.c ├── LICENSE └── RUSH ├── rush01.c ├── rush00.c └── rush02.c /DAYS/C10/ex02/srcs/ft_puterr.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DAYS/Shell00/ex00/z: -------------------------------------------------------------------------------- 1 | echo "Z" > z -------------------------------------------------------------------------------- /DAYS/Shell01/ex05/$'MaRViN'$: -------------------------------------------------------------------------------- 1 | 42 -------------------------------------------------------------------------------- /DAYS/Shell00/ex06/git_ignore.sh: -------------------------------------------------------------------------------- 1 | git clean -ndX | awk '{print $3}' -------------------------------------------------------------------------------- /DAYS/Shell01/ex06/skip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ls -l | awk 'NR % 2 == 1' -------------------------------------------------------------------------------- /DAYS/Shell01/ex01/print_groups.sh: -------------------------------------------------------------------------------- 1 | groups $FT_USER | tr ' ' ',' | tr -d '\n' -------------------------------------------------------------------------------- /DAYS/Shell01/ex02/find_sh.sh: -------------------------------------------------------------------------------- 1 | find . -name '*.sh' -print | xargs basename -s .sh -------------------------------------------------------------------------------- /DAYS/Shell01/ex03/count_files.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | find . | wc -l | tr -d ' ' -------------------------------------------------------------------------------- /DAYS/Shell00/ex05/git_commit: -------------------------------------------------------------------------------- 1 | git log --pretty=oneline | head -n 5 | awk '{print $1}' -------------------------------------------------------------------------------- /DAYS/Shell00/ex06/README.md: -------------------------------------------------------------------------------- 1 | ## Git ignore 2 | ```sh 3 | git-clean -Xnd | cut -b 14-256 4 | ``` -------------------------------------------------------------------------------- /DAYS/C09/ex00/libft_creator.sh: -------------------------------------------------------------------------------- 1 | gcc -Wall -Wextra -Werror -c *.c 2 | ar rcs libft.a *.o 3 | rm -r *.o -------------------------------------------------------------------------------- /DAYS/C01/ex00/ft_ft.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_ft(int *nbr) 4 | { 5 | *nbr = 42; 6 | } -------------------------------------------------------------------------------- /how_to_push.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Its-Kaizen/1337-Pool-Piscine-42-Network/HEAD/how_to_push.pdf -------------------------------------------------------------------------------- /DAYS/C00/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/ft_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } -------------------------------------------------------------------------------- /DAYS/Shell00/ex03/exo3.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Kerberos authentification. 4 | klist > klist.txt 5 | ls -l 6 | cat klist.txt -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft_swap.c: -------------------------------------------------------------------------------- 1 | void ft_swap(int *a, int *b) 2 | { 3 | int tmp; 4 | 5 | tmp = *a; 6 | *a = *b; 7 | *b = tmp; 8 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/only_a/only_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | write(1, "a", 1); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/only_z/only_z.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | write(1, "z", 1); 6 | return 0; 7 | } -------------------------------------------------------------------------------- /DAYS/C08/ex02/ft_abs.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_ABS_H 2 | # define FT_ABS_H 3 | 4 | # define ABS(Value) (Value < 0) ? (Value * -1) : (Value) 5 | 6 | #endif -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | while (*str) 6 | write(1, str++, 1); 7 | } 8 | -------------------------------------------------------------------------------- /DAYS/C10/ex00/srcs/ft_puterr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_puterr(char *str) 4 | { 5 | while (*str) 6 | write(2, str++, 1); 7 | } -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | while (*str) 6 | write(1, str++, 1); 7 | } -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/ft_strlen.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while(str[i]) 7 | i++; 8 | return (i); 9 | } -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_putchar.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(STDOUT_FILENO, &c, 1); 6 | } -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_strlen.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while (str[i]) 7 | i++; 8 | return (i); 9 | } -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while (str[i]) 7 | i++; 8 | return (i); 9 | } 10 | -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/ft_strlen.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while (str[i] != '\0') 7 | i++; 8 | return (i); 9 | } -------------------------------------------------------------------------------- /DAYS/C08/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: ft_abs.h 2 | - Create a marco __ABS__ which replaces its argument by it absolute value: 3 | ```C 4 | #define ABS(Value) 5 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/hello/hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | write(1, "Hello World!", 12); 6 | write(1, "\n", 1); 7 | return 0; 8 | } -------------------------------------------------------------------------------- /DAYS/C08/ex03/ft_point.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_POINT_H 2 | # define FT_POINT_H 3 | 4 | typedef struct s_point 5 | { 6 | int x; 7 | int y; 8 | } t_point; 9 | 10 | #endif -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/stdin_to_stdout.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_cat.h" 2 | 3 | void in_to_out(void) 4 | { 5 | char c; 6 | 7 | while (read(0, &c, 1)) 8 | ft_putchar(c); 9 | } -------------------------------------------------------------------------------- /DAYS/Shell01/ex04/MAC.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ifconfig -a | grep ether | awk '{print $2}' 4 | 5 | # ifconfig | awk '/ether/ {print $2}' 6 | # ✗ ifconfig -a | grep ether | cut -d ' ' -f 2 -------------------------------------------------------------------------------- /DAYS/C00/ex04/ft_is_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_is_negative(int n) 4 | { 5 | if (n < 0) 6 | write(1, "N", 1); 7 | else 8 | write(1, "P", 1); 9 | } -------------------------------------------------------------------------------- /DAYS/Shell01/ex08/add_chelou.sh: -------------------------------------------------------------------------------- 1 | echo $FT_NBR1 + $FT_NBR2 | sed "s/\'/0/g" | tr '\\"?!' '1234' | tr 'mrdoc' '01234' | xargs -I {} echo "obase=13; ibase=5;" {} | bc | tr '0123456789ABC' 'gtaio luSnemf' -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_swap/ft_swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_swap(int *a, int *b) 4 | { 5 | int tmp; 6 | 7 | tmp = *a; 8 | *a = *b; 9 | *b = tmp; 10 | } -------------------------------------------------------------------------------- /DAYS/C04/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 00 2 | * Create a function that counts and returns the number of characters in a string. 3 | * Here’s how it should be prototyped : 4 | ```C 5 | int ft_strlen(char *str); 6 | ``` -------------------------------------------------------------------------------- /DAYS/Shell01/ex07/r_dwssap.sh: -------------------------------------------------------------------------------- 1 | cat /etc/passwd | grep -v "#" | awk "NR%2==0" | awk -F: '{print $1}' | rev | sort -r | sed -n "$FT_LINE1,$FT_LINE2 p" | tr '\n' ',' | sed 's/,/, /g' | sed 's/, $/./' | xargs -I{} echo -n {} -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/stdin_to_stdout.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | void stdin_to_stdout(void) 4 | { 5 | char c; 6 | 7 | while (read(STDIN_FILENO, &c, 1) > 0) 8 | write(STDIN_FILENO, &c, 1); 9 | } -------------------------------------------------------------------------------- /DAYS/C04/ex00/ft_strlen.C: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strlen(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i]) 9 | { 10 | i++; 11 | } 12 | return(i); 13 | } 14 | -------------------------------------------------------------------------------- /DAYS/C10/ex00/includes/display_file.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAY_FILE_H 2 | #define DISPLAY_FILE_H 3 | 4 | #include 5 | #include 6 | 7 | void ft_puterr(char *err); 8 | void display_file(char *file); 9 | 10 | #endif -------------------------------------------------------------------------------- /DAYS/C00/ex03/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_print_numbers(void) 4 | { 5 | char x; 6 | x = '0'; 7 | while (x <= '9') 8 | { 9 | write(1, &x, 1); 10 | x++; 11 | } 12 | } -------------------------------------------------------------------------------- /DAYS/C04/ex01/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while(str[i]) 9 | { 10 | write(1, &str[i], 1); 11 | i++; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /DAYS/C07/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 00: ft_strdup 2 | - Reproduce the behavior of the function __strdup__ (man strdup). 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strdup(char *src); 6 | ``` 7 | - Allowed functions: __malloc__ -------------------------------------------------------------------------------- /DAYS/C08/ex00/ft.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_H 2 | # define FT_H 3 | 4 | void ft_putchar(char c); 5 | void ft_swap(int *a, int *b); 6 | void ft_putstr(char *str); 7 | int ft_strlen(char *str); 8 | int ft_strcmp(char *s1, char *s2); 9 | 10 | #endif -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_H 2 | # define FT_H 3 | 4 | void ft_putchar(char c); 5 | void ft_swap(int *a, int *b); 6 | void ft_putstr(char *str); 7 | int ft_strlen(char *str); 8 | int ft_strcmp(char *s1, char *s2); 9 | 10 | #endif -------------------------------------------------------------------------------- /DAYS/C09/ex01/ft.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_H 2 | # define FT_H 3 | 4 | void ft_putchar(char c); 5 | void ft_swap(int *a, int *b); 6 | void ft_putstr(char *str); 7 | int ft_strlen(char *str); 8 | int ft_strcmp(char *s1, char *s2); 9 | 10 | #endif -------------------------------------------------------------------------------- /DAYS/C00/ex01/ft_print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_print_alphabet(void) 4 | { 5 | int x; 6 | x = 'a'; 7 | 8 | while (x <= 'z') 9 | { 10 | write(1, &x, 1); 11 | x++; 12 | } 13 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_putstr/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(str[i]) 10 | { 11 | write(1, &str[i], 1); 12 | i++; 13 | } 14 | } -------------------------------------------------------------------------------- /DAYS/C02/ex07/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 08: ft_strupcase 2 | - Create a function that transforms every letter of every word to uppercase. 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strupcase(char *str) 6 | ``` 7 | - It should return __str__. -------------------------------------------------------------------------------- /DAYS/C02/ex08/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 09: ft_strlowcase 2 | - Create a function that transforms every letter of every word to lowercase. 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strlowcase(char *str); 6 | ``` 7 | - It should return **str**. -------------------------------------------------------------------------------- /DAYS/C05/ex06/ft_is_prime.c: -------------------------------------------------------------------------------- 1 | int ft_is_prime(int nb) 2 | { 3 | int i; 4 | 5 | i = 2; 6 | if (nb < 2) 7 | return (0); 8 | while (i <= nb / 2) 9 | { 10 | if (nb % i == 0) 11 | return (0); 12 | i++; 13 | } 14 | return (1); 15 | } -------------------------------------------------------------------------------- /DAYS/C09/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | int ft_strcmp(char *s1, char *s2) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while (s1[i] && s2[i]) 7 | { 8 | if (s1[i] == s2[i]) 9 | i++; 10 | else 11 | break ; 12 | } 13 | return (s1[i] - s2[i]); 14 | } 15 | -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | int ft_strcmp(char *s1, char *s2) 2 | { 3 | int i; 4 | 5 | i = 0; 6 | while (s1[i] && s2[i]) 7 | { 8 | if (s1[i] == s2[i]) 9 | i++; 10 | else 11 | break ; 12 | } 13 | return (s1[i] - s2[i]); 14 | } -------------------------------------------------------------------------------- /DAYS/C00/ex02/ft_print_reverse_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_print_reverse_alphabet(void) 4 | { 5 | char x; 6 | x = 'z'; 7 | 8 | while (x >= 'a') 9 | { 10 | write(1, &x, 1); 11 | x--; 12 | } 13 | } -------------------------------------------------------------------------------- /DAYS/C04/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01: ft_putstr 2 | 3 | - Create a function that displays a string of characters on the standard output. 4 | - Here's how it should be prototyped: 5 | ```C 6 | void ft_putstr(char *str); 7 | ``` 8 | - Allowed function: ft_putchar. 9 | -------------------------------------------------------------------------------- /DAYS/C10/ex00/test/test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char b[30]; 6 | 7 | write(1, "Enter your text: ", 17); 8 | read(0, b, 30); 9 | write(1, "You Entered: ", 17); 10 | write(1, b, 30); 11 | return (0); 12 | return (0); 13 | } -------------------------------------------------------------------------------- /DAYS/C03/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strcmp(char *s1, char *s2) 4 | { 5 | unsigned int i; 6 | 7 | i = 0; 8 | 9 | while(s1[i] == s2[i] && s1[i] != '\0' || s2[i] != '\0') 10 | { 11 | i++; 12 | } 13 | return (s1[i] - s2[i]); 14 | } 15 | -------------------------------------------------------------------------------- /DAYS/Shell00/ex04/exo7.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #------------------------------------------------------------------------------ 4 | # This one hell of a an easy exercice. 5 | ls -trhpm 6 | ##ls -upm 7 | #RTFM. 8 | #------------------------------------------------------------------------------ -------------------------------------------------------------------------------- /DAYS/Shell00/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Git commit 2 | - Objective: Write a shell script that returns the last 5 hashes in your git #deposit. 3 | - Used files: git, cat. 4 | 5 | ## Solution: 6 | - Git is very usefull tool, check a tutorial. 7 | ```sh 8 | git log -5 --format='%H' | cat -e 9 | ``` -------------------------------------------------------------------------------- /DAYS/C00/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 03 2 | * Create a function that displays all digits, on a single line, by ascending order. 3 | * Here's how it should be prototyped: 4 | ```C 5 | void ft_print_numbers(void); 6 | ``` 7 | * Files to turn in: ft_print_numbers.c 8 | * Allowed functions: ft_putchar -------------------------------------------------------------------------------- /DAYS/C01/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 05: ft_putstr 2 | + Create a function that display a string of characters on the standard output. 3 | + Here's how it should be prototyped: 4 | ```C 5 | void ft_putstr(char *str); 6 | ``` 7 | + Files to turn in: ft_putstr.c 8 | + Allowed functions: ft_putchar -------------------------------------------------------------------------------- /DAYS/C01/ex06/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 06: ft_strlen 2 | + Create a function that counts and returns the number of characters in a string. 3 | + Here's how it should be prototyped: 4 | ```C 5 | int ft_strlen(char *str); 6 | ``` 7 | + Files to turn in: ft_strlen.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C01/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 00: ft_ft 2 | + Create a function that takes a pointer to int as parameter, and sets the value "42" to that int. 3 | + Here's how it should be prototyped: 4 | ```C 5 | void ft_ft(int *nbr); 6 | ``` 7 | + Files to turn in: ft_ft.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | char *ft_strncpy(char *dest, char *src, unsigned int n) 2 | { 3 | unsigned int i; 4 | 5 | i = 0; 6 | while (src[i] && i < n) 7 | { 8 | dest[i] = src[i]; 9 | i++; 10 | } 11 | while (i < n) 12 | dest[i++] = '\0'; 13 | return (dest); 14 | } -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | char *ft_strncpy(char *dest, char *src, unsigned int n) 2 | { 3 | unsigned int i; 4 | 5 | i = 0; 6 | while (src[i] && i < n) 7 | { 8 | dest[i] = src[i]; 9 | i++; 10 | } 11 | while (i < n) 12 | dest[i++] = '\0'; 13 | return (dest); 14 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/ft_countdown/ft_countdown.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char n; 6 | 7 | n = '9'; 8 | 9 | while(n >= '0') 10 | { 11 | write(1, &n, 1); 12 | n--; 13 | } 14 | write(1, "\n", 1); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /DAYS/C01/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: ft_swap 2 | + Create a function that swaps the value of two integers whose addresses are entered as parameters. 3 | + Here’s how it should be prototyped: 4 | ```C 5 | void ft_swap(int *a, int *b); 6 | ``` 7 | + Files to turn in: ft_swap.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_strcpy/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strcpy(char *s1, char *s2) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while (s2[i]) 10 | { 11 | s1[i] = s2[i]; 12 | i++; 13 | } 14 | s1[i] = '\n'; 15 | 16 | return (s1); 17 | } -------------------------------------------------------------------------------- /DAYS/C10/ex00/srcs/display_file.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | void display_file(char *file_name) 6 | { 7 | int fd; 8 | char buf; 9 | 10 | fd = open(file_name, O_RDONLY); 11 | if (fd > 0) 12 | while (read(fd, &buf, 1)) 13 | write(1, &buf, 1); 14 | close(fd); 15 | } -------------------------------------------------------------------------------- /DAYS/C02/ex07/ft_strupcase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strupcase(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(str[i]) 10 | { 11 | if (str[i] >= 'a' && str[i] <= 'z') 12 | str[i] = str[i] - 32; 13 | i++; 14 | } 15 | return(str); 16 | } -------------------------------------------------------------------------------- /DAYS/C05/ex07/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 07: ft_find_next_prime 2 | - Create a function that returns the next prime number greater of equal to the number given as argument. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_find_next_prime(int nb); 6 | ``` 7 | - Your function must return its result in less than two seconds. -------------------------------------------------------------------------------- /DAYS/C05/ex04/ft_fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_fibonacci(int index) 4 | { 5 | if (index < 0) 6 | return (-1); 7 | if (index < 2) 8 | return (index); 9 | return (ft_fibonacci(index - 2) + ft_fibonacci(index - 1)); 10 | } 11 | 12 | int main(void) 13 | { 14 | printf("%i", ft_fibonacci(7)); 15 | } -------------------------------------------------------------------------------- /DAYS/C08/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 00: ft.h 2 | - Create your __ft.h__ file. 3 | - It contains all prototypes of all the following functions. 4 | ```c 5 | void ft_putchar(char c); 6 | void ft_swap(int *a, int *b); 7 | void ft_putstr(char *str); 8 | int ft_strlen(char *str); 9 | int ft_strcmp(char *s1, char *s2); 10 | ``` -------------------------------------------------------------------------------- /DAYS/C02/ex00/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strcpy(char *dest, char *src) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(src[i]) 10 | { 11 | dest[i] = src[i]; 12 | i++; 13 | } 14 | dest[i] = '\0'; 15 | return(dest); 16 | } -------------------------------------------------------------------------------- /DAYS/C02/ex08/ft_strlowcase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strlowcase(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(str[i]) 10 | { 11 | if (str[i] >= 'A' && str[i] <= 'Z') 12 | str[i] = str[i] + 32; 13 | i++; 14 | } 15 | return(str); 16 | } 17 | -------------------------------------------------------------------------------- /DAYS/C00/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 01 2 | * Create a function that displays the alphabet in lowercase, on a single line, by ascending order, starting from the letter 'a'. 3 | * Here's how it should be prototyped: 4 | ```C 5 | void ft_print_alphabet(void); 6 | ``` 7 | * Files to turn in: ft_print_alphabet.c 8 | * Allowed funcitons: ft_putchar -------------------------------------------------------------------------------- /DAYS/C02/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 12: ft_str_is_numeric 2 | - Create a function that returns 1 if the string given as a parameter contains only digits, and 0 if it contains any other character. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_str_is_numeric(char *str); 6 | ``` 7 | - It should return 1 if __str__ is empty. 8 | -------------------------------------------------------------------------------- /DAYS/C07/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_strjoin 2 | - Create a function that transforms arguments given as command-line into a single string of characters. Those arguments should be __separated__ by '\n'. 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strjoin(int argc, char **argv); 6 | ``` 7 | - Allowed functions: __malloc__ -------------------------------------------------------------------------------- /DAYS/C10/ex00/srcs/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ft_puterr.c" 3 | #include "display_file.c" 4 | 5 | int main(int ac, char **av) 6 | { 7 | if (ac < 2) 8 | ft_puterr("File name missing."); 9 | else if (ac > 2) 10 | ft_puterr("Too many arguments."); 11 | else 12 | display_file(av[1]); 13 | return (0); 14 | } -------------------------------------------------------------------------------- /DAYS/C02/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 11: ft_str_is_alpha 2 | - Create a function that returns 1 if the string given as a parameter contains only alphabetical characters, and 0 if it contains any other character. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_str_is_alpha(char *str); 6 | ``` 7 | - It should return 1 if __str__ is empty. 8 | -------------------------------------------------------------------------------- /DAYS/C00/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 02 2 | * Create a function that displays the alphabet in lowercase, on a single line, by descending order, starting from the letter 'z'. 3 | * Here's how it should be prototyped: 4 | ```C 5 | void ft_print_reverse_alphabet(void); 6 | ``` 7 | * Files to turn in: fr_reverse_alphabet.c 8 | * Allowed functions: ft_putchar 9 | -------------------------------------------------------------------------------- /DAYS/C02/ex06/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 15: ft_str_is_printable 2 | - Create a function that returns 1 if the string given as a parameter contains only printable characters, and 0 if it contains any other character. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_str_is_printable(char *str); 6 | ``` 7 | - It should return 1 if __str__ is empty. 8 | -------------------------------------------------------------------------------- /DAYS/C05/ex03/ft_recursive_power.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_recursive_power(int nb, int power) 4 | { 5 | int result; 6 | 7 | result = nb; 8 | if (power > 1) 9 | return (nb * ft_recursive_power(nb, (power - 1))); 10 | if (power == 0) 11 | return (1); 12 | if (power < 0) 13 | return (0); 14 | return (result); 15 | } 16 | -------------------------------------------------------------------------------- /DAYS/C02/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 14: ft_str_is_uppercase 2 | - Create a function that returns 1 if the string given as a parameter contains only uppercase alphabetical characters, and 0 if it contains any other characters. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_str_is_uppercase(char *str); 6 | ``` 7 | - It should return 1 if __str__ is empty. -------------------------------------------------------------------------------- /DAYS/C02/ex04/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 13: ft_str_is_lowercase 2 | - Create a function that returns 1 if the string given as a parameter contains only lowercase alphabetical characters, and 0 if it contains any other character. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_str_is_lowercase(char *str); 6 | ``` 7 | - It should return 1 if __str__ is empty. 8 | -------------------------------------------------------------------------------- /DAYS/C03/ex01/ft_strncmp.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strncmp(char *s1, char *s2, unsigned int n) 4 | { 5 | unsigned int i; 6 | 7 | i = 0; 8 | 9 | while((s1[i] != '\0' || s2[i] != '\0') && i < n) 10 | { 11 | if (s1[i] != s2[i]) 12 | return(s1[i] - s2[i]); 13 | i++; 14 | } 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /DAYS/C06/ex00/ft_print_program_name.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | int main(int argc, char **argv) 9 | { 10 | int i; 11 | 12 | i = 0; 13 | while (argv[0][i] != '\0' && argc) 14 | { 15 | ft_putchar(argv[0][i]); 16 | ++i; 17 | } 18 | ft_putchar('\n'); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /DAYS/C06/ex02/ft_rev_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i]) 9 | write(1, &str[i++], 1); 10 | write(1, "\n", 1); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | while (argc > 1) 16 | { 17 | ft_putstr(argv[argc - 1]); 18 | argc--; 19 | } 20 | return (0); 21 | } -------------------------------------------------------------------------------- /DAYS/C08/ex01/ft_boolean.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_BOOLEAN_H 2 | # define FT_BOOLEAN_H 3 | 4 | # include 5 | # define EVEN(x) x % 2 == 0 6 | # define TRUE 1 7 | # define FALSE 0 8 | # define EVEN_MSG "I have an even number of arguments.\n" 9 | # define ODD_MSG "I have an odd number of arguments.\n" 10 | # define SUCCESS 0 11 | 12 | typedef int t_bool; 13 | 14 | #endif -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/main.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_cat.h" 2 | 3 | int main(int ac, char **av) 4 | { 5 | int i; 6 | 7 | i = 1; 8 | if (ac == 1) 9 | in_to_out(); 10 | else 11 | { 12 | while (i < ac) 13 | { 14 | if (ft_strcmp(av[i], "-") == 0) 15 | in_to_out(); 16 | else 17 | ft_cat(av[i]); 18 | i++; 19 | } 20 | } 21 | return (0); -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strcmp/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : ft_strcmp 2 | Expected files : ft_strcmp.c 3 | Allowed functions: 4 | -------------------------------------------------------------------------------- 5 | 6 | Reproduce the behavior of the function strcmp (man strcmp). 7 | 8 | Your function must be declared as follows: 9 | 10 | int ft_strcmp(char *s1, char *s2); -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strdup/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : ft_strdup 2 | Expected files : ft_strdup.c 3 | Allowed functions: malloc 4 | -------------------------------------------------------------------------------- 5 | 6 | Reproduce the behavior of the function strdup (man strdup). 7 | 8 | Your function must be declared as follows: 9 | 10 | char *ft_strdup(char *src); -------------------------------------------------------------------------------- /DAYS/C00/ex04/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 04 2 | * Create a function that displays 'N' or 'P' depending on the integer's sign entered as a parameter. If **n** is negative, display 'N', if **n** is positive or null, display 'P'. 3 | * Here's how it should be prototyped: 4 | ```C 5 | void ft_is_negative(int n); 6 | ``` 7 | * Files to turn in: ft_is_negative.c 8 | * Allowed funcitons: ft_putchar -------------------------------------------------------------------------------- /DAYS/C06/ex01/ft_print_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i]) 9 | write(1, &str[i++], 1); 10 | write(1, "\n", 1); 11 | } 12 | 13 | int main(int argc, char **argv) 14 | { 15 | int i; 16 | 17 | i = 1; 18 | while (i < argc) 19 | ft_putstr(argv[i++]); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /DAYS/C08/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_point.h 2 | - Create a file __ft_point_h__ that'll compile the following main: 3 | ```c 4 | # include "ft_point.h" 5 | 6 | void set_point(t_point *point) 7 | { 8 | point->x = 42; 9 | point->y = 21; 10 | } 11 | 12 | int main(void) 13 | { 14 | t_point point; 15 | 16 | set_point(&point); 17 | return (0); 18 | } 19 | ``` -------------------------------------------------------------------------------- /DAYS/C02/ex01/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strncpy(char *dest, char *src, unsigned int n) 4 | { 5 | unsigned int i; 6 | 7 | i = 0; 8 | 9 | while(src[i] && i < n) 10 | { 11 | dest[i] = src[i]; 12 | } 13 | while(i < n) 14 | { 15 | dest[i] = '\0'; 16 | i++; 17 | } 18 | return(dest); 19 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/ft_print_numbers/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_print_numbers(void) 4 | { 5 | int i; 6 | 7 | i = '0'; 8 | 9 | while(i <= '9') 10 | { 11 | write(1, &i, 1); 12 | i++; 13 | } 14 | write(1, "\n", 1); 15 | } 16 | 17 | int main() 18 | { 19 | ft_print_numbers(); 20 | 21 | return 0; 22 | } -------------------------------------------------------------------------------- /DAYS/C01/ex08/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 08: ft_sort_int_tab 2 | + Create a function which sorts an array (table) of integers by ascending order. 3 | + The arguments are a pointer to int and the number of ints in the array. 4 | + Here's how it should be prototyped: 5 | ```C 6 | void ft_sort_int_tab(int *tab, int size); 7 | ``` 8 | + Files to turn in: ft_sort_int_tab.c 9 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C10/ex01/includes/ft_cat.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_CAT_H 2 | # define FT_CAT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | void in_to_out(void); 11 | int ft_strcmp(char *s1, char *s2); 12 | void ft_putstr(char *str); 13 | void ft_putchar(char c); 14 | void ft_cat(char *file_name); 15 | 16 | #endif -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_last_param/aff_last_param.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | if (argc == 1) 10 | write(1, "\n", 1); 11 | else if (argc >= 2) 12 | while(argv[argc - 1][i]) 13 | write(1, &argv[argc -1][i++], 1); 14 | write(1, "\n", 1); 15 | 16 | return 0; 17 | } -------------------------------------------------------------------------------- /DAYS/C10/ex04/test/test1.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]){ 7 | 8 | struct passwd *buffer; 9 | struct utmp *naveen; 10 | 11 | while((buffer=getpwent()!=NULL)){ 12 | printf("%s", buffer->pw_gecos); 13 | printf("%s", naveen->ut_user); 14 | } 15 | return 0; 16 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strspn/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : ft_strspn 2 | Expected files : ft_strspn.c 3 | Allowed functions: None 4 | --------------------------------------------------------------- 5 | 6 | Reproduce exactly the behavior of the strspn function 7 | (man strspn). 8 | 9 | The function should be prototyped as follows: 10 | 11 | size_t ft_strspn(const char *s, const char *accept); -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_hexdump.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | void ft_hexdump(char *content, unsigned int size, int flag) 4 | { 5 | char *str; 6 | unsigned int i; 7 | 8 | str = content; 9 | i = 0; 10 | while(i < size) 11 | { 12 | 13 | ft_putaddr(i, flag); 14 | ft_puthex(str, i, flag); 15 | i += ft_putstr(str, i, size, flag); 16 | ft_putchar('\n'); 17 | } 18 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strrev/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : ft_strrev 2 | Expected files : ft_strrev.c 3 | Allowed functions: 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a function that reverses (in-place) a string. 7 | 8 | It must return its parameter. 9 | 10 | Your function must be declared as follows: 11 | 12 | char *ft_strrev(char *str); -------------------------------------------------------------------------------- /DAYS/C01/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01: ft_ultimate_ft 2 | + Create a function that takes a pointer to pointer to pointer to pointer to pointer to pointer to pointer to pointer to pointer to int as a parameter and sets the value "42" to that int. 3 | + Here's how it should be prototyped: 4 | ```C 5 | void ft_ultimate_ft(int *********nbr); 6 | ``` 7 | + Files to turn in: ft_ultimate_ft.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C04/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: ft_putnbr 2 | 3 | - Create a function that displays the number entered as a parameter. The function has to be able to display all possible values within an __int__ type variable. 4 | - Here's how it should be prototyped: 5 | ```C 6 | void ft_putnbr(int nb); 7 | ``` 8 | - For example: 9 | - ft_putnbr(1337) displays "42"; 10 | - Allowed functions: ft_putchar. -------------------------------------------------------------------------------- /DAYS/C05/ex01/ft_recursive_factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_recursive_factorial(int nb) 4 | { 5 | int result; 6 | 7 | result = 1; 8 | if (nb > 0) 9 | { 10 | result *= nb * ft_recursive_factorial(nb - 1); 11 | nb -= 1; 12 | } 13 | if (nb < 0) 14 | return (0); 15 | return (result); 16 | } 17 | 18 | int main(void) 19 | { 20 | printf("%i", ft_recursive_factorial(9)); 21 | } -------------------------------------------------------------------------------- /DAYS/C01/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_div_mod 2 | + Create a function **ft_div_mod** prototyped like this: 3 | ```C 4 | void ft_div_mod(int a, int b, int *div, int *mod); 5 | ``` 6 | + This function divides parameters a by b and stores the result in the int pointed by div. It also stores the remainder of the division of a by b in the int pointed by mod. 7 | + Files to turn in: ft_div_mod.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C07/ex01/ft_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int *ft_range(int min, int max) 5 | { 6 | int i; 7 | int size; 8 | int *range; 9 | 10 | i = 0; 11 | size = max - min; 12 | range = malloc(sizeof(int) * size); 13 | if (min >= max) 14 | return (NULL); 15 | while (min < max) 16 | { 17 | range[i] = min; 18 | i++; 19 | min++; 20 | } 21 | return (range); 22 | } 23 | -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/show_file_name.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | void show_file_name(int ac, int bytes, char *filename) 4 | { 5 | static int i; 6 | 7 | if ((!bytes && ac > 2) || (bytes && ac > 4)) 8 | { 9 | if (i++) 10 | write(1, "\n", 1); 11 | write(STDOUT_FILENO, "==> ", 4); 12 | write(STDOUT_FILENO, filename, ft_strlen(filename)); 13 | write(STDOUT_FILENO, " <==\n", 5); 14 | } 15 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/maff_revalpha/maff_revalpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | int main(void) 9 | { 10 | int x; 11 | 12 | x = 122; 13 | 14 | while (x >= 97) 15 | { 16 | if (x % 2 == 0) 17 | ft_putchar(x); 18 | else 19 | ft_putchar(x - 32); 20 | x--; 21 | } 22 | return 0; 23 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_strlen/ft_strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strlen(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while (str[i]) 10 | { 11 | i++; 12 | } 13 | 14 | return (i); 15 | } 16 | 17 | int main(int argc, char **argv) 18 | { 19 | int i = 0; 20 | 21 | while (argv[1][i]) 22 | { 23 | i++; 24 | } 25 | 26 | return i; 27 | } -------------------------------------------------------------------------------- /DAYS/C01/ex08/ft_sort_int_tab.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | void ft_sort_int_tab(int *tab, int size) 5 | { 6 | int i; 7 | int swap; 8 | 9 | while (size >= 0) 10 | { 11 | i = 0; 12 | while (i < size - 1) 13 | { 14 | if (tab[i] > tab[i + 1]) 15 | { 16 | swap = tab [i]; 17 | tab[i] = tab [i + 1]; 18 | tab [i + 1] = swap; 19 | } 20 | i++; 21 | } 22 | size--; 23 | } 24 | } -------------------------------------------------------------------------------- /DAYS/C05/ex02/ft_iterative_power.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_iterative_power(int nb, int power) 4 | { 5 | int result; 6 | 7 | result = nb; 8 | while (power > 1) 9 | { 10 | result *= nb; 11 | power--; 12 | } 13 | if (power == 0) 14 | return (1); 15 | if (power < 0) 16 | return (0); 17 | return (result); 18 | } 19 | 20 | int main(void) 21 | { 22 | printf("%i", ft_iterative_power(3, 4 )); 23 | } -------------------------------------------------------------------------------- /DAYS/C06/ex00/README.MD: -------------------------------------------------------------------------------- 1 | ## ft_print_program_name 2 | 3 | 4 | - Turn-in directory : ex00/ 5 | - Files to turn in : ft_print_program_name.c 6 | - Allowed functions : write 7 | • We’re dealing with a program here, you should therefore have a function main in 8 | your .c file. 9 | • Create a program that displays its own name followed by a new line. 10 | • Example : 11 | ```$>./a.out | cat -e 12 | ./a.out$ 13 | $>`` 14 | -------------------------------------------------------------------------------- /DAYS/C10/ex04/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall -Wextra -Werror 3 | INCLUDES=-I includes 4 | SRCS=$(wildcard srcs/*) 5 | OBJS=$(notdir $(SRCS:.c=.o)) 6 | BIN=ft_last 7 | 8 | .PHONY: all clean fclean 9 | 10 | all: $(BIN) 11 | 12 | $(BIN): $(OBJS) 13 | $(CC) $(INCLUDES) $(FLAGS) $? -o $@ 14 | 15 | $(OBJS): $(SRCS) 16 | $(CC) $(FLAGS) -c $(SRCS) 17 | 18 | clean: 19 | rm $(OBJS) 20 | 21 | fclean: clean 22 | rm $(BIN) -------------------------------------------------------------------------------- /DAYS/C03/ex03/ft_strncat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strncat(char *dest, char *src, unsigned int nb) 4 | { 5 | int i; 6 | int j; 7 | 8 | i = 0; 9 | while(dest[i]) 10 | { 11 | i++; 12 | } 13 | j = 0; 14 | while(j < nb && src[j] != '\0') 15 | { 16 | dest[i + j] = src[j]; 17 | j++; 18 | } 19 | dest[i + j] = '\0'; 20 | return (dest); 21 | } 22 | -------------------------------------------------------------------------------- /DAYS/C10/ex01/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall -Wextra -Werror 3 | INCLUDES=-I./includes 4 | SRCS=$(wildcard srcs/*.c) 5 | OBJS=$(SRCS:.c=.o) 6 | BIN=ft_cat 7 | 8 | all: $(BIN) 9 | 10 | $(BIN): $(OBJS) 11 | $(CC) $(INCLUDES) $(FLAGS) $(OBJS) -o $(BIN) 12 | %.o: %.c ft_cat.h 13 | $(CC) $(FLAGS) -c $< -o $@ 14 | 15 | clean: 16 | rm -f $(OBJS) 17 | 18 | fclean: clean 19 | rm -f $(BIN) 20 | 21 | .PHONY: all clean fclean -------------------------------------------------------------------------------- /DAYS/C01/ex04/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 04: ft_ultimate_div_mod 2 | + Create a function **ft_ultimate_div_mod** with the following prototype: 3 | ```C 4 | void ft_ultimate_div_mod(int *a, int *b); 5 | ``` 6 | + This function divides parameters a by b. The result of this division is stored in the int pointed by a. The remainder of the division is stored in the int pointed by b. 7 | + Files to turn in: ft_ultimate_div_mod.c 8 | + Allowed functions: Nothing -------------------------------------------------------------------------------- /DAYS/C06/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03 : ft_sort_params 2 | 3 | - Turn-in directory : ex03/ 4 | - Files to turn in : ft_sort_params.c 5 | - Allowed functions : write 6 | • We’re dealing with a program here, you should therefore have a function main in 7 | your .c file. 8 | • Create a program that displays its given arguments sorted by ascii order. 9 | • It should display all arguments, except for argv[0]. 10 | • One argument per line -------------------------------------------------------------------------------- /DAYS/C10/ex00/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall -Wextra -Werror 3 | INCLUDES=-I includes 4 | SRCS=$(wildcard srcs/*) 5 | OBJS=$(notdir $(SRCS:.c=.o)) 6 | BIN=ft_display_file 7 | 8 | .PHONY: all clean fclean 9 | 10 | all: $(BIN) 11 | 12 | $(BIN): $(OBJS) 13 | $(CC) $(INCLUDES) $(FLAGS) $? -o $@ 14 | 15 | $(OBJS): $(SRCS) 16 | $(CC) $(FLAGS) -c $(SRCS) 17 | 18 | clean: 19 | rm $(OBJS) 20 | 21 | fclean: clean 22 | rm $(BIN) -------------------------------------------------------------------------------- /DAYS/C10/ex02/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall -Wextra -Werror 3 | INCLUDES=-I includes 4 | SRCS=$(wildcard srcs/*) 5 | OBJS=$(notdir $(SRCS:.c=.o)) 6 | BIN=ft_tail 7 | 8 | .PHONY: all clean fclean 9 | 10 | all: $(BIN) 11 | 12 | $(BIN): $(OBJS) 13 | $(CC) $(INCLUDES) $(FLAGS) -g $? -o $@ 14 | 15 | $(OBJS): $(SRCS) 16 | $(CC) $(FLAGS) -g -c $(SRCS) 17 | 18 | clean: 19 | rm $(OBJS) 20 | 21 | fclean: clean 22 | rm $(BIN) -------------------------------------------------------------------------------- /DAYS/C10/ex03/Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | FLAGS=-Wall -Wextra -Werror -g 3 | INCLUDES=-I includes 4 | SRCS=$(wildcard srcs/*) 5 | OBJS=$(notdir $(SRCS:.c=.o)) 6 | BIN=ft_hexdump 7 | 8 | .PHONY: all clean fclean 9 | 10 | all: $(BIN) 11 | 12 | $(BIN): $(OBJS) 13 | $(CC) $(INCLUDES) $(FLAGS) $? -o $@ 14 | 15 | $(OBJS): $(SRCS) 16 | $(CC) $(FLAGS) -c $(SRCS) 17 | 18 | clean: 19 | rm $(OBJS) 20 | 21 | fclean: clean 22 | rm $(BIN) -------------------------------------------------------------------------------- /DAYS/C05/ex00/ft_iterative_factorial.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_iterative_factorial(int nb) 4 | { 5 | int result; 6 | 7 | result = 1; 8 | 9 | while (nb > 0) 10 | { 11 | result *= nb; 12 | nb--; 13 | } 14 | if (nb < 0) 15 | { 16 | return(0); 17 | } 18 | return(result); 19 | } 20 | 21 | int main(void) 22 | { 23 | printf("%i", ft_iterative_factorial(5)); 24 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rev_print/rev_print.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | if (argc == 2) 8 | { 9 | while (argv[1][i]) 10 | i++; 11 | i--; 12 | while (i >= 0) 13 | { 14 | write(1, &argv[1][i], 1); 15 | i--; 16 | } 17 | write(1, "\n", 1); 18 | } 19 | write(1, "\n", 1); 20 | } -------------------------------------------------------------------------------- /DAYS/C01/ex05/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_putstr(char *str) 9 | { 10 | int i; 11 | 12 | i = 0; 13 | while (str[i] != '\0') 14 | { 15 | write(1, &str[i], 1); 16 | i++; 17 | } 18 | } 19 | 20 | int main() 21 | { 22 | char *c; 23 | c = "karim"; 24 | ft_putstr(c); 25 | 26 | return 0; 27 | } -------------------------------------------------------------------------------- /DAYS/C07/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01: ft_range 2 | - Create a function __ft_range__ which returns an array of __ints__. This int array should contain all values between __min__ and __max__. 3 | - __min__ included - __max__ excluded. 4 | - Here's how it should be prototyped: 5 | ```C 6 | int *ft_range(int min, int max); 7 | ``` 8 | - If __min__ value is greater or equal to __max__'s value, a null pointer should be returned. 9 | - Allowed functions: __malloc__ -------------------------------------------------------------------------------- /DAYS/Shell00/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Resources 2 | [Kerberos](https://www.roguelynn.com/words/explain-like-im-5-kerberos/?fbclid=IwAR25Mf4XjM1teYggK_4XNe9keDd3LC1jKWbstLcs_ibvgZEV_gOcyrq_xtE) 3 | [42 US Remote Vogsphere Access Setup](https://github.com/hanuprateek/42_US_vogsphere_access) 4 | 5 | [Taming Kerberos - Computerphile](https://www.youtube.com/watch?v=qW361k3-BtU) 6 | [Kerberos Authentication Explained | A deep dive](https://www.youtube.com/watch?v=5N242XcKAsM) -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/maff_alpha/maff_alpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | int main(void) 9 | { 10 | int x; 11 | 12 | x = 97; 13 | while(x <= 122) 14 | { 15 | if(x % 2 == 0) 16 | ft_putchar(x - 32); 17 | else 18 | ft_putchar(x); 19 | x++; 20 | } 21 | ft_putchar('\n'); 22 | 23 | return 0; 24 | } -------------------------------------------------------------------------------- /DAYS/C07/ex00/ft_strdup.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char *ft_strdup(char *src) 5 | { 6 | int i; 7 | char *duplicate; 8 | 9 | i = 0; 10 | while (src[i]) 11 | i++; 12 | duplicate = malloc((sizeof(char) * i) + 1); 13 | if (!duplicate) 14 | return (NULL); 15 | i = 0; 16 | while (src[i]) 17 | { 18 | duplicate[i] = src[i]; 19 | i++; 20 | } 21 | duplicate[i] = '\0'; 22 | return (duplicate); 23 | } 24 | -------------------------------------------------------------------------------- /DAYS/C06/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02 : ft_rev_params 2 | 3 | - Turn-in directory : ex02/ 4 | - Files to turn in : ft_rev_params.c 5 | - Allowed functions : write 6 | • We’re dealing with a program here, you should therefore have a function main in 7 | your .c file. 8 | • Create a program that displays its given arguments. 9 | • One per line, in the reverse order of the command line. 10 | • It should display all arguments, except for argv[0]. 11 | -------------------------------------------------------------------------------- /DAYS/C07/ex02/ft_ultimate_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ft_ultimate_range(int **range, int min, int max) 5 | { 6 | int i; 7 | int size; 8 | 9 | i = 0; 10 | size = max - min; 11 | if (min >= max) 12 | { 13 | *range = NULL; 14 | return (0); 15 | } 16 | *range = malloc(sizeof(int) * size); 17 | while (min < max) 18 | { 19 | (*range)[i] = min; 20 | i++; 21 | min++; 22 | } 23 | return (size); 24 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_z/aff_z.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | if (argc == 2) 10 | while (argv[1][i]) 11 | { 12 | if (argv[1][i] = 'z') 13 | { 14 | write(1, "z\n", 2); 15 | break; 16 | } 17 | i++; 18 | } 19 | else 20 | write(1, "z\n", 2); 21 | 22 | return 0; 23 | } -------------------------------------------------------------------------------- /DAYS/C05/ex05/ft_sqrt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_sqrt(int nb) 4 | { 5 | long index; 6 | long b; 7 | 8 | b = nb; 9 | if (b <= 0) 10 | { 11 | return (0); 12 | } 13 | if (b == 1) 14 | { 15 | return (1); 16 | } 17 | index = 2; 18 | if (b >= 2) 19 | { 20 | while (index * index <= b) 21 | { 22 | if (index * index == b) 23 | { 24 | return (index); 25 | } 26 | index++; 27 | } 28 | } 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /DAYS/C00/ex06/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 06 2 | * Create a function that displays all different combinations of two digits between 00 and 99, listed by ascending order. 3 | * Here's the expected output: 4 | ``` 5 | $>./a.out | cat -e 6 | 00 01, 00 02, 00 03, 00 04, 00 05, ..., 00 99, 01 02, ..., 97 99, 98 99$> 7 | ``` 8 | * Here's how it should be prototyped: 9 | ```C 10 | void ft_print_comb2(void); 11 | ``` 12 | + Files to turn in: ft_print_comb2.c 13 | + Allowed functions: ft_putchar -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_atoi/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : ft_atoi 2 | Expected files : ft_atoi.c 3 | Allowed functions: None 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a function that converts the string argument str to an integer (type int) 7 | and returns it. 8 | 9 | It works much like the standard atoi(const char *str) function, see the man. 10 | 11 | Your function must be declared as follows: 12 | 13 | int ft_atoi(const char *str); -------------------------------------------------------------------------------- /DAYS/C05/ex06/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 06: ft_is_prime 2 | - Create a function that returns 1 if the number given as a parameter is a prime number, and 0 if it isn't. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_is_prime(int nb); 6 | ``` 7 | - Your function must return its result in less than two seconds. 8 | - **HINT**: 0 and 1 are not prime numbers. 9 | 10 | ## Understanding Prime Numbers 11 | - Prime number is a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11). -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/main.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | int main(int ac, char **av) 4 | { 5 | int i; 6 | int return_value; 7 | int bytes; 8 | 9 | i = 1; 10 | bytes = 0; 11 | return_value = 0; 12 | if (ac == 1) 13 | stdin_to_stdout(); 14 | else 15 | { 16 | bytes = check_flag(av); 17 | if (bytes) 18 | i = 3; 19 | else if (bytes == -1) 20 | return (bytes); 21 | while (i < ac) 22 | ft_tail(ac, bytes, av[i++]); 23 | } 24 | return (return_value); 25 | } -------------------------------------------------------------------------------- /DAYS/C01/ex07/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 07: 2 | ### ft_rev_int_tab 3 | 4 | + Create a function which reverses a given array of integers (first goes last, etc). 5 | + The arguments are a pointer to int and the number of ints in the array. 6 | + Here's how it should be prototyped: 7 | ```C 8 | void ft_rev_int_tab(int *tab, int size); 9 | ``` 10 | + Files to turn in: ft_rev_int_tab.c 11 | + Allowed functions: None 12 | 13 | + Example: 14 | ``` 15 | a => a 16 | ab => ba 17 | abcde => edcba 18 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/only_a/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-1-only_a.txt==================================== 5 | Assignment name : only_a 6 | Expected files : only_a.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays a 'a' character on the standard output. 11 | ========================================================================================== 12 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/only_z/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-1-only_z.txt==================================== 5 | Assignment name : only_z 6 | Expected files : only_z.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays a 'z' character on the standard output. 11 | ========================================================================================== 12 | ``` -------------------------------------------------------------------------------- /DAYS/C10/ex04/test/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int fd; 9 | struct utmp cr; 10 | int reclen = sizeof(struct utmp); 11 | 12 | fd = open(_PATH_UTMP, O_RDONLY); 13 | if (fd == -1){ 14 | perror("oops"); 15 | return(1); 16 | } 17 | while (read(fd, &cr, reclen) == reclen) 18 | printf("-- %s\n", cr.ut_host); 19 | 20 | close (fd); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /DAYS/C02/ex09/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 10: ft_strcapitalize 2 | - Create a function that capitalize the first letter of each word and transforms all other letter to lowercase. 3 | - A word is a string of alphanumeric characters. 4 | - Here's how it should be prototyped: 5 | ```C 6 | char *ft_strcapitalize(char *str); 7 | ``` 8 | - It should return __str__. 9 | - For example: 10 | > salut, comment tu vas ? 1337mots quanate-deux; cinquante+et+un 11 | - Becomes: 12 | > Salut, Comment Tu Vas ? 1337mots Quarante-Deux; Cinuante+Et+Un -------------------------------------------------------------------------------- /DAYS/C10/ex01/srcs/ft_cat.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_cat.h" 2 | #include 3 | 4 | void ft_cat(char *file_name) 5 | { 6 | int fd; 7 | char buf[29000]; 8 | int ret; 9 | 10 | errno = 0; 11 | fd = open(file_name, O_RDWR); 12 | if (errno) 13 | { 14 | ft_putstr("ft_cat: "); 15 | ft_putstr(basename(file_name)); 16 | ft_putstr(": "); 17 | ft_putstr(strerror(errno)); 18 | write(1, "\n", 1); 19 | return ; 20 | } 21 | ret = read(fd, buf, 29000); 22 | write(1, buf, ret); 23 | close(fd); 24 | } -------------------------------------------------------------------------------- /DAYS/C10/ex02/includes/ft_tail.h: -------------------------------------------------------------------------------- 1 | #ifndef FT_TAIL_H 2 | #define FT_TAIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | void ft_tail(int ac, int bytes, char *file); 10 | void show_file_name(int ac, int bytes, char *filename); 11 | char *ft_strncpy(char *dest, char *src, unsigned int n); 12 | void stdin_to_stdout(void); 13 | int check_flag(char **av); 14 | int ft_strlen(char *str); 15 | int ft_atoi(char *str); 16 | int get_tail_index(char *file); 17 | 18 | #endif -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/ft_atoi.c: -------------------------------------------------------------------------------- 1 | int ft_atoi(char *str) 2 | { 3 | int number; 4 | int sign; 5 | int i; 6 | 7 | sign = 1; 8 | number = 0; 9 | i = 0; 10 | while (str[i] == ' ' || str[i] == '\n' || str[i] == '\t'|| 11 | str[i] == '\r' || str[i] == '\v' || str[i] == '\f') 12 | i++; 13 | if (str[i] == '-') 14 | { 15 | sign = -1; 16 | i++; 17 | } 18 | else if (str[i] == '+') 19 | i++; 20 | while (str[i] >= '0' && str[i] <= '9') 21 | number = (number * 10) + str[i++] - '0'; 22 | return (number * sign); 23 | } -------------------------------------------------------------------------------- /DAYS/C03/ex04/ft_strstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | char *ft_strstr(char *str, char *to_find) 6 | { 7 | int i; 8 | int j; 9 | 10 | i = 0; 11 | j = 0; 12 | 13 | if (to_find[j] == '\0') 14 | return(str); 15 | while (str[i]) 16 | { 17 | while (str[i + j] == to_find[j] && str[i + j] != '\0') 18 | j++; 19 | if (to_find[j] == '\0') 20 | return(str + i); 21 | i++; 22 | j = 0; 23 | } 24 | return(0); 25 | } 26 | -------------------------------------------------------------------------------- /DAYS/C08/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 05: ft_show_tab 2 | - Create a function that displays the content of the array created by the previous function. 3 | - Here's how it should be prototyped: 4 | ```C 5 | void ft_show_tab(struct s_stock_par *par); 6 | ``` 7 | - The structure will be the same as the previous exercise and will be defined in the __ft_stock_str.h__ file. 8 | - For each box, we'll display: 9 | - the string followed by '\n' 10 | - the size followed by '\n' 11 | - the copy of the string (that could have been modified) followed by '\n' -------------------------------------------------------------------------------- /DAYS/C02/ex06/ft_str_is_printable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_str_is_printable(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(str[i]) 10 | { 11 | if (str[i] >= 31 && str[i] <= 126) 12 | i++; 13 | else 14 | return(0); 15 | } 16 | return(1); 17 | } 18 | 19 | int main() 20 | { 21 | printf("%d", ft_str_is_printable("ABdDCDEE")); 22 | printf("\n%d", ft_str_is_printable("abcAdefghijkl")); 23 | printf("\n%d", ft_str_is_printable("-_134556efSghij67")); 24 | } -------------------------------------------------------------------------------- /DAYS/C03/ex02/ft_strcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | char *ft_strcat(char *dest, char *src) 4 | { 5 | int i; 6 | int j; 7 | 8 | i = 0; 9 | 10 | while(dest[i]) 11 | { 12 | i++; 13 | } 14 | j = 0; 15 | while(src[j]) 16 | { 17 | dest[i] = src[j]; 18 | i++; 19 | j++; 20 | } 21 | dest[i] = '\0'; 22 | return(dest); 23 | } 24 | 25 | int main() 26 | { 27 | char dest[] = "hello "; 28 | char src[] = "karim"; 29 | printf("%s", ft_strcat(dest, src)); 30 | } -------------------------------------------------------------------------------- /DAYS/C09/ex01/makefile: -------------------------------------------------------------------------------- 1 | CC=GCC 2 | FLAGS = -Wall -Werror -Wextra -I./includes 3 | AR=ar crs 4 | RM=rm -rf 5 | FILES = srcs/ft_putchar srcs/ft_strcmp \ 6 | srcs/ft_putstr srcs/ft_swap srcs/ft_strlen 7 | SRC = $(FILES:=.c) 8 | OBJ = $(FILES:=.o) 9 | LIB=libft.a 10 | 11 | .PHONY: all clean fclean re 12 | 13 | all: $(LIB) 14 | 15 | $(LIB): $(OBJ) 16 | $(AR) $(LIB) $(OBJ) 17 | 18 | %.o: %.c 19 | $(CC) $(FLAGS) -c $< -o $@ 20 | 21 | clean: 22 | $(RM) $(OBJ) 23 | 24 | fclean: clean 25 | $(RM) $(LIB) 26 | 27 | re: fclean all 28 | -------------------------------------------------------------------------------- /DAYS/C10/ex04/test/test2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | int main(int argc, char **argv){ 8 | struct utmp data; 9 | FILE *log_file = fopen(_PATH_UTMP, "r"); 10 | memset(&data, 0, sizeof(struct utmp)); 11 | 12 | while(fread(&data, sizeof(struct utmpx), 1, log_file) == 1){ 13 | printf("Read a record , User : %s\n", data.ut_user); 14 | } 15 | fclose(log_file); 16 | return EXIT_SUCCESS; 17 | } -------------------------------------------------------------------------------- /DAYS/C02/ex04/ft_str_is_lowercase.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_str_is_lowercase(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while(str[i]) 10 | { 11 | if (str[i] >= 'a' && str[i] <= 'z') 12 | i++; 13 | else 14 | return(0); 15 | } 16 | return(1); 17 | } 18 | 19 | int main() 20 | { 21 | printf("%d", ft_str_is_lowercase("abcdefghijkl")); 22 | printf("\n%d", ft_str_is_lowercase("abcAdefghijkl")); 23 | printf("\n%d", ft_str_is_lowercase("-_134556efSghij67")); 24 | } -------------------------------------------------------------------------------- /DAYS/C06/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01 : ft_print_params 2 | 3 | - Turn-in directory : ex01/ 4 | - Files to turn in : ft_print_params.c 5 | - Allowed functions : write 6 | • We’re dealing with a program here, you should therefore have a function main in 7 | your .c file. 8 | • Create a program that displays its given arguments. 9 | • One per line, in the same order as in the command line. 10 | • It should display all arguments, except for argv[0]. 11 | • Example : 12 | ```$>./a.out test1 test2 test3 | cat -e 13 | test1$ 14 | test2$ 15 | test3$ 16 | $> 17 | -------------------------------------------------------------------------------- /DAYS/C02/ex03/ft_str_is_numeric.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | 5 | int ft_str_is_numeric(char *str) 6 | { 7 | int i; 8 | 9 | i = 0; 10 | 11 | while(str[i]) 12 | { 13 | if (str[i] >= '0' && str[i] <= '9') 14 | i++; 15 | else 16 | return (0); 17 | } 18 | return (1); 19 | } 20 | 21 | int main() 22 | { 23 | printf("%d", ft_str_is_numeric("01948987493")); 24 | printf("\n%d", ft_str_is_numeric("0484882j8995489")); 25 | printf("\n%d", ft_str_is_numeric("-_jsdsdc67sdlkc,")); 26 | } -------------------------------------------------------------------------------- /DAYS/C02/ex05/ft_str_is_uppercase.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ft_str_is_uppercase(char *str) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | 10 | while(str[i]) 11 | { 12 | if (str[i] >= 'A' && str[i] <= 'Z') 13 | i++; 14 | else 15 | return(0); 16 | } 17 | return(1); 18 | } 19 | 20 | int main() 21 | { 22 | printf("%d", ft_str_is_uppercase("ABdDCDEE")); 23 | printf("\n%d", ft_str_is_uppercase("abcAdefghijkl")); 24 | printf("\n%d", ft_str_is_uppercase("-_134556efSghij67")); 25 | } -------------------------------------------------------------------------------- /DAYS/C02/ex10/ft_strlcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | unsigned int ft_strlcpy(char *dest, char *src, unsigned int size) 5 | { 6 | unsigned int len_src; 7 | unsigned int i; 8 | 9 | len_src = 0; 10 | i = 0; 11 | 12 | while (src[i]) 13 | { 14 | len_src++; 15 | i++; 16 | } 17 | if (size == 0) 18 | return (len_src); 19 | i = 0; 20 | while (src[i] && i < size - 1) 21 | { 22 | dest[i] = src[i]; 23 | i++; 24 | } 25 | dest[i] = '\0'; 26 | return (len_src); 27 | } -------------------------------------------------------------------------------- /DAYS/C07/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: ft_ultimate_range 2 | - Create a function __ft_ultimate_range__ which allocates and assigns an array of __ints__. This __int__ array should contain all values between __min__ and __max__. 3 | - __min__ included - __max__ excluded. 4 | - Here's how it should be prototyped: 5 | ```C 6 | int ft_ultimate_range(int **range, int min, int max); 7 | ``` 8 | - If the value if __min__ is greater or equal to __max__'s value, __range__ will point on __NULL__. 9 | - The size of the __range__ should be returned (or 0 on error). 10 | - Allowed functions: __malloc__ 11 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_strlen/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-0-ft_strlen.txt================================= 5 | Assignment name : ft_strlen 6 | Expected files : ft_strlen.c 7 | Allowed functions: 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a function that returns the length of a string. 11 | 12 | Your function must be declared as follows: 13 | 14 | int ft_strlen(char *str); 15 | ========================================================================================== 16 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rotone/rotone.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | 8 | if (argc == 2) 9 | { 10 | i = 0; 11 | while(argv[1][i]) 12 | { 13 | if ((argv[1][i] == 'z') || (argv[1][i] == 'Z')) 14 | argv[1][i] -= 25; 15 | else if ((argv[1][i] >= 'a' && argv[1][i] <= 'z') || (argv[1][i] >= 'A' && argv[1][i] == 'Z')) 16 | argv[1][i] += 1; 17 | write(1, &argv[1][i], 1); 18 | i++; 19 | } 20 | } 21 | write(1, "\n", 1); 22 | } -------------------------------------------------------------------------------- /DAYS/C00/ex07/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_putnbr(int nb) 9 | { 10 | if (nb == -2147483648) 11 | { 12 | ft_putchar('-'); 13 | ft_putchar('2'); 14 | ft_putnbr(147483648); 15 | } 16 | if (nb < 0) 17 | { 18 | ft_putchar('-'); 19 | nb = -nb; 20 | ft_putnbr(nb); 21 | } 22 | else if (nb > 9) 23 | { 24 | ft_putnbr(nb / 10); 25 | ft_putnbr(nb % 10); 26 | } 27 | else 28 | ft_putchar(nb + 48); 29 | } 30 | 31 | int main() 32 | { 33 | ft_putnbr(235353345); 34 | 35 | return 0; 36 | } -------------------------------------------------------------------------------- /DAYS/C04/ex02/ft_putnbr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_putnbr(int nb) 9 | { 10 | if (nb == -2147483648) 11 | { 12 | ft_putchar('-'); 13 | ft_putchar('2'); 14 | ft_putnbr('147483648'); 15 | } 16 | if (nb < 0) 17 | { 18 | ft_putchar('-'); 19 | nb *= -1; 20 | ft_putnbr(nb); 21 | } 22 | if (nb > 9) 23 | { 24 | ft_putnbr(nb /10); 25 | ft_putnbr(nb % 10); 26 | } 27 | else 28 | ft_putchar(nb + 48); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/hello/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-0-hello.txt===================================== 5 | Assignment name : hello 6 | Expected files : hello.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays "Hello World!" followed by a \n. 11 | 12 | Example: 13 | 14 | $>./hello 15 | Hello World! 16 | $>./hello | cat -e 17 | Hello World!$ 18 | $> 19 | ========================================================================================== 20 | ``` -------------------------------------------------------------------------------- /DAYS/C02/ex02/ft_str_is_alpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ft_str_is_alpha(char *str) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | if (str[i] == '\0' ) 10 | { 11 | return (1); 12 | } 13 | while (str[i] != '\0') 14 | { 15 | if ((str[i] >= 'A' && str [i] <= 'Z') || (str [i] >= 'a' && str [i] <= 'z')) 16 | i++; 17 | else 18 | return (0); 19 | } 20 | return (1); 21 | } 22 | int main() 23 | { 24 | printf("%d", ft_str_is_alpha("abcdefghijkl")); 25 | printf("\n%d", ft_str_is_alpha("abc1defghijkl")); 26 | printf("\n%d", ft_str_is_alpha("-_134556efghij67")); 27 | } 28 | -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_putaddr.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | void ft_putnbr_base(int nbr, int nbase) 4 | { 5 | char *base = "0123456789abcdef"; 6 | 7 | if (nbr >= nbase) 8 | ft_putnbr_base(nbr / nbase, nbase); 9 | ft_putchar(base[nbr % nbase]); 10 | } 11 | 12 | void ft_putaddr(int nbr, int flag) 13 | { 14 | int i; 15 | int len; 16 | 17 | len = 2; 18 | if (flag) 19 | len = flag; 20 | i = nbr; 21 | while (i /= 16) 22 | len++; 23 | while (i++ < 8 - len) 24 | ft_putchar('0'); 25 | ft_putnbr_base(nbr, 16); 26 | if (flag == 1) 27 | ft_putchar(' '); 28 | ft_putchar(' '); 29 | } -------------------------------------------------------------------------------- /DAYS/Shell01/ex06/README.md: -------------------------------------------------------------------------------- 1 | # Exercise 06: Skip 2 | 3 | - Write a command line that displays every other line for the command ls -l, starting from the first line. 4 | 5 | ------------------------------------------ 6 | ## We can use `ls` in combination with `awk` for this: 7 | * First we use the command `ls -l` to display all contents on the current 8 | directory in a list format, then pass the results forward using pipe `|` for 9 | `awk` with the option: 10 | NR → The total number of input records seen so far. 11 | And the `% 2 == 1` to print every second line counting from line 0. 12 | ``` 13 | ls -l | awk 'NR % 2 == 1' 14 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/ft_print_numbers/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-0-ft_print_numbers.txt========================== 5 | Assignment name : ft_print_numbers 6 | Expected files : ft_print_numbers.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a function that displays all digits in ascending order. 11 | 12 | Your function must be declared as follows: 13 | 14 | void ft_print_numbers(void); 15 | 16 | ========================================================================================== 17 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_swap/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-2-ft_swap.txt=================================== 5 | Assignment name : ft_swap 6 | Expected files : ft_swap.c 7 | Allowed functions: 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a function that swaps the contents of two integers the adresses of which 11 | are passed as parameters. 12 | 13 | Your function must be declared as follows: 14 | 15 | void ft_swap(int *a, int *b); 16 | ========================================================================================== 17 | ``` -------------------------------------------------------------------------------- /DAYS/C05/ex07/ft_find_next_prime.c: -------------------------------------------------------------------------------- 1 | int ft_is_prime(int nb) 2 | { 3 | int i; 4 | 5 | i = 2; 6 | if (nb < 2) 7 | return (0); 8 | if (nb > 2147483640 && nb >= 2147483647) 9 | return (2147483647); 10 | while (i <= nb / 2) 11 | { 12 | if (nb % i == 0) 13 | return (0); 14 | i++; 15 | } 16 | return (1); 17 | } 18 | 19 | int ft_find_next_prime(int nb) 20 | { 21 | while (!ft_is_prime(nb)) 22 | nb++; 23 | return (nb); 24 | } 25 | 26 | /* 27 | * Note: or 28 | * Step 1 - take square root of nb (sqrt(nb) + 1) 29 | * Step 2 - divide nb by numbers greter than 2 and less than or 30 | * equal to (sqrt(nb) + 1); 31 | */ -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ulstr/ulstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | if (argc == 2) 8 | { 9 | i = 0; 10 | while (argv[1][i]) 11 | { 12 | if (argv[1][i] >= 'a' && argv[1][i] <= 'z') 13 | { 14 | argv[1][i] -= 32; 15 | } 16 | else if (argv[1][i] >= 'A' && argv[1][i] <= 'Z') 17 | { 18 | argv[1][i] += 32; 19 | } 20 | write(1, &argv[1][i], 1); 21 | i++; 22 | } 23 | } 24 | else 25 | write(1, "\n", 1); 26 | } -------------------------------------------------------------------------------- /DAYS/C02/ex11/ft_putstr_non_printable.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | int ft_char_is_printable(char c) 9 | { 10 | if (c >= 32 && c <= 126) 11 | return (1); 12 | else 13 | return (0); 14 | } 15 | 16 | void ft_putstr_non_printable(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | while (str[i] != '\0') 22 | { 23 | if (ft_char_is_printable(str[i]) == 1) 24 | ft_putchar(str[i]); 25 | else 26 | { 27 | ft_putchar('\\'); 28 | ft_putchar("0123456789abcdef"[str[i] / 16]); 29 | ft_putchar("0123456789abcdef"[str[i] % 16]); 30 | } 31 | i++; 32 | } 33 | } -------------------------------------------------------------------------------- /DAYS/C10/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01: cat 2 | 3 | - Create a "program" called `ft_cat` which does the same thing as the system's `cat` command-line. 4 | - You don't have to handle options. 5 | - The submission directory should have a `Makefile` with the following rules: `all`, `clean`, `fclean` 6 | - You may use the variable `errno` (check `man errno`) 7 | - You can only do this exercise by declaring a fixed-sized array. This array will have a size limited to a little less than `30ko`. In order to test that size-limit, use the `limit` command-line in your `Shell` 8 | ``` 9 | $> limit stacksize 32 10 | $> limit stacksize 11 | stacksize 32 kbytes 12 | $> 13 | ``` -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/main.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | int main(int ac, char **av) 4 | { 5 | char *str; 6 | int size; 7 | int flag; 8 | int i; 9 | 10 | size = 0; 11 | str = 0; 12 | i = 1; 13 | if (ac > 1) 14 | { 15 | flag = check_flag(av); 16 | if (flag == -1) 17 | return (flag); 18 | else if (flag) 19 | i = 2; 20 | while (i < ac) 21 | { 22 | str = get_content(av[i]); 23 | if (str && flag >= 0) 24 | { 25 | size = ft_strlen(str); 26 | ft_hexdump(str, size, flag); 27 | free(str); 28 | } 29 | i++; 30 | } 31 | } 32 | else 33 | write(2, "usage: ft_hexdump [ -C ] file ...\n", 35); 34 | return (0); 35 | } -------------------------------------------------------------------------------- /DAYS/C00/ex08/ft_print_combn.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_combn(char *num, int num_size, int index, char digit) 4 | { 5 | if (index == num_size) 6 | { 7 | write(1, num, num_size); 8 | if (num[0] - '0' < 10 - num_size) 9 | write(1, ", ", 2); 10 | } 11 | else 12 | { 13 | while (digit - '0' <= (10 - num_size) + index) 14 | { 15 | num[index] = digit; 16 | print_combn(num, num_size, index + 1, digit + 1); 17 | digit++; 18 | } 19 | } 20 | } 21 | 22 | void ft_print_combn(int n) 23 | { 24 | char num[9]; 25 | 26 | if (n > 0 && n < 10) 27 | print_combn(num, n, 0, '0'); 28 | } 29 | 30 | int main(void) 31 | { 32 | ft_print_combn(5); 33 | } -------------------------------------------------------------------------------- /DAYS/C07/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 05: ft_split 2 | - Create a function that split a string of character depending on another string of characters. 3 | - You'll have to use each character from the string __charset__ as a separator. 4 | - The function returns an array where each box contains the address of a string wrapped between two separators. The last element of the array should equal to 0 to indicate the end of the array. 5 | - There cannot be any empty strings in your array. Draw your conclusions accordingly. 6 | - The string given as argument won't be modifiable. 7 | - Here's how it should be prototyped: 8 | ```C 9 | char **ft_split(char *str, char *charset); 10 | ``` 11 | - Allowed functions: malloc -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/maff_revalpha/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-1-maff_revalpha.txt============================= 5 | Assignment name : maff_revalpha 6 | Expected files : maff_revalpha.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays the alphabet in reverse, with even letters in 11 | uppercase, and odd letters in lowercase, followed by a newline. 12 | 13 | Example: 14 | 15 | $> ./maff_revalpha | cat -e 16 | zYxWvUtSrQpOnMlKjIhGfEdCbA$ 17 | ========================================================================================== 18 | ``` -------------------------------------------------------------------------------- /DAYS/Shell00/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 00 2 | 3 | * Create a file called **z** that returns "Z", followed by a new line, whenever the command cat is used on it. 4 | ``` 5 | ?>cat z Z 6 | ?> 7 | ``` 8 | 9 | ## Ok this Exercise is kind of a joke... 10 | 11 | Because if we read the `man cat` page we see that this command just 12 | *"concatenate files and print on the standard output"*. So is going to print 13 | whatever we put inside the target file **z**, and in this case is only needed to 14 | put a simple '**Z**' inside our file, using vim or nano. 15 | You can also use echo command and redirection to redirect the character z inside the file Z. 16 | 17 | Example: 18 | ```sh 19 | echo "Z" > z 20 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/fizzbuzz/fizzbuzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_printnbr(int i) 4 | { 5 | if (i >= 10) 6 | ft_printnbr(i / 10); 7 | i = (i % 10 + '0'); 8 | write(1, &i, 1); 9 | } 10 | 11 | int main(void) 12 | { 13 | int nbr; 14 | 15 | nbr = 1; 16 | 17 | while(nbr <= 100) 18 | { 19 | if ((nbr % 3 == 0) && (nbr % 5 == 0)) 20 | write(1, "fizzbuzz", 8); 21 | else if (nbr % 3 == 0) 22 | write(1, "fizz", 4); 23 | else if (nbr % 5 == 0) 24 | write(1, "buzz", 4); 25 | else 26 | ft_printnbr(nbr); 27 | write(1, "\n", 1); 28 | nbr++; 29 | } 30 | return 0; 31 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_putstr/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-2-ft_putstr.txt================================= 5 | Assignment name : ft_putstr 6 | Expected files : ft_putstr.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a function that displays a string on the standard output. 11 | 12 | The pointer passed to the function contains the address of the string's first 13 | character. 14 | 15 | Your function must be declared as follows: 16 | 17 | void ft_putstr(char *str); 18 | ========================================================================================== 19 | ``` -------------------------------------------------------------------------------- /DAYS/C03/ex05/ft_strlcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strlen(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i]) 9 | { 10 | i++; 11 | } 12 | return(i); 13 | } 14 | 15 | unsigned int ft_strlcat(char *dest, char *src, unsigned int size) 16 | { 17 | int i; 18 | int j; 19 | int dlen; 20 | int slen; 21 | 22 | i = 0; 23 | j = 0; 24 | while (dest[j]) 25 | { 26 | j++; 27 | } 28 | dlen = j; 29 | slen = ft_strlen(src); 30 | if (size == 0 || size < dlen) 31 | return (slen + size); 32 | while (src[i] != '\0' && i < size - dlen - 1) 33 | { 34 | dest[j] = src[i]; 35 | i++; 36 | j++; 37 | } 38 | dest[j] = '\0'; 39 | return (dlen + slen); 40 | } 41 | -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_puthex.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | void ft_puthex(char *str, int index, int flag) 4 | { 5 | char *hex = "0123456789abcdef"; 6 | 7 | int byte = 0; 8 | while (byte < 16) 9 | { 10 | if (str[byte + index] == '\0') 11 | write(STDOUT_FILENO, " ", 2); 12 | else if (str[byte] > 16) 13 | { 14 | ft_putchar(hex[str[byte + index] / 16]); 15 | ft_putchar(hex[str[byte + index] % 16]); 16 | } 17 | else 18 | { 19 | ft_putchar('0'); 20 | ft_putchar(hex[str[byte + index] % 16]); 21 | } 22 | byte++; 23 | ft_putchar(' '); 24 | if (byte == 8 && flag) 25 | write(STDOUT_FILENO, " ", 1); 26 | } 27 | if (flag) 28 | ft_putchar(' '); 29 | } -------------------------------------------------------------------------------- /DAYS/Shell01/ex07/README.md: -------------------------------------------------------------------------------- 1 | # Exercise 07: r_dwssap 2 | 3 | - Write a command line that displays the output of a cat /etc/passwd command, removing comments, every other line starting from the second line, reversing each lo- gin, sorted in reverse alphabetical order, and keeping only logins between FT_LINE1 and FT_LINE2 included, and they must separated by ", " (without quotation marks), and the output must end with a ".". 4 | 5 | - Example: Between lines 8 and 16, the result should be something like this: 6 | ``` 7 | $> ./r_dwssap.sh 8 | sstq_, sorebrek_brk_, soibten_, sergtsop_, scodved_, rlaxcm_, rgmecived_, revreswodniw_, revressta_ 9 | .$> 10 | ``` 11 | 12 | HINT: Rigorously follow the order indicated in the instructions. -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/get_tail_index.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | int get_tail_index(char *buf) 4 | { 5 | int lines; 6 | int i; 7 | int li; 8 | 9 | lines = 0; 10 | li = 0; 11 | i = 0; 12 | while (buf[i]) 13 | if (buf[i++] == '\n') 14 | lines++; 15 | i = 0; 16 | while (buf[i] && li < (lines - 10)) 17 | if (buf[i++] == '\n') 18 | li++; 19 | return (i); 20 | } 21 | 22 | /* 23 | int count_bytes(char *filename) 24 | { 25 | char buf; 26 | int fd; 27 | int lines; 28 | 29 | lines = 0; 30 | fd = open(filename, O_RDONLY); 31 | if (fd == -1) 32 | return (errno); 33 | while (read(fd, &buf, 1)) 34 | if (buf == '\n') 35 | lines++; 36 | close(fd); 37 | return (lines); 38 | } 39 | */ -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/ft_putstr.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | int ft_putstr(char *str, int index, int size, int flag) 4 | { 5 | int done; 6 | int byte; 7 | int i; 8 | 9 | byte = 0; 10 | done = 0; 11 | if (flag == 0) 12 | return (16); 13 | ft_putchar('|'); 14 | while (byte < 16) 15 | { 16 | i = index + byte; 17 | if (str[i] == '\0') 18 | { 19 | done = 1; 20 | break; 21 | } 22 | if ((str[i] >= '!' && str[i] <= '~') || str[i] == ' ') 23 | ft_putchar(str[i]); 24 | else 25 | ft_putchar('.'); 26 | byte++; 27 | } 28 | ft_putchar('|'); 29 | if (done) 30 | { 31 | ft_putchar('\n'); 32 | ft_putaddr(size, flag); 33 | return (size); 34 | } 35 | return (byte); 36 | } -------------------------------------------------------------------------------- /DAYS/C02/ex09/ft_strcapitalize.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char *ft_strlowcase(char *str) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | while (str[i]) 10 | { 11 | if (str[i] >= 65 && str[i] <= 90) 12 | { 13 | str[i] += 32; 14 | } 15 | i++; 16 | } 17 | return (str); 18 | } 19 | 20 | char *ft_strcapitalize(char *str) 21 | { 22 | int i; 23 | int x; 24 | 25 | i = 0; 26 | x = 1; 27 | ft_strlowcase(str); 28 | while (str[i]) 29 | { 30 | if (str[i] >= 97 && str[i] <= 122) 31 | { 32 | if (x == 1) 33 | str[i] -= 32; 34 | x = 0; 35 | } 36 | else if (str[i] >= '0' && str[i] <= '9') 37 | x = 0; 38 | else 39 | x = 1; 40 | i++; 41 | } 42 | return (str); 43 | } -------------------------------------------------------------------------------- /DAYS/C04/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 05 : ft_atoi_base 2 | 3 | - Turn-in directory : ex05/ 4 | - Files to turn in : ft_atoi_base.c 5 | - Allowed functions : None 6 | • Write a function that converts the initial portion of the string pointed by str to int 7 | representation. 8 | • str is in a specific base given as a second parameter. 9 | • excepted the base rule, the function should work exactly like ft_atoi. 10 | • If there’s an invalid argument, the function should return 0. Examples of invalid 11 | arguments : 12 | ◦ base is empty or size of 1; 13 | ◦ base contains the same character twice ; 14 | ◦ base contains + or - or whitespaces; 15 | • Here’s how it should be prototyped : 16 | ```int ft_atoi_base(char *str, char *base);`` 17 | -------------------------------------------------------------------------------- /DAYS/C01/ex07/ft_rev_int_tab.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | 9 | void ft_rev_int_tab(int *tab, int size) 10 | { 11 | int first; 12 | int last; 13 | int tmp; 14 | 15 | first = 0; 16 | last = size - 1; 17 | 18 | while (first < last) 19 | { 20 | tmp = tab[first]; 21 | tab[first] = tab[last]; 22 | tab[last] = tmp; 23 | first++; 24 | last--; 25 | } 26 | 27 | } 28 | 29 | int main(int i) 30 | { 31 | int arr[5] = {1,2,3,4,5}; 32 | 33 | ft_rev_int_tab(arr, 5); 34 | 35 | for(i = 0; i < 5; i++) 36 | { 37 | ft_putchar(arr[i] + '0'); 38 | } 39 | 40 | return 0; 41 | } -------------------------------------------------------------------------------- /DAYS/C09/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 00: libft 2 | - Create your __ft__ library. It'll be called __libft.a__. 3 | - A shell script called __libft_creator.sh__ will compile source files appropriately and will create your library. 4 | - This library should contain __all__ of the following functions: 5 | ```C 6 | void ft_putchar(char c); 7 | void ft_swap(int *a, int *b); 8 | void ft_putstr(char *str); 9 | int ft_strlen(char *str); 10 | int ft_strcmp(char *s1, char *s2); 11 | ``` 12 | - We'll launch the following command-line: 13 | ```sh 14 | sh libft_creator.sh 15 | ``` 16 | - Allowed functions: __write__ 17 | - Files to turn in: libft_creator.sh, ft_putchar.c, ft_swap.c, ft_putstr.c, ft_strlen.c, ft_strcmp.c 18 | - Hint: Don't hesitate to add other useful functions... ;-) -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/inter/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : inter 2 | Expected files : inter.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes two strings and displays, without doubles, the 7 | characters that appear in both strings, in the order they appear in the first 8 | one. 9 | 10 | The display will be followed by a \n. 11 | 12 | If the number of arguments is not 2, the program displays \n. 13 | 14 | Examples: 15 | 16 | $>./inter "padinton" "paqefwtdjetyiytjneytjoeyjnejeyj" | cat -e 17 | padinto$ 18 | $>./inter ddf6vewg64f gtwthgdwthdwfteewhrtag6h4ffdhsd | cat -e 19 | df6ewg4$ 20 | $>./inter "rien" "cette phrase ne cache rien" | cat -e 21 | rien$ 22 | $>./inter | cat -e 23 | $ -------------------------------------------------------------------------------- /DAYS/C00/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 00 2 | * Write a function that displays characters passed as parameter. 3 | * This is how it should be prototyped: 4 | ```C 5 | void ft_putchar(char c); 6 | ``` 7 | * Files to turn in: ft_putchar.c 8 | * Allowed function: write 9 | 10 | ### write() 11 | - write(2): the write function takes 3 parameters 12 | 13 | I. file descriptor\ 14 | II. address to a buffer\ 15 | III. count 16 | 17 | - 1. There is 3 types of file descriptor: 18 | * 0 standart input. 19 | * 1 standard output. 20 | * 2 standart error. 21 | - 2. Address in memory that points to a string (if we write the string directly, the compiler will find a place in memory for it and place the address of it in the second parameter). 22 | - 3. The length: number of bytes to print -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/fizzbuzz/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : fizzbuzz 2 | Expected files : fizzbuzz.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that prints the numbers from 1 to 100, each separated by a 7 | newline. 8 | 9 | If the number is a multiple of 3, it prints 'fizz' instead. 10 | 11 | If the number is a multiple of 5, it prints 'buzz' instead. 12 | 13 | If the number is both a multiple of 3 and a multiple of 5, it prints 'fizzbuzz' instead. 14 | 15 | Example: 16 | 17 | $>./fizzbuzz 18 | 1 19 | 2 20 | fizz 21 | 4 22 | buzz 23 | fizz 24 | 7 25 | 8 26 | fizz 27 | buzz 28 | 11 29 | fizz 30 | 13 31 | 14 32 | fizzbuzz 33 | [...] 34 | 97 35 | 98 36 | fizz 37 | buzz 38 | $> -------------------------------------------------------------------------------- /DAYS/C03/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 17: ft_strncat 2 | - Reproduce the behavior of the function strncat (man strncat). 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strncat(char *dest, char *src, int nb); 6 | ``` 7 | 8 | ## Understanding strncat 9 | ### Description: 10 | The strncat() function appends the first count characters of string2 to string1 and ends the resulting string with a null character (\0). If count is greater than the length of string2, the length of string2 is used in place of count.\ 11 | The strncat() function operates on null-ended strings. The string argument to the function should contain a null character (\0) marking the end of the string. 12 | 13 | ### Return value 14 | The strncat() function returns a pointer to the joined string (string1). 15 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/search_and_replace/search_and_replace.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_strlen(char *str) 4 | { 5 | int i = 0; 6 | 7 | while (str[i]) 8 | { 9 | i++; 10 | } 11 | return (i); 12 | } 13 | 14 | int main(int argc, char **argv) 15 | { 16 | int i; 17 | 18 | i = 0; 19 | 20 | if (argc == 4) 21 | { 22 | if (ft_strlen(argv[2]) == 1 && ft_strlen(argv[3]) == 1) 23 | { 24 | while (argv[1][i]) 25 | { 26 | if (argv[1][i] == argv[2][0]) 27 | write(1, &argv[3][0], 1); 28 | else 29 | write(1, &argv[1][i], 1); 30 | i++; 31 | } 32 | } 33 | } 34 | write(1, "\n", 1); 35 | 36 | } -------------------------------------------------------------------------------- /DAYS/C08/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 01: ft_boolean.h 2 | - Create a __ft_boolean.h__ file. It'll compile and run the following main appropriately: 3 | ```C 4 | #include "ft_boolean.h" 5 | 6 | void ft_putchar(char *str) 7 | { 8 | while(*str) 9 | write(1, str++, 1); 10 | } 11 | 12 | t_bool ft_is_even{int nbr) 13 | { 14 | return ((EVEN(nbr)) ? TRUE : FALSE); 15 | } 16 | 17 | int main(int argc, char **argv) 18 | { 19 | (void)argv; 20 | if (ft_is_even(argc - 1) == TRUE) 21 | ft_putstr(EVEN_MSG); 22 | else 23 | ft_putstr(ODD_MSG); 24 | return (SUCCESS); 25 | } 26 | ``` 27 | - This program should display 28 | ``` 29 | I have an even number of arguments. 30 | ``` 31 | - or 32 | ``` 33 | I have an odd number of arguments. 34 | ``` 35 | - followed by a line break when adequate. 36 | -------------------------------------------------------------------------------- /DAYS/C00/ex06/ft_print_comb2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers(int a, int b) 9 | { 10 | ft_putchar((a / 10) + '0'); 11 | ft_putchar((a % 10) + '0'); 12 | ft_putchar(' '); 13 | ft_putchar((b / 10) + '0'); 14 | ft_putchar((b % 10) + '0'); 15 | if (a <= 98) 16 | { 17 | ft_putchar(','); 18 | ft_putchar(' '); 19 | } 20 | } 21 | void ft_print_comb2(void) 22 | { 23 | int x; 24 | int y; 25 | 26 | x = 0; 27 | 28 | while (x <= 98) 29 | { 30 | y = x + 1; 31 | while (y <= 99) 32 | { 33 | ft_print_numbers(x, y); 34 | y++; 35 | } 36 | x++; 37 | 38 | } 39 | 40 | } -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/get_content.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | char *get_content(char *file) 4 | { 5 | char buf[28000]; 6 | char *content; 7 | int fd; 8 | int size; 9 | int i; 10 | 11 | i = 0; 12 | size = 0; 13 | content = 0; 14 | fd = open(file, O_RDWR); 15 | if (fd > 0) 16 | { 17 | while ((i = read(fd, buf, 28000))) 18 | size += i; 19 | close(fd); 20 | content = malloc(sizeof(char) * size); 21 | ft_strncpy(content, buf, size); 22 | } 23 | else 24 | { 25 | write(STDERR_FILENO, "ft_hexdump: ", 12); 26 | write(STDERR_FILENO, file, ft_strlen(file)); 27 | if (errno == 2) 28 | write(STDERR_FILENO, ": No such file or directory\n", 28); 29 | else if (errno == 21) 30 | write(STDERR_FILENO, ": Is a directory\n", 17); 31 | } 32 | return (content); 33 | } -------------------------------------------------------------------------------- /DAYS/C10/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 00: display_file 2 | 3 | - Create a `program` called `ft_display_file` that displays, on the standard output, only the content of the file given as argument. 4 | - The submission directory should have a `Makefile` with the following rules: `all`, `clean`, `fclean`. The binary will be called `ft_display_file`. 5 | - The `malloc` function is forbidden. You can only do this exercise by declaring fixed-sized array. 6 | - All files given as arguments will be valid. 7 | - Error messages have to be displayed on their reserved output. 8 | ``` 9 | $> ./ft_display_file 10 | File name missing. 11 | $> ./ft_display_file Makefile 12 | *contenu du Makefile* 13 | $> ./ft_display_file Makefile display_file.c 14 | Too many arguments. 15 | $> 16 | ``` 17 | - Allowed functions: close, open, read, write -------------------------------------------------------------------------------- /DAYS/Shell01/ex05/README.md: -------------------------------------------------------------------------------- 1 | # Exercise 05: Can you create it? 2 | 3 | - Create a file containing only "42", and NOTHING else. 4 | - Its name will be: `"\?$*MaRViN*$?\"` 5 | - Example: 6 | ``` 7 | $>ls -lRa *waM* | cat -e 8 | -rw---xr-- 1 75355 32015 2 Oct 2 12:21 "\?$*KwaMe*$?\"$ 9 | $> 10 | ``` 11 | ------------------------------------------ 12 | ## There are two solutions (that I know of) for this: 13 | * The easiest is just use the command `touch` to create the file and we need to 14 | specify the name like this: 15 | ``` 16 | touch \"\\\?\$\*'KwaMe'\*\$\?\\\" 17 | ``` 18 | * And the other way is just to create a temp file with whichever name you want 19 | and rename it to "\?$*'MaRViN'*$?\" 20 | 21 | > Let's not forget to include the '42' inside that file after completing the 22 | previous steps. 23 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/alpha_mirror/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : alpha_mirror 2 | Expected files : alpha_mirror.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program called alpha_mirror that takes a string and displays this string 7 | after replacing each alphabetical character by the opposite alphabetical 8 | character, followed by a newline. 9 | 10 | 'a' becomes 'z', 'Z' becomes 'A' 11 | 'd' becomes 'w', 'M' becomes 'N' 12 | 13 | and so on. 14 | 15 | Case is not changed. 16 | 17 | If the number of arguments is not 1, display only a newline. 18 | 19 | Examples: 20 | 21 | $>./alpha_mirror "abc" 22 | zyx 23 | $>./alpha_mirror "My horse is Amazing." | cat -e 24 | Nb slihv rh Znzarmt.$ 25 | $>./alpha_mirror | cat -e 26 | $ 27 | $> -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/ft_countdown/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-0-ft_countdown.txt============================== 5 | Assignment name : ft_countdown 6 | Expected files : ft_countdown.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays all digits in descending order, followed by a 11 | newline. 12 | 13 | Example: 14 | $> ./ft_countdown | cat -e 15 | 9876543210$ 16 | $> 17 | ========================================================================================== 18 | ``` 19 | 20 | ### Algorithm 21 | 22 | - Assign the char '9' to a variable. 23 | - Then as long as the variable is less or equal to '0'. 24 | - Print the variable. 25 | - Decrement the variable. -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/last_word/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : last_word 2 | Expected files : last_word.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes a string and displays its last word followed by a \n. 7 | 8 | A word is a section of string delimited by spaces/tabs or by the start/end of 9 | the string. 10 | 11 | If the number of parameters is not 1, or there are no words, display a newline. 12 | 13 | Example: 14 | 15 | $> ./last_word "FOR PONY" | cat -e 16 | PONY$ 17 | $> ./last_word "this ... is sparta, then again, maybe not" | cat -e 18 | not$ 19 | $> ./last_word " " | cat -e 20 | $ 21 | $> ./last_word "a" "b" | cat -e 22 | $ 23 | $> ./last_word " lorem,ipsum " | cat -e 24 | lorem,ipsum$ 25 | $> -------------------------------------------------------------------------------- /DAYS/C00/ex07/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 07 2 | * Create a function that displays the number entered as a parameter. The function has to be able to display all possible values within an int type variable. 3 | * Here's how it should be prototyped: 4 | ```C 5 | void ft_putnbr(int nbr); 6 | ``` 7 | * For example: 8 | * ft_putnbr(1337) displays '1337'. 9 | + Files to turn in: ft_putnbr.c 10 | + Allowed functions: ft_putchar 11 | 12 | ### Resources 13 | 1. [printing a integer variable using putchar()](https://bytes.com/topic/c/answers/594812-printing-integer-variable-using-putchar) 14 | 2. [How to Print a Long Integer Using Only putchar()](https://wuhrr.wordpress.com/2007/11/09/how-to-print-a-long-integer-using-only-putchar/) 15 | 3. [Split a number into digits](https://www.log2base2.com/c-examples/loop/split-a-number-into-digits-in-c.html) -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ft_strcpy/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-0-ft_strcpy.txt================================= 5 | Assignment name : ft_strcpy 6 | Expected files : ft_strcpy.c 7 | Allowed functions: 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Reproduce the behavior of the function strcpy (man strcpy). 11 | 12 | Your function must be declared as follows: 13 | 14 | char *ft_strcpy(char *s1, char *s2); 15 | ========================================================================================== 16 | ``` 17 | 18 | ### Algorithm 19 | 20 | - Go through each character of `s1` and assign it to `s2` 21 | - (as long as that character isn't `\0` the end of the string.) 22 | - Add `\0` to the end of the `s2` string. 23 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rot_13/rot_13.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | 7 | if (argc == 2) 8 | { 9 | i = 0; 10 | while (argv[1][i]) 11 | { 12 | if (argv[1][i] >= 'a' && argv[1][i] <= 'm' || argv[1][i] >= 'A' && argv[1][i] <= 'M') 13 | { 14 | argv[1][i] += 13; 15 | write(1, &argv[1][i], 1); 16 | } 17 | else if (argv[1][i] >= 'n' && argv[1][i] <= 'z' || argv[1][i] >= 'N' && argv[1][i] <= 'Z') 18 | { 19 | argv[1][i] -= 13; 20 | write(1, &argv[1][i], 1); 21 | } 22 | else 23 | write(1, &argv[1][i], 1); 24 | i++; 25 | } 26 | } 27 | write (1, "/n", 1); 28 | } -------------------------------------------------------------------------------- /DAYS/C10/ex03/srcs/check_flag.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_hexdump.h" 2 | 3 | int check_flag(char **av) 4 | { 5 | if (av[1][0] == '-') 6 | { 7 | if (av[1][1] == 'C') 8 | { 9 | if (av[1][2]) 10 | { 11 | write(2, "ft_hexdump: illegal option -- ", 31); 12 | write(2, &av[1][2], 1); 13 | write(2, "\n", 1); 14 | write(2, "usage: ft_hexdump [ -C ] file ...\n", 35); 15 | return (-1); 16 | } 17 | else if (!av[2]) 18 | { 19 | write(2, "usage: ft_hexdump [ -C ] file ...\n", 35); 20 | return (-1); 21 | } 22 | return (1); 23 | } 24 | else 25 | { 26 | write(2, "ft_hexdump: illegal option -- ", 30); 27 | write(2, &av[1][1], 1); 28 | write(2, "\n", 1); 29 | write(2, "usage: ft_hexdump [ -C ] file ...\n", 35); 30 | return (-1); 31 | } 32 | } 33 | return (0); 34 | } -------------------------------------------------------------------------------- /DAYS/C07/ex04/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 04 : ft_convert_base 2 | 3 | - Turn-in directory : ex04/ 4 | - Files to turn in : ft_convert_base.c, ft_convert_base2.c 5 | - Allowed functions : malloc, free 6 | • Create a function that returns the result of the conversion of the string nbr from a 7 | base base_from to a base base_to. 8 | • nbr, base_from, base_to may be not writable. 9 | • nbr will follow the same rules as ft_atoi_base (from an other module). Beware of 10 | ’+’, ’-’ and whitespaces. 11 | • The number represented by nbr must fit inside an int. 12 | • If a base is wrong, NULL should be returned. 13 | • The returned number must be prefix only by a single and uniq ’-’ if necessary, no 14 | whitespaces, no ’+’. 15 | • Here’s how it should be prototyped : 16 | char *ft_convert_base(char *nbr, char *base_from, char *base_to); 17 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_last_param/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-1-aff_last_param.txt============================ 5 | Assignment name : aff_last_param 6 | Expected files : aff_last_param.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes strings as arguments, and displays its last 11 | argument followed by a newline. 12 | 13 | If the number of arguments is less than 1, the program displays a newline. 14 | 15 | Examples: 16 | 17 | $> ./aff_last_param "zaz" "mange" "des" "chats" | cat -e 18 | chats$ 19 | $> ./aff_last_param "j'aime le savon" | cat -e 20 | j'aime le savon$ 21 | $> ./aff_last_param 22 | $ 23 | ========================================================================================== 24 | ``` -------------------------------------------------------------------------------- /DAYS/C08/ex05/ft_show_tab.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ft_stock_str.h" 3 | 4 | void ft_putchar(char c) 5 | { 6 | write(1, &c, 1); 7 | } 8 | 9 | void ft_putstr(char *str) 10 | { 11 | while (*str) 12 | write(1, str++, 1); 13 | } 14 | 15 | void ft_putnbr(int nb) 16 | { 17 | unsigned int n; 18 | 19 | n = nb; 20 | if (nb < 0) 21 | { 22 | ft_putchar('-'); 23 | n *= -1; 24 | } 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_show_tab(struct s_stock_str *par) 35 | { 36 | int i; 37 | 38 | i = 0; 39 | while (par[i].str) 40 | { 41 | ft_putstr(par[i].str); 42 | ft_putchar('\n'); 43 | ft_putnbr(par[i].size); 44 | ft_putchar('\n'); 45 | ft_putstr(par[i].copy); 46 | ft_putchar('\n'); 47 | i++; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /DAYS/C00/ex05/ft_print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers(char a, char b, char c) 9 | { 10 | ft_putchar(a); 11 | ft_putchar(b); 12 | ft_putchar(c); 13 | if (a <= '7') 14 | { 15 | ft_putchar(','); 16 | ft_putchar(' '); 17 | } 18 | } 19 | 20 | void ft_print_comb(void) 21 | { 22 | char a; 23 | char b; 24 | char c; 25 | 26 | a = '0'; 27 | while (a <= '7') 28 | { 29 | b = a + 1; 30 | while (b <= '8') 31 | { 32 | c = b +1; 33 | while (c <= '9') 34 | { 35 | ft_print_numbers(a, b, c); 36 | c++; 37 | } 38 | 39 | b++; 40 | } 41 | 42 | a++; 43 | } 44 | 45 | } -------------------------------------------------------------------------------- /DAYS/C03/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 16: ft_strcat 2 | - Reproduce the behavior of the function __strcat__ (man strcat). 3 | - Here's how it should be prototyped: 4 | ```C 5 | char *ft_strcat(char *dest, char *src); 6 | ``` 7 | 8 | ## Understanding strcat 9 | ### Description: 10 | The strcat() function concatenates string2 to string1 and ends the resulting string with the null character.\ 11 | The strcat() function operates on null-ended strings. The string arguments to the function should contain a null character (\0) that marks the end of the string. No length checking is performed. You should not use a literal string for a string1 value, although string2 may be a literal string.\ 12 | If the storage of string1 overlaps the storage of string2, the behavior is undefined. 13 | 14 | ### Return value 15 | The strcat() function returns a pointer to the concatenated string (string1). 16 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rotone/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : rotone 2 | Expected files : rotone.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes a string and displays it, replacing each of its 7 | letters by the next one in alphabetical order. 8 | 9 | 'z' becomes 'a' and 'Z' becomes 'A'. Case remains unaffected. 10 | 11 | The output will be followed by a \n. 12 | 13 | If the number of arguments is not 1, the program displays \n. 14 | 15 | Example: 16 | 17 | $>./rotone "abc" 18 | bcd 19 | $>./rotone "Les stagiaires du staff ne sentent pas toujours tres bon." | cat -e 20 | Mft tubhjbjsft ev tubgg of tfoufou qbt upvkpvst usft cpo.$ 21 | $>./rotone "AkjhZ zLKIJz , 23y " | cat -e 22 | BlkiA aMLJKa , 23z $ 23 | $>./rotone | cat -e 24 | $ 25 | $> 26 | $>./rotone "" | cat -e 27 | $ 28 | $> -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/union/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : union 2 | Expected files : union.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes two strings and displays, without doubles, the 7 | characters that appear in either one of the strings. 8 | 9 | The display will be in the order characters appear in the command line, and 10 | will be followed by a \n. 11 | 12 | If the number of arguments is not 2, the program displays \n. 13 | 14 | Example: 15 | 16 | $>./union zpadinton "paqefwtdjetyiytjneytjoeyjnejeyj" | cat -e 17 | zpadintoqefwjy$ 18 | $>./union ddf6vewg64f gtwthgdwthdwfteewhrtag6h4ffdhsd | cat -e 19 | df6vewg4thras$ 20 | $>./union "rien" "cette phrase ne cache rien" | cat -e 21 | rienct phas$ 22 | $>./union | cat -e 23 | $ 24 | $> 25 | $>./union "rien" | cat -e 26 | $ 27 | $> -------------------------------------------------------------------------------- /DAYS/C01/ex04/ft_ultimate_div_mod.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers(int n) 9 | { 10 | if (n >= 10) 11 | ft_print_numbers(n / 10); 12 | ft_putchar((n % 10) + '0'); 13 | } 14 | 15 | void ft_ultimate_div_mod(int *a, int *b) 16 | { 17 | int tmp; 18 | 19 | tmp = *a / *b; 20 | *b = *a % *b; 21 | *a = tmp; 22 | } 23 | 24 | int main() 25 | { 26 | 27 | int a = 12; 28 | int b = 6; 29 | int *pa = &a; 30 | int *pb = &b; 31 | 32 | ft_ultimate_div_mod(pa, pb); 33 | 34 | ft_putchar('a'); 35 | ft_putchar(' '); 36 | ft_putchar(a + 48); 37 | 38 | ft_putchar('\n'); 39 | 40 | ft_putchar('b'); 41 | ft_putchar(' '); 42 | ft_putchar(b + 48); 43 | 44 | ft_putchar('\n'); 45 | 46 | 47 | return 0; 48 | } 49 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_first_param/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-1-aff_first_param.txt=========================== 5 | Assignment name : aff_first_param 6 | Expected files : aff_first_param.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes strings as arguments, and displays its first 11 | argument followed by a \n. 12 | 13 | If the number of arguments is less than 1, the program displays \n. 14 | 15 | Example: 16 | 17 | $> ./aff_first_param vincent mit "l'ane" dans un pre et "s'en" vint | cat -e 18 | vincent$ 19 | $> ./aff_first_param "j'aime le fromage de chevre" | cat -e 20 | j'aime le fromage de chevre$ 21 | $> ./aff_first_param 22 | $ 23 | ========================================================================================== 24 | ``` -------------------------------------------------------------------------------- /DAYS/C08/ex04/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 04: ft_strs_to_tab 2 | - Create a function that takes an array of string as argument and the size of this array. 3 | - Here's how it should be prototyped: 4 | 5 | ```C 6 | struct s_stock_par *ft_strs_to_tab(int ac, char **av); 7 | ``` 8 | - It will transform each element of av into a structure. 9 | - The structure is defined in the __ft_stock_par.h__ file that we will provided, 10 | 11 | ```C 12 | typedef struct s_stock_par 13 | { 14 | int size; 15 | char *str; 16 | char *copy; 17 | } t_stock_par; 18 | ``` 19 | - __size__ being the length of the string; 20 | - __str__ being the string; 21 | - __copy__ being the copy of the string; 22 | 23 | - It should keep the order of av. 24 | - The return array should allocated in memory and its last element's __str__ set to 0, this will mark the end of the array. 25 | - It should return __NULL__ pointer if an error occurs. -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/maff_alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-0-maff_alpha.txt================================ 5 | Assignment name : maff_alpha 6 | Expected files : maff_alpha.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that displays the alphabet, with even letters in uppercase, and 11 | odd letters in lowercase, followed by a newline. 12 | 13 | Example: 14 | 15 | $> ./maff_alpha | cat -e 16 | aBcDeFgHiJkLmNoPqRsTuVwXyZ$ 17 | ========================================================================================== 18 | ``` 19 | 20 | ### Algorithm 21 | 22 | - Assign a variable to a lower case 'a'. 23 | - For every letter in the alphabet check if the letter is even or odd ('letter' % 2). 24 | - If even print it in upper case ('letter' - 32). 25 | - Else print it as it is. -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_a/aff_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i; 6 | i = 0; 7 | 8 | if(argc == 2) 9 | while (argv[1][i]) 10 | { 11 | if(argv[1][i] == 'a') 12 | { 13 | write(1, "a", 1); 14 | break; 15 | } 16 | i++; 17 | } 18 | else 19 | write(1, "a", 1); 20 | write(1, "\n", 1); 21 | 22 | return 0; 23 | } 24 | 25 | 26 | #include 27 | 28 | int main(int argc, char **argv) 29 | { 30 | int i; 31 | 32 | if (argc == 2) 33 | { 34 | i = 0; 35 | while (argv[1][i]) 36 | { 37 | if (argv[1][i] == 'a') 38 | { 39 | write(1, &argv[1][i], 1); 40 | break; 41 | } 42 | i++; 43 | } 44 | write(1, "\n", 1); 45 | } 46 | else 47 | { 48 | write(1, "a\n", 2); 49 | } 50 | return (0); 51 | } -------------------------------------------------------------------------------- /DAYS/C01/ex02/ft_swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_putnbr(int nbr) 9 | { 10 | if (nbr < 0) 11 | { 12 | ft_putchar('-'); 13 | nbr = -nbr; 14 | } 15 | if (nbr > 9) 16 | { 17 | ft_putnbr(nbr / 10); 18 | } 19 | ft_putchar(nbr % 10 + '0'); 20 | 21 | } 22 | 23 | void ft_swap(int *a, int *b) 24 | { 25 | int tmp; 26 | 27 | tmp = *a; 28 | *a = *b; 29 | *b = tmp; 30 | 31 | } 32 | 33 | int main(int i, int j) 34 | { 35 | 36 | i = 69; 37 | j = 2001; 38 | 39 | ft_putnbr(i); 40 | ft_putchar(','); 41 | ft_putchar(' '); 42 | ft_putnbr(j); 43 | ft_putchar('\n'); 44 | 45 | ft_swap(&i, &j); 46 | 47 | ft_putnbr(i); 48 | ft_putchar(','); 49 | ft_putchar(' '); 50 | ft_putnbr(j); 51 | ft_putchar('\n'); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_z/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-2-aff_z.txt===================================== 5 | Assignment name : aff_z 6 | Expected files : aff_z.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes a string, and displays the first 'z' 11 | character it encounters in it, followed by a newline. If there are no 12 | 'z' characters in the string, the program writes 'z' followed 13 | by a newline. If the number of parameters is not 1, the program displays 14 | 'z' followed by a newline. 15 | 16 | Example: 17 | 18 | $> ./aff_z "abc" | cat -e 19 | z$ 20 | $> ./aff_z "dubO a POIL" | cat -e 21 | z$ 22 | $> ./aff_z "zaz sent le poney" | cat -e 23 | z$ 24 | $> ./aff_z | cat -e 25 | z$ 26 | ========================================================================================== 27 | ``` -------------------------------------------------------------------------------- /DAYS/C03/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 06: ft_strcmp 2 | - Reproduce the behavior of the function strcmp (man strcmp). 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_strcmp(char *s1, char *s2); 6 | ``` 7 | 8 | ## Understanding strcmp 9 | 10 | ### Description 11 | The strcmp() function is used to compare two strings two strings str1 and str2. If two strings are same then strcmp() returns 0, otherwise, it returns a non-zero value. 12 | 13 | ### Return values 14 | The strcmp() and strncmp() functions return an integer greater than, equal to, or less than 0, according as the string s1 is greater than, equal to, or less than the string s2. The comparison is done using unsigned characters, so that `\200' is greater than `\0'. 15 | 16 | | Value | Meaning | 17 | |---|----| 18 | | < 0| str1 < str2 19 | | 0|str1 == str2 20 | | > 0 | str1 > str2 21 | 22 | ### More 23 | [Detailed description](https://overiq.com/c-programming-101/the-strcmp-function-in-c/) -------------------------------------------------------------------------------- /DAYS/C10/ex04/srcs/ft_last.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | void display_entry_time(long time) 6 | { 7 | struct tm *ltime; 8 | char buff[64]; 9 | 10 | ltime = localtime(&time); 11 | strftime(buff, sizeof(buff), "%Y-%m-%d %H:%M:%S", ltime); 12 | printf("%s - ", buff); 13 | 14 | } 15 | 16 | void desplay_entry(struct utmpx *entry) 17 | { 18 | printf("%s - ", entry->ut_user); 19 | printf("%s - ", entry->ut_line); 20 | display_entry_time(entry->ut_tv.tv_sec); 21 | printf("%s\n", entry->ut_host); 22 | //printf("%s - ", entry->ut_id); 23 | //printf("%d - ", entry->ut_pid); 24 | //printf("%d - ", SHUTDOWN_TIME); 25 | } 26 | 27 | int main(void) 28 | { 29 | struct utmpx *entry; 30 | 31 | while ((entry = getutxent()) != NULL) 32 | { 33 | ///printf("%d\n", USER_PROCESS); 34 | if (entry->ut_type != USER_PROCESS) 35 | continue; 36 | desplay_entry(entry); 37 | } 38 | return (0); 39 | } -------------------------------------------------------------------------------- /DAYS/Shell00/ex08/clean.sh: -------------------------------------------------------------------------------- 1 | 2 | # **************************************************************************** # 3 | # # 4 | # ::: :::::::: # 5 | # clean.sh :+: :+: :+: # 6 | # +:+ +:+ +:+ # 7 | # By: ael-khni +#+ +:+ +#+ # 8 | # +#+#+#+#+#+ +#+ # 9 | # Created: 2021/11/28 09:32:40 by ael-khni #+# #+# # 10 | # Updated: 2021/11/28 09:32:42 by ael-khni ### ########.fr # 11 | # # 12 | # **************************************************************************** # 13 | 14 | find . -name "*[~#]" -print -delete -------------------------------------------------------------------------------- /DAYS/C10/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: hexdump 2 | 3 | - Create a "program" called `ft_hexdump` which does the same thing as the system's `hexdump` command-line. 4 | - The only option you have to handle is `-C` 5 | - The submission directory should have a `Makefile` with the following rules: `all`, `clean`, `fclean` 6 | - You may use the variable `errno` 7 | 8 | 9 | ## Notes. 10 | 11 | - man last, utmp, wtmp, lastlog. 12 | - .asl files = apple system log. 13 | - [how to open .asl files](https://www.google.com/search?client=safari&rls=en&q=how+to+open+apple+system+logs+files&ie=UTF-8&oe=UTF-8) 14 | - http://macadmins.psu.edu/wp-content/uploads/sites/24696/2016/06/psumac2016-19-osxlogs_macadmins_2016.pdf 15 | - [OSX: “last” command and utmpx](https://stackoverflow.com/questions/33417520/osx-last-command-and-utmpx) 16 | - [last login](https://superuser.com/questions/128705/ssh-last-login-last-and-os-x) 17 | - [piscine](https://github.com/amalliar/piscine-C/blob/master/d12/ex04/src/ft_wtmp_load.c) -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/wdmatch/README.md: -------------------------------------------------------------------------------- 1 | Assignment name : wdmatch 2 | Expected files : wdmatch.c 3 | Allowed functions: write 4 | -------------------------------------------------------------------------------- 5 | 6 | Write a program that takes two strings and checks whether it's possible to 7 | write the first string with characters from the second string, while respecting 8 | the order in which these characters appear in the second string. 9 | 10 | If it's possible, the program displays the string, followed by a \n, otherwise 11 | it simply displays a \n. 12 | 13 | If the number of arguments is not 2, the program displays a \n. 14 | 15 | Examples: 16 | 17 | $>./wdmatch "faya" "fgvvfdxcacpolhyghbreda" | cat -e 18 | faya$ 19 | $>./wdmatch "faya" "fgvvfdxcacpolhyghbred" | cat -e 20 | $ 21 | $>./wdmatch "quarante deux" "qfqfsudf arzgsayns tsregfdgs sjytdekuoixq " | cat -e 22 | quarante deux$ 23 | $>./wdmatch "error" rrerrrfiiljdfxjyuifrrvcoojh | cat -e 24 | $ 25 | $>./wdmatch | cat -e 26 | $ -------------------------------------------------------------------------------- /DAYS/C06/ex03/ft_sort_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | while (str[i]) 9 | write(1, &str[i++], 1); 10 | write(1, "\n", 1); 11 | } 12 | 13 | int ft_strcmp(char *str1, char *str2) 14 | { 15 | int i; 16 | 17 | i = 0; 18 | while (str1[i] && str2[i]) 19 | { 20 | if (str1[i] == str2[i]) 21 | i++; 22 | else 23 | break ; 24 | } 25 | return (str1[i] - str2[i]); 26 | } 27 | 28 | void ft_sort_param(int argc, char **argv) 29 | { 30 | char *tmp; 31 | int i; 32 | 33 | i = 1; 34 | while (i < argc - 1) 35 | { 36 | if (ft_strcmp(argv[i], argv[i + 1]) > 0) 37 | { 38 | tmp = argv[i]; 39 | argv[i] = argv[i + 1]; 40 | argv[i + 1] = tmp; 41 | i = 0; 42 | } 43 | i++; 44 | } 45 | } 46 | 47 | int main(int argc, char **argv) 48 | { 49 | int i; 50 | 51 | i = 1; 52 | ft_sort_param(argc, argv); 53 | while (i < argc) 54 | ft_putstr(argv[i++]); 55 | return (0); 56 | } 57 | -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/check_flag.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | int check_flag(char **av) 4 | { 5 | int bytes; 6 | int i; 7 | 8 | bytes = 0; 9 | i = 2; 10 | if (av[1][0] == '-') 11 | { 12 | if (av[1][1] == 'c' && !av[1][2]) 13 | { 14 | if (!av[2]) 15 | { 16 | write(2, "ft_tail: option requires an argument -- c\n", 42); 17 | write(2, "usage: ft_tail [ -c # ] [file ...]\n", 35); 18 | return (-1); 19 | } 20 | else 21 | { 22 | bytes = ft_atoi(av[2]); 23 | return (bytes); 24 | } 25 | } 26 | else if (av[1][1] == 'c' && av[1][2]) 27 | { 28 | write(2, "ft_tail: illegal offset -- ", 28); 29 | while (i < ft_strlen(av[1])) 30 | write(2, &av[1][i++], 1); 31 | write(2, "\n", 1); 32 | } 33 | else 34 | { 35 | write(2, "ft_tail: illegal option -- ", 28); 36 | write(2, &av[1][1], 1); 37 | write(2, "\n", 1); 38 | write(2, "usage: ft_tail [ -c # ] [file ...]\n", 35); 39 | } 40 | } 41 | return (0); 42 | } -------------------------------------------------------------------------------- /DAYS/C10/ex02/srcs/ft_tail.c: -------------------------------------------------------------------------------- 1 | #include "../includes/ft_tail.h" 2 | 3 | void ft_tail(int ac, int bytes, char *file) 4 | { 5 | char buf[28000]; 6 | char *content; 7 | int fd; 8 | int size; 9 | int i; 10 | 11 | i = 0; 12 | size = 0; 13 | fd = open(file, O_RDWR); 14 | if (fd > 0) 15 | { 16 | show_file_name(ac, bytes, file); 17 | while ((i = read(fd, buf, 28000))) 18 | size +=i; 19 | close(fd); 20 | content = malloc(sizeof(char) * size); 21 | ft_strncpy(content, buf, size); 22 | if (bytes) 23 | i = size - bytes; 24 | else 25 | i = get_tail_index(content); 26 | while (buf[i]) 27 | write(1, &content[i++], 1); 28 | free(content); 29 | } 30 | else 31 | { 32 | write(STDERR_FILENO, "ft_tail: ", 9); 33 | write(STDERR_FILENO, file, ft_strlen(file)); 34 | if (errno == 2) 35 | write(STDERR_FILENO, ": No such file or directory\n", 28); 36 | else if (errno == 21) 37 | write(STDERR_FILENO, ": Is a directory\n", 17); 38 | } 39 | close(fd); 40 | } -------------------------------------------------------------------------------- /DAYS/C08/ex04/ft_strs_to_tab.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "ft_stock_str.h" 3 | 4 | int ft_strlen(char *str) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | while (str[i]) 10 | i++; 11 | return (i); 12 | } 13 | 14 | char *ft_strdup(char *src) 15 | { 16 | char *copy; 17 | int i; 18 | 19 | i = 0; 20 | while (src[i]) 21 | i++; 22 | copy = malloc((sizeof(char) * i) + 1); 23 | if (!copy) 24 | return (NULL); 25 | i = 0; 26 | while (src[i]) 27 | { 28 | copy[i] = src[i]; 29 | i++; 30 | } 31 | copy[i] = '\0'; 32 | return (copy); 33 | } 34 | 35 | struct s_stock_str *ft_strs_to_tab(int ac, char **av) 36 | { 37 | t_stock_str *output; 38 | int i; 39 | 40 | i = 0; 41 | output = malloc(sizeof(t_stock_str) * (ac + 1)); 42 | if (!output) 43 | return (NULL); 44 | while (i < ac) 45 | { 46 | output[i].size = ft_strlen(av[i]); 47 | output[i].str = av[i]; 48 | output[i].copy = ft_strdup(av[i]); 49 | i++; 50 | } 51 | output[i].str = 0; 52 | return (output); 53 | } 54 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/repeat_alpha/repeat_alpha.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(int argc, char **argv) 4 | { 5 | int i = 0; 6 | int j = 0; 7 | 8 | if (argc == 2) 9 | { 10 | while (argv[1][i]) 11 | { 12 | if (argv[1][i] >= 'a' && argv[1][i] <= 'z') 13 | { 14 | j = argv[1][i]; 15 | while (j >= 'a') 16 | { 17 | write(1, &argv[1][i], 1); 18 | j--; 19 | } 20 | } 21 | else if (argv[1][i] >= 'A' && argv[1][i] <= 'Z') 22 | { 23 | j = argv[1][i]; 24 | while (j >= 'A') 25 | { 26 | write(1, &argv[1][i], 1); 27 | j--; 28 | } 29 | } 30 | else{ 31 | write(1, &argv[1][i], 1); 32 | } 33 | i++; 34 | } 35 | 36 | } 37 | write(1, "\n", 1); 38 | return 0; 39 | } -------------------------------------------------------------------------------- /DAYS/C01/ex01/ft_ultimate_ft.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_putnbr(int n) 9 | { 10 | if (n < 0) 11 | { 12 | ft_putchar('-'); 13 | n = -n; 14 | } 15 | if (n > 9) 16 | { 17 | ft_putnbr(n / 10); 18 | } 19 | ft_putchar((n % 10) + '0'); 20 | } 21 | 22 | void ft_ultimate_ft(int *********nbr) 23 | { 24 | *********nbr = 42; 25 | } 26 | 27 | int main(void) 28 | { 29 | int number; 30 | int *p; 31 | int **p2; 32 | int ***p3; 33 | int ****p4; 34 | int *****p5; 35 | int ******p6; 36 | int *******p7; 37 | int ********p8; 38 | int *********p9; 39 | 40 | p = &number; 41 | p2 = &p; 42 | p3 = &p2; 43 | p4 = &p3; 44 | p5 = &p4; 45 | p6 = &p5; 46 | p7 = &p6; 47 | p8 = &p7; 48 | p9 = &p8; 49 | 50 | number = 1337; 51 | ft_ultimate_ft(p9); 52 | ft_putchar('\n'); 53 | return (0); 54 | } -------------------------------------------------------------------------------- /DAYS/C01/ex03/ft_div_mod.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers(int n) 9 | { 10 | if (n >= 10) 11 | ft_print_numbers(n / 10); 12 | ft_putchar((n % 10) + '0'); 13 | } 14 | 15 | void ft_div_mod(int a, int b, int *div, int *mod) 16 | { 17 | if (b != 0) 18 | { 19 | *div = a / b; 20 | *mod = a % b; 21 | } 22 | } 23 | 24 | int main(){ 25 | 26 | int a = 40; 27 | int b = 5; 28 | int x; 29 | int y; 30 | 31 | ft_div_mod(a, b, &x, &y); 32 | 33 | 34 | ft_putchar('a'); 35 | ft_putchar(' '); 36 | ft_print_numbers(a); 37 | 38 | ft_putchar('\n'); 39 | 40 | ft_putchar('b'); 41 | ft_putchar(' '); 42 | ft_print_numbers(b); 43 | 44 | ft_putchar('\n'); 45 | 46 | ft_putchar('x'); 47 | ft_putchar(' '); 48 | ft_print_numbers(x); 49 | 50 | ft_putchar('\n'); 51 | 52 | ft_putchar('y'); 53 | ft_putchar(' '); 54 | ft_print_numbers(y); 55 | 56 | 57 | return 0; 58 | } -------------------------------------------------------------------------------- /DAYS/C05/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: ft_iterative_power 2 | - Create an iterated function that returns the value of a power applied to a number. An power lower than 0 returns 0. Overflows don't have to be handled. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_iterative_power(int nb, int power); 6 | ``` 7 | 8 | ## Understanding Power (exponent) 9 | - The power (exponent) of a number says how many times to use the number in a multiplication. 10 | - In **8^2** the "2" says to use 8 twice in a multiplication, so `8^2 = 8 * 8 = 64` 11 | - Exponents are also called Power or Indices. 12 | 13 | ### In General 14 | - **a^n** tells you to multiply **a** by itself, so there are **n** of those **a**'s: 15 | 16 | ![pic alt](https://github.com/achrafelkhnissi/Computer-Science/blob/master/1337/imgs/exponent-definition.gif) 17 | 18 | ### Negative Exponents 19 | - [Example](https://www.mathsisfun.com/exponent.html) 20 | - [Laws of Exponents](https://www.mathsisfun.com/algebra/exponent-laws.html) 21 | - [Negative Exponents Explained! - YouTube](https://www.youtube.com/watch?v=TKj8kEofbAw) -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_a/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./0-0-aff_a.txt===================================== 5 | Assignment name : aff_a 6 | Expected files : aff_a.c 7 | Allowed functions: write 8 | ----------------------------------------------------------------------------------------- 9 | 10 | Write a program that takes a string, and displays the first 'a' character it 11 | encounters in it, followed by a newline. If there are no 'a' characters in the 12 | string, the program just writes a newline. If the number of parameters is not 13 | 1, the program displays 'a' followed by a newline. 14 | 15 | Example: 16 | 17 | $> ./aff_a "abc" | cat -e 18 | a$ 19 | $> ./aff_a "dubO a POIL" | cat -e 20 | a$ 21 | $> ./aff_a "zz sent le poney" | cat -e 22 | $ 23 | $> ./aff_a | cat -e 24 | a$ 25 | ========================================================================================== 26 | ``` 27 | 28 | ### Algorithm 29 | 30 | - go through each character of the given string. 31 | - compare each character with 'a'. 32 | - If true print 'a'. 33 | - print '\n'. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Kaizen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strcmp/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strcmp.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou ` to compile it, 12 | and `file -m ` to use it. 13 | 14 | ### To create our magic file (ft_magic) we break down the requirements: 15 | * File has to be formatted appropriately to detect files of **42 file type**: 16 | * This file type is defined by having a *42 'string' at the 42nd byte* 17 | * If we go to `man magic` we can see the following break down: 18 | ``` 19 | 42 string 42 magic 42 number found` 20 | └┬┘└─┬──┘ └──┬───┘ └──────┬──────┘ 21 | │ │ │ └─── Message 22 | │ │ └──────────────── Test 23 | │ └──────────────────────── Type 24 | └──────────────────────────── Offset 25 | ``` 26 | > Feel free to modify it to fully comprehend it, if needed. 27 | 28 | ------------------------------------------ -------------------------------------------------------------------------------- /DAYS/C10/ex04/test/maybe_working.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | //open the Utmp file 12 | // mine is different because I have mac so it is utmpx 13 | 14 | void utmpprint(struct utmpx *log); 15 | int openUtmpFile(); 16 | 17 | int main() 18 | { 19 | struct utmpx buffer[100]; 20 | int tmpfile = open("/var/run/utmpx", O_RDONLY); 21 | 22 | if (tmpfile < 0) 23 | { 24 | printf("Error opening utmpx file"); 25 | return -1; 26 | } 27 | read(tmpfile, &buffer, sizeof(struct utmpx) * 100); 28 | for (int i = 0; i < 5; i++) 29 | printf("ut_user = %s\n", buffer[i].ut_user); 30 | 31 | return 0; 32 | } 33 | int openUtmpFile() 34 | { 35 | int tmp = open("/var/run/utmpx", O_RDONLY); 36 | printf("%i", tmp); 37 | return tmp; 38 | } 39 | 40 | /* From: 41 | * https://stackoverflow.com/questions/64394182/reading-utmpx-without-file-in-c 42 | * https://opensource.apple.com/source/Libc/Libc-583/include/utmpx.h.auto.html 43 | */ -------------------------------------------------------------------------------- /DAYS/Shell00/ex07/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 09 2 | 3 | * Create a file **b**, so that: 4 | ``` 5 | %>cat -e a 6 | STARWARS$ 7 | Episode IV, A NEW HOPE It is a period of civil war.$ 8 | $ 9 | Rebel spaceships, striking from a hidden base, have won their first victory against the evil 10 | Galactic Empire.$ 11 | During the battle, Rebel spies managed to steal secret plans to the Empires ultimate weapon, the 12 | DEATH STAR,$ 13 | an armored space station with enough power to destroy an entire planet.$ 14 | $ 15 | Pursued by the Empires sinister agents, Princess Leia races home aboard her starship, custodian of 16 | the stolen plans that can save her people and restore freedom to the galaxy...$ $ 17 | %>diff a b > sw.diff 18 | ``` 19 | 20 | HINT: man patch 21 | 22 | ------------------------------------------ 23 | #### If we RTFM!(`man diff`) we will see that: 24 | ``` 25 | DESCRIPTION 26 | Compare FILES line by line. 27 | ``` 28 | 29 | > And since there is no argument required for `diff a b > sw.diff` we just 30 | create a bile called `b` that is just different enough to file `a` so that the 31 | command may work correctly. 32 | 33 | ------------------------------------------ 34 | -------------------------------------------------------------------------------- /DAYS/C02/ex11/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 22: ft_putstr_non_printable 2 | - Create a function that displays a string of characters onscreen. If this string contains characters that aren't printable, they'll have to be displayed in the shape of hexadecimals (lowercase), preceded by a "backslash". 3 | - For example: 4 | > Coucou\ntu vas bien ? 5 | - The function should display: 6 | > Coucou\0atu vas bien ? 7 | - Here's how it should be prototyped: 8 | ```C 9 | void ft_putstr_non_printable(char *str); 10 | ``` 11 | 12 | TODO: 13 | 1. scan text for none printable character. 14 | 2. get the integer value of the particular character. 15 | 3. convert the value to hex. (and from int to str) 16 | 4. replace the non-printable character with the converted value.\ 17 | insert the converted hex string in the index of the non printable character 18 | 19 | note: 20 | - we need a function to convert integer to a null terminated string. (including negative). 21 | 22 | 23 | ## IMPORTANT: 24 | that's why you always need to understand the exercise the right way.\ 25 | because the simplest steps are:\ 26 | 1. for every character in the given string print it if it's printable 27 | 2. if not then print the hex value of it after printing \\0. -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rev_print/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-3-rev_print.txt========================================= 5 | Assignment name : rev_print 6 | Expected files : rev_print.c 7 | Allowed functions: write 8 | -------------------------------------------------------------------------------------------------- 9 | 10 | Write a program that takes a string, and displays the string in reverse 11 | followed by a newline. 12 | 13 | If the number of parameters is not 1, the program displays a newline. 14 | 15 | Examples: 16 | 17 | $> ./rev_print "zaz" | cat -e 18 | zaz$ 19 | $> ./rev_print "dub0 a POIL" | cat -e 20 | LIOP a 0bud$ 21 | $> ./rev_print | cat -e 22 | $ 23 | ================================================================================================== 24 | ``` 25 | 26 | ### Algorithm 27 | 28 | - First we check if the number of input arguments is 2 29 | - If so. We get the length of the second argument. 30 | - Note: the length of a string is also the index of the last element of that string. 31 | - So we go through that string from the last element printing each character and decrementing the index variable. 32 | - Finally we print a new line. 33 | -------------------------------------------------------------------------------- /DAYS/C10/ex02/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 02: tail 2 | 3 | - Create a "program" called `ft_tail` which does the same thing as the system command-line `tail`, but which takes at least one file as argument. 4 | - The only option you have to handle is `-c`. This option will be present in all tests. 5 | - The submission directory should have a `Makefile` with the following rules: `all`, `clean`, `fclean` 6 | - You may use the variable `errno` 7 | 8 | 9 | ### Cases 10 | 11 | 1. `tail -c 10 file1 file2` 12 | ``` 13 | ==> Makefile <== 14 | rm $(BIN) 15 | 16 | ==> README.md <== 17 | e `errno` 18 | ``` 19 | 2. `tail -c 10 file1 -c 10 file2` 20 | ``` 21 | ==> Makefile <== 22 | rm $(BIN) 23 | tail: -c: No such file or directory 24 | tail: 10: No such file or directory 25 | 26 | ==> README.md <== 27 | e `errno` 28 | ``` 29 | 3. `tail file1 file2` 30 | ``` 31 | ==> file1 <== 32 | * file1 content * 33 | 34 | ==> file2 <== 35 | * file2 content * 36 | ``` 37 | 4. `tail file1 file2_noexist` 38 | ``` 39 | ==> file1 <== 40 | * file1 content * 41 | tail: file2_noexist: No such file or directory 42 | ``` 43 | 5. `tail -c` 44 | ``` 45 | tail: option requires an argument -- c 46 | usage: tail [-F | -f | -r] [-q] [-b # | -c # | -n #] [file ...] 47 | ``` -------------------------------------------------------------------------------- /DAYS/C04/ex04/ft_putnbr_base.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | int ft_strlen(char *str) 9 | { 10 | int i; 11 | 12 | i = 0; 13 | while (str[i]) 14 | i++; 15 | return (i); 16 | } 17 | 18 | int ft_check(char *base) 19 | { 20 | int i; 21 | int j; 22 | 23 | i = 0; 24 | if (ft_strlen(base) < 2) 25 | return (0); 26 | while (base[i + 1]) 27 | { 28 | j = i + 1; 29 | while (base[j]) 30 | { 31 | if (base[i] == base[j] || base[i] == '+' || base[i] == '-' 32 | || base[j] == '+' || base[j] == '-' || base[i] <= ' ' 33 | || base[i] > 126 || base[j] <= ' ' || base[j] > 126) 34 | return (0); 35 | j++; 36 | } 37 | i++; 38 | } 39 | return (1); 40 | } 41 | 42 | void ft_putnbr_base(int nbr, char *base) 43 | { 44 | long int nb; 45 | 46 | if (nbr == 0) 47 | { 48 | ft_putchar(base[0]); 49 | return ; 50 | } 51 | nb = (long int)nbr; 52 | if (!ft_check(base)) 53 | return ; 54 | if (nb < 0) 55 | { 56 | ft_putchar('-'); 57 | nb = -nb; 58 | } 59 | if (nb != 0) 60 | { 61 | if (nb / ft_strlen(base) != 0) 62 | ft_putnbr_base(nb / ft_strlen(base), base); 63 | ft_putchar(base[nb % ft_strlen(base)]); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /DAYS/C05/ex08/ft_ten_queens_puzzle.c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SIZE 10 4 | 5 | void ft_putchar(char c) 6 | { 7 | write(1, &c, 1); 8 | } 9 | 10 | void print_position(int *board) 11 | { 12 | int i; 13 | 14 | i = 0; 15 | while (i < SIZE) 16 | ft_putchar(board[i++] + 48); 17 | ft_putchar('\n'); 18 | } 19 | 20 | int is_valid(int *board, int row, int col) 21 | { 22 | int i; 23 | 24 | i = 0; 25 | while (i < row) 26 | { 27 | if (board[i] == col || board[i] - i == col - row 28 | || board[i] + i == col + row) 29 | return (0); 30 | else 31 | i++; 32 | } 33 | return (1); 34 | } 35 | 36 | int put_queen(int *board, int row) 37 | { 38 | static int pos; 39 | int col; 40 | 41 | if (row == SIZE) 42 | { 43 | pos++; 44 | print_position(board); 45 | } 46 | else 47 | { 48 | col = 0; 49 | while (col < SIZE) 50 | { 51 | if (is_valid(board, row, col)) 52 | { 53 | board[row] = col; 54 | put_queen(board, row + 1); 55 | } 56 | col++; 57 | } 58 | } 59 | return (pos); 60 | } 61 | 62 | int ft_ten_queens_puzzle(void) 63 | { 64 | int board[SIZE]; 65 | int row; 66 | 67 | row = 0; 68 | while (row < SIZE) 69 | { 70 | board[row] = -1; 71 | row++; 72 | } 73 | row = 0; 74 | return (put_queen(board, row)); 75 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 0/aff_first_param/aff_first_param.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* aff_first_param.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: Kaizen +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/05/04 22:38:07 by Kaizen #+# #+# */ 9 | /* Updated: 2023/05/04 22:38:07 by Kaizen ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | 21 | if (argc == 1) 22 | write(1, "\0", 1); 23 | else if(argc >= 2) 24 | { 25 | while(argv[1][i]) 26 | write(1, &argv[1][i++], 1); 27 | write(1, "\n", 1); 28 | } 29 | 30 | return 0; 31 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strspn/ft_strspn.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strspn.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | size_t ft_strspn(const char *s, const char *accept) 16 | { 17 | size_t i; 18 | size_t j; 19 | 20 | i = 0; 21 | while (s[i]) 22 | { 23 | j = 0; 24 | while (accept[j]) 25 | { 26 | if (s[i] == accept[j]) 27 | break ; 28 | j++; 29 | } 30 | if (!accept[j]) 31 | break ; 32 | i++; 33 | } 34 | return (i); 35 | } 36 | -------------------------------------------------------------------------------- /DAYS/C09/ex01/README.md: -------------------------------------------------------------------------------- 1 | # Exercise 01: Makefile 2 | - Create the `Makefile` that’ll compile a library `libft.a`. 3 | - Your `makefile` should print all the command it’s running. 4 | - Your `makefile` should not run any unnecessary command. 5 | - The `Makefile` will get its source files from the "srcs" directory. 6 | - Those files will be: `ft_putchar.c`, `ft_swap.c`, `ft_putstr.c`, `ft_strlen.c`, `ft_strcmp.c` 7 | - The `Makefile` will get its header files from the "includes" directory. 8 | - Those files will be: `ft.h` 9 | - It should compile the .c files with gcc and with `-Wall -Wextra -Werror` flags in that order. 10 | - The lib should be at the root of the exercise. 11 | - `.o` files should be near their `.c` file. 12 | - The `Makefile `should also implement the following rules: `clean`, `fclean`, `re`, `all` and of course `libft.a`. 13 | - Running just `make` should be equal to `make all` 14 | - The rule `all` should be equal to `make libft.a`. 15 | - The rule `clean` should remove all the temporary generated files. 16 | - The rule `fclean` should be like a `make clean` plus all the binary made with `make all`. 17 | - The rule `re` should be like a `make fclean` followed by `make all`. 18 | - Your `makefile` should not compile any file for nothing. 19 | - We’ll only fetch your `Makefile` and test it with our files. 20 | - NOTE!: Watch out for whildcards! -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/wdmatch/wdmatch.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* wdmatch.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | void wdmatch(char *s1, char *s2) 16 | { 17 | int len = 0; 18 | int i = 0; 19 | 20 | while (s1[len]) 21 | ++len; 22 | while (*s2 && i < len) 23 | (*s2++ == s1[i]) ? ++i : 0; 24 | if (i == len) 25 | write(1, s1, len); 26 | } 27 | 28 | int main(int ac, char **av) 29 | { 30 | if (ac == 3) 31 | wdmatch(av[1], av[2]); 32 | write(1, "\n", 1); 33 | return (0); 34 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strrev/ft_strrev.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strrev.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou i) 32 | { 33 | tmp = str[i]; 34 | str[i] = str[len]; 35 | str[len] = tmp; 36 | i++; 37 | len--; 38 | } 39 | return (str); 40 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/rot_13/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-1-rot_13.txt==================================== 5 | Assignment name : rot_13 6 | Expected files : rot_13.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes a string and displays it, replacing each of its 11 | letters by the letter 13 spaces ahead in alphabetical order. 12 | 13 | 'z' becomes 'm' and 'Z' becomes 'M'. Case remains unaffected. 14 | 15 | The output will be followed by a newline. 16 | 17 | If the number of arguments is not 1, the program displays a newline. 18 | 19 | Example: 20 | 21 | $>./rot_13 "abc" 22 | nop 23 | $>./rot_13 "My horse is Amazing." | cat -e 24 | Zl ubefr vf Nznmvat.$ 25 | $>./rot_13 "AkjhZ zLKIJz , 23y " | cat -e 26 | NxwuM mYXVWm , 23l $ 27 | $>./rot_13 | cat -e 28 | $ 29 | $> 30 | $>./rot_13 "" | cat -e 31 | $ 32 | $> 33 | ========================================================================================== 34 | ``` 35 | 36 | ### Algorithm 37 | 38 | - There's 26 letters in the alphabet. 39 | - Then 26 / 2 = 13 40 | - Which is the number of the assignment 41 | - Therefore we split the alphabet into 2 42 | - If the input char is in the first half we increment it by 13. 43 | - if the input char is in the second half, we decrement it by 13. -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/last_word/last_word.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* last_word.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: Kaizen +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/05/05 23:11:45 by Kaizen #+# #+# */ 9 | /* Updated: 2023/05/05 23:11:45 by Kaizen ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int i; 18 | 19 | if (argc == 2) 20 | { 21 | i = 0; 22 | while (argv[1][i]) 23 | { 24 | while (argv[1][i] == ' ' || argv[1][i] == '\t' || argv[1][i] != '\0') 25 | i++; 26 | while (argv[1][i] != ' ' && argv[1][i] != '\t' && argv[1][i] != '\0') 27 | { 28 | write(1, &argv[1][i], 1); 29 | i++; 30 | } 31 | break; 32 | } 33 | } 34 | write(1, "\n", 1); 35 | } 36 | -------------------------------------------------------------------------------- /DAYS/Shell00/ex08/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 10 2 | 3 | * In a file called **clear**, place the command line that will search for all files - in the current directory as well as in its sub-directories - end by ~, and/or all files that start or end by # 4 | * The command line will show and erase all files found. 5 | * Only one command is allowed: no ';' or '&&' or other shenanigans. 6 | 7 | HINT: man find 8 | 9 | ------------------------------------------ 10 | ## If we STFE!(Search the Fuc***g Ethernet) we will see that: 11 | 12 | * `find` is the command that can address all the requirements. 13 | * so next we can `man find` and we can with the next solution: 14 | 15 | ``` 16 | $ find . -name "*~" -print -delete -o -name "*#" -print -delete -o -name "#*" -print -delete 17 | 18 | -name [pattern] 19 | Base of file name (the path with the leading directories removed) 20 | matches shell pattern. 21 | -print [format] 22 | -delete: 23 | Delete files; true if removal succeeded. If the removal failed, 24 | an error message is issued. If -delete fails, find's exit status will 25 | be nonzero (when it eventually exits). Use of -delete automatically 26 | turns on the `-depth' option. 27 | -o: 28 | Ensures that the right hand side is evaluated only for those directories 29 | which didn't get deleted before. 30 | ``` 31 | --------------------- 32 | 33 | ```bash 34 | find . -type f \( -name "#*#" -o -name "*~" \) -delete 35 | ``` -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_atoi/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou = 9 && str[i] <= 13)) 23 | i++; 24 | if (str[i] == '-') 25 | { 26 | sign = -1; 27 | i++; 28 | } 29 | else if (str[i] == '+') 30 | i++; 31 | while (str[i] != '\0' && str[i] >= '0' && str[i] <= '9') 32 | { 33 | result *= 10; 34 | result += str[i] - '0'; 35 | i++; 36 | } 37 | return (result * sign); 38 | } -------------------------------------------------------------------------------- /DAYS/C07/ex03/ft_strjoin.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int ft_strlength(char *str) 5 | { 6 | int i; 7 | 8 | i = 0; 9 | while (str[i]) 10 | i++; 11 | return (i); 12 | } 13 | 14 | char *ft_strcpy(char *dest, char *src) 15 | { 16 | int i; 17 | 18 | i = 0; 19 | while (src[i] != '\0') 20 | { 21 | dest[i] = src[i]; 22 | i++; 23 | } 24 | dest[i] = 0; 25 | return (dest); 26 | } 27 | 28 | int ft_strflength(char **strings, int size, int sep_length) 29 | { 30 | int final_length; 31 | int i; 32 | 33 | final_length = 0; 34 | i = 0; 35 | while (i < size) 36 | { 37 | final_length += ft_strlength(strings[i]); 38 | final_length += sep_length; 39 | i++; 40 | } 41 | final_length -= sep_length; 42 | return (final_length); 43 | } 44 | 45 | char *ft_strjoin(int size, char **strs, char *sep) 46 | { 47 | int full_length; 48 | int i; 49 | char *string; 50 | 51 | if (size == 0) 52 | return ((char *)malloc(sizeof(char))); 53 | full_length = ft_strflength(strs, size, ft_strlength(sep)); 54 | string = (char *)malloc((full_length + 1) * sizeof(char)); 55 | if (!string) 56 | return (0); 57 | i = 0; 58 | while (i < size) 59 | { 60 | ft_strcpy(string, strs[i]); 61 | string += ft_strlength(strs[i]); 62 | if (i < size - 1) 63 | { 64 | ft_strcpy(string, sep); 65 | string += ft_strlength(sep); 66 | } 67 | i++; 68 | } 69 | *string = '\0'; 70 | return (string - full_length); 71 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/ft_strdup/ft_strdup.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_strdup.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | #include 15 | 16 | char *ft_strdup(char *src) 17 | { 18 | char *str; 19 | int len; 20 | int index; 21 | 22 | len = 0; 23 | index = 0; 24 | if (src == NULL) 25 | return (NULL); 26 | while (src[len]) 27 | len++; 28 | str = (char *)malloc(sizeof((char) len + 1)); 29 | if (str == NULL) 30 | return (NULL); 31 | while (src[index]) 32 | { 33 | str[index] = src[index]; 34 | index++; 35 | } 36 | str[index] = '\0'; 37 | return ((char *)str); 38 | } 39 | -------------------------------------------------------------------------------- /DAYS/C02/ex00/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_strcpy 2 | 3 | - Reproduce the behavior of the function __strcpy__ (man strcpy). 4 | - Here's how it should be prototyped: 5 | ```C 6 | char *ft_strcpy(char *dest, char *src); 7 | ``` 8 | 9 | ## Understanding strcpy 10 | Syntax: char \*strcpy (char \*destination, const char \*source);\ 11 | 12 | The strcpy() function is used to copy strings. It copies string pointed to by source into the destination. This function accepts two arguments of type pointer to char or array of characters and returns a pointer to the first string i.e destination. Notice that source is preceded by the const modifier because strcpy() function is not allowed to change the source string. 13 | 14 | It is important to note that strcpy() function do not check whether the destination has enough size to store all the characters present in the source. It is the responsibility of the program to make sure that the destination array has enough space to accommodate all the characters of the source string. 15 | 16 | Another important point to note about strcpy() is that you should never pass string literals as a first argument. For example: 17 | 18 | ```C 19 | char ch_arr[] = "string array"; 20 | 21 | strcpy("destination string", c_arr); // wrong 22 | ``` 23 | 24 | Here you are trying to copy the contents of ch_arr to "destination string" which is a string literal. Since modifying a string literal causes undefined behaviour, calling strcpy() in this way may cause the program to crash. -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/last_word/last_word.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* last_word.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | int ft_isblank(char c) 16 | { 17 | if (c == ' ' || c == '\t') 18 | return (1); 19 | return (0); 20 | } 21 | 22 | int main(int ac, char **av) 23 | { 24 | if (ac == 2) 25 | { 26 | while (*av[1]) 27 | av[1]++; 28 | av[1]--; 29 | while (ft_isblank(*av[1])) 30 | av[1]--; 31 | while (*av[1] && !ft_isblank(*av[1])) 32 | av[1]--; 33 | av[1]++; 34 | while (*av[1] && !ft_isblank(*av[1])) 35 | write(1, av[1]++, 1); 36 | } 37 | write(1, "\n", 1); 38 | return (0); 39 | } -------------------------------------------------------------------------------- /DAYS/C01/ex06/ft_strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write(1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers(int i) 9 | { 10 | if (i >= 10) 11 | ft_print_numbers(i / 10); 12 | ft_putchar((i % 10) + '0'); 13 | 14 | } 15 | 16 | int ft_strlen(char *str) 17 | { 18 | int i; 19 | 20 | i = 0; 21 | 22 | while (str[i] != '\0') 23 | { 24 | i++; 25 | } 26 | return (i); 27 | } 28 | 29 | int main() 30 | { 31 | // Declare a pointer to a string literal "karim" 32 | char *c = "younes"; 33 | 34 | // Call ft_strlen with the string and store the result in the variable length 35 | int length = ft_strlen(c); 36 | 37 | // Declare a character array to store the string representation of the length 38 | char len_str[16]; 39 | 40 | // Initialize an index variable to 0 41 | int i = 0; 42 | 43 | // Convert the length to a string representation using a loop that extracts the last digit and adds it to the array 44 | while (length > 0) 45 | { 46 | len_str[i++] = (length % 10) + '0'; 47 | length /= 10; 48 | } 49 | 50 | // Print the string representation of the length in reverse order using a loop 51 | while (--i >= 0) 52 | { 53 | ft_putchar(len_str[i]); 54 | } 55 | 56 | // Print a newline character to separate the outputs 57 | ft_putchar('\n'); 58 | 59 | 60 | // End the program by returning 0 to indicate success 61 | return 0; 62 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/first_word/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-2-first_word.txt================================ 5 | Assignment name : first_word 6 | Expected files : first_word.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes a string and displays its first word, followed by a 11 | newline. 12 | 13 | A word is a section of string delimited by spaces/tabs or by the start/end of 14 | the string. 15 | 16 | If the number of parameters is not 1, or if there are no words, simply display 17 | a newline. 18 | 19 | Examples: 20 | 21 | $> ./first_word "FOR PONY" | cat -e 22 | FOR$ 23 | $> ./first_word "this ... is sparta, then again, maybe not" | cat -e 24 | this$ 25 | $> ./first_word " " | cat -e 26 | $ 27 | $> ./first_word "a" "b" | cat -e 28 | $ 29 | $> ./first_word " lorem,ipsum " | cat -e 30 | lorem,ipsum$ 31 | $> 32 | ========================================================================================== 33 | ``` 34 | 35 | ### Algorithm 36 | 37 | - First we check if the input has 2 arguments 38 | - If true. We go through each character 39 | - We check if that character is not a space and the next character is also not a space. 40 | - If True we enter a loop as long as the current character isn't a space we print it 41 | - Then we break when we reach a space. 42 | - We increment the index. (means that the current char is space.) 43 | - Finally we print a new line. 44 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/alpha_mirror/alpha_mirror.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* alpha_mirror.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int i; 18 | 19 | if (argc == 2) 20 | { 21 | i = 0; 22 | while (argv[1][i]) 23 | { 24 | if (argv[1][i] >= 'a' && argv[1][i] <= 'z') 25 | argv[1][i] = ('m' - (argv[1][i] - 'n')); 26 | else if (argv[1][i] >= 'A' && argv[1][i] <= 'Z') 27 | argv[1][i] = ('M' - (argv[1][i] - 'N')); 28 | write(1, &argv[1][i], 1); 29 | i++; 30 | } 31 | 32 | } 33 | write(1, "\n", 1); 34 | return 0; 35 | } -------------------------------------------------------------------------------- /DAYS/Shell01/ex03/README.md: -------------------------------------------------------------------------------- 1 | # Exercise 03: count_files 2 | 3 | - Write a command line that counts and displays the number of regular files and directories in the current directory and all its sub-directories. It should include ".", the starting directory. 4 | - Example of output: 5 | ``` 6 | $>./count_files.sh | cat -e 7 | 42$ 8 | $> 9 | ``` 10 | 11 | ------------------------------------------ 12 | ## Using your favorite search engine go for: 13 | `Recursively counting files in a Linux directory` 14 | And you will encounter a variety of answers that range from not necessary to 15 | very useful. I found a very nice page with all that we need 16 | [here](https://stackoverflow.com/questions/9157138/recursively-counting-files-in-a-linux-directory). 17 | As we can see (if this page still exist when you search for it, if not we always 18 | have [Wayback Machine](http://archive.org/web/web.php)) the first answer gives 19 | us this: 20 | `find DIR_NAME -type f | wc -l` 21 | 22 | **Explanation:** 23 | * Replace *DIR_NAME* with __.__ to execute the command in the current folder. 24 | * We remove the __-type f__ because that limits the search to ONLY files. 25 | * __|__ redirects find command's standard output to wc command's standard input. 26 | * __wc__ (short for word count) counts newlines, words and bytes on its input. 27 | * __-l__ to count just newlines. 28 | 29 | **Result:** 30 | `find . | wc -l` 31 | 32 | > Note: remember to make the file executable so we don't end up with this error 33 | message: 'bash: ./count_files.sh: Permission denied' by running this command: 34 | __chmod u+x count_files.sh__. -------------------------------------------------------------------------------- /DAYS/C04/ex05/ft_atoi_base.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int ft_check(char *str) 4 | { 5 | int i; 6 | int j; 7 | 8 | i = 0; 9 | if (str[0] == '\0' || str[1] == '\0') 10 | return (0); 11 | while (str[i]) 12 | { 13 | if (str[i] <= 32 || str[i] == 127 || str[i] == 43 || str[i] == 45) 14 | return (0); 15 | j = i + 1; 16 | while (str[j] != '\0') 17 | { 18 | if (str[i] == str[j]) 19 | return (0); 20 | j++; 21 | } 22 | i++; 23 | } 24 | return (i); 25 | } 26 | 27 | int ft_base(char str, char *base) 28 | { 29 | int nb; 30 | 31 | nb = 0; 32 | while (base[nb] != '\0') 33 | { 34 | if (str == base[nb]) 35 | return (nb); 36 | nb++; 37 | } 38 | return (-1); 39 | } 40 | 41 | int ft_spaces(char *str, int *ptr_i) 42 | { 43 | int sign; 44 | int i; 45 | 46 | i = 0; 47 | while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) 48 | i++; 49 | sign = 1; 50 | while (str[i] && (str[i] == 43 || str[i] == 45)) 51 | { 52 | if (str[i] == 45) 53 | sign *= -1; 54 | i++; 55 | } 56 | *ptr_i = i; 57 | return (sign); 58 | } 59 | 60 | int ft_atoi_base(char *str, char *base) 61 | { 62 | int i; 63 | int sign; 64 | int nb; 65 | int nb2; 66 | int base_length; 67 | 68 | nb = 0; 69 | i = 0; 70 | base_length = ft_check(base); 71 | if (base_length >= 2) 72 | { 73 | sign = ft_spaces(str, &i); 74 | nb2 = ft_base(str[i], base); 75 | while (nb2 != -1) 76 | { 77 | nb = (nb * base_length) + nb2; 78 | i++; 79 | nb2 = ft_base(str[i], base); 80 | } 81 | return (nb *= sign); 82 | } 83 | return (0); 84 | } 85 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/first_word/first_word.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* first_word.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: Kaizen +#+ +:+ +#+ */ 7 | /* +#+#+#+#+#+ +#+ */ 8 | /* Created: 2023/05/11 20:45:09 by Kaizen #+# #+# */ 9 | /* Updated: 2023/05/11 20:45:09 by Kaizen ### ########.fr */ 10 | /* */ 11 | /* ************************************************************************** */ 12 | 13 | #include 14 | 15 | int main(int argc, char **argv) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | 21 | if (argc == 2) 22 | { 23 | while (argv[1][i]) 24 | { 25 | while (argv[1][i] == ' ' || argv[1][i] == '\t' || argv[1][i] == '\n') 26 | i++; 27 | while (argv[1][i] != ' ' && argv[1][i] != '\t' && argv[1][i] != '\n' && argv[1][i] != '\0') 28 | { 29 | write(1, &argv[1][i], 1); 30 | i++; 31 | } 32 | break; 33 | } 34 | write(1, "\n", 1); 35 | } 36 | else 37 | write(1, "\n", 1); 38 | } -------------------------------------------------------------------------------- /RUSH/rush01.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush01.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou = 1 && y >= 1 ) 39 | { 40 | while (li_c <= y) 41 | { 42 | if (li_c == 1) 43 | ft_print(x, '/', '*', '\\'); 44 | else if (li_c == y) 45 | ft_print(x, '\\', '*', '/'); 46 | else 47 | ft_print(x, '*', ' ', '*'); 48 | li_c++; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /DAYS/C03/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 07: ft_strncmp 2 | - Reproduce the behavior of the function __strncmp__ (man strncmp). 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_strncmp(char *s1, char *s2, unsigned int n); 6 | ``` 7 | 8 | ## Understanding __strncmp__ 9 | 10 | ### Description 11 | The strncmp() function is used to compare two strings two strings str1 and str2. If two strings are same then strncmp() returns 0, otherwise, it returns a non-zero value. 12 | The strncmp() function compares not more than n characters. Because strncmp() is designed for comparing strings rather than binary data, characters that appear after a `\0' character are not compared. 13 | 14 | ### Return values 15 | The strcmp() and strncmp() functions return an integer greater than, equal to, or less than 0, according as the string s1 is greater than, equal to, or less than the string s2. The comparison is done using unsigned characters, so that '\200' is greater than '\0'. 16 | 17 | | Value | Meaning | 18 | |---|----| 19 | | < 0| str1 < str2 20 | | 0|str1 == str2 21 | | > 0 | str1 > str2 22 | 23 | ## Solution 24 | - declare an unsigned int variable and initialize it to 0 (index). 25 | - check if the (n) == 0 is so we return (0). 26 | - we go through a while loop as long as the nth character from str1 is == to the same nth character from str2. And al song as we didn't reach the end of the str1. 27 | - if (1) is less than (n - 1) (-1 because we start counting from 0) 28 | - we increment (1). 29 | - else we return (0), which means str1 and str2 are identical. 30 | - Finally we return str1[i] - str2[i]. Which means strings are different and we return the different between them. -------------------------------------------------------------------------------- /DAYS/C02/ex10/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 10: ft_strlcpy 2 | - Reproduce the behavior of the function strlcpy (man strlcpy). 3 | - Here's how it should be prototyped: 4 | ```C 5 | unsigned inft_strlcpyt (char *dest, char *src, unsigned int size); 6 | ``` 7 | ## Understanding strlcpy 8 | ### Description: 9 | - The strlcpy() and strlcat() functions copy and concatenate strings with the same input parameters and output result as snprintf(3). They are designed to be safer, more consistent, and less error prone replacements for the easily misused functions strncpy(3) and strncat(3). strlcpy() and strlcat() take the full size of the destination buffer and guarantee NUL-termination if there is room. Note that room for the NUL should be included in dstsize. strlcpy() copies up to dstsize - 1 characters from the string src to dst, NUL-terminating the result if dstsize is not 0. 10 | 11 | - The strcpy() function copies string s2 to s1, including the terminating null character, stopping after the null character has been copied. The strncpy() function copies exactly n bytes, truncating s2 or adding null characters to s1 if necessary. The result will not be null-terminated if the length of s2 is n or more. Each function returns s1. If copying takes place between objects that overlap, the behavior of strcpy(), strncpy(), and strlcpy() is undefined.\ 12 | The strlcpy() function copies at most dstsize−1 characters (dstsize being the size of the string buffer dst) from src to dst, truncating src if necessary. The result is always null-terminated. The function returns strlen(src). Buffer overflow can be checked as follows: 13 | ```C 14 | if (strlcpy(dst, src, dstsize) >= dstsize) 15 | return −1; 16 | ``` 17 | -------------------------------------------------------------------------------- /DAYS/C04/ex03/ft_atoi.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* ft_atoi.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | int whitespaces(char *str, int *ptr_i) 16 | { 17 | int count; 18 | int i; 19 | 20 | i = 0; 21 | count = 1; 22 | while ((str[i] >= 9 && str[i] <= 13) || str[i] == 32) 23 | i++; 24 | while (str[i] && (str[i] == 43 || str[i] == 45)) 25 | { 26 | if (str[i] == 45) 27 | count *= -1; 28 | i++; 29 | } 30 | *ptr_i = i; 31 | return (count); 32 | } 33 | 34 | int ft_atoi(char *str) 35 | { 36 | int sign; 37 | int result; 38 | int i; 39 | 40 | result = 0; 41 | sign = whitespaces(str, &i); 42 | while (str[i] && str[i] >= 48 && str[i] <= 57) 43 | { 44 | result *= 10; 45 | result += str[i] - 48; 46 | i++; 47 | } 48 | result *= sign; 49 | return (result); 50 | } 51 | -------------------------------------------------------------------------------- /DAYS/C07/ex05/ft_split.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int g_len; 4 | 5 | int is_sep(char c, char *sep) 6 | { 7 | int i; 8 | 9 | i = 0; 10 | while (sep[i]) 11 | { 12 | if (c == sep[i]) 13 | return (1); 14 | i++; 15 | } 16 | return (0); 17 | } 18 | 19 | int word_count(char *str, char *sep) 20 | { 21 | int i; 22 | int count; 23 | int word; 24 | 25 | i = 0; 26 | count = 0; 27 | word = 1; 28 | while (str[i]) 29 | { 30 | if (!is_sep(str[i], sep)) 31 | { 32 | if (word == 1) 33 | count++; 34 | word = 0; 35 | } 36 | else 37 | word = 1; 38 | i++; 39 | } 40 | return (count); 41 | } 42 | 43 | char *ft_strdup(char *str, int *index, char *sep) 44 | { 45 | char *word; 46 | int i; 47 | 48 | g_len = 0; 49 | i = *index; 50 | while (is_sep(str[i], sep)) 51 | i++; 52 | *index = i; 53 | while (str[i] && !is_sep(str[i], sep)) 54 | { 55 | i++; 56 | g_len++; 57 | } 58 | word = malloc(sizeof(char) * (g_len + 1)); 59 | if (!word) 60 | return (NULL); 61 | word[g_len] = '\0'; 62 | i = 0; 63 | while (str[*index] && !is_sep(str[*index], sep)) 64 | { 65 | word[i] = str[*index]; 66 | i++; 67 | (*index)++; 68 | } 69 | return (word); 70 | } 71 | 72 | char **ft_split(char *str, char *charset) 73 | { 74 | char **words_arr; 75 | int index; 76 | int wc; 77 | int i; 78 | 79 | i = 0; 80 | index = 0; 81 | wc = word_count(str, charset); 82 | words_arr = malloc(sizeof(char *) * (wc + 1)); 83 | if (!words_arr) 84 | return (NULL); 85 | words_arr[wc] = 0; 86 | while (i < wc) 87 | { 88 | words_arr[i] = ft_strdup(str, &index, charset); 89 | i++; 90 | } 91 | return (words_arr); 92 | } 93 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/ulstr/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-0-ulstr.txt===================================== 5 | Assignment name : ulstr 6 | Expected files : ulstr.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program that takes a string and reverses the case of all its letters. 11 | Other characters remain unchanged. 12 | 13 | You must display the result followed by a '\n'. 14 | 15 | If the number of arguments is not 1, the program displays '\n'. 16 | 17 | Examples : 18 | 19 | $>./ulstr "L'eSPrit nE peUt plUs pRogResSer s'Il staGne et sI peRsIsTent VAnIte et auto-justification." | cat -e 20 | l'EspRIT Ne PEuT PLuS PrOGrESsER S'iL STAgNE ET Si PErSiStENT vaNiTE ET AUTO-JUSTIFICATION.$ 21 | $>./ulstr "S'enTOuRer dE sECreT eSt uN sIGnE De mAnQuE De coNNaiSSanCe. " | cat -e 22 | s'ENtoUrER De SecREt EsT Un SigNe dE MaNqUe dE COnnAIssANcE. $ 23 | $>./ulstr "3:21 Ba tOut moUn ki Ka di KE m'en Ka fe fot" | cat -e 24 | 3:21 bA ToUT MOuN KI kA DI ke M'EN kA FE FOT$ 25 | $>./ulstr | cat -e 26 | $ 27 | ========================================================================================== 28 | ``` 29 | 30 | ## Algorithm 31 | 32 | - First we check if the input is 2 `argc` 33 | - If true. We go through each character of the second argument of the input. 34 | - We check if the character is lowercase. 35 | - If True. We print it in uppercase. (by subtracting 32 from it) 36 | - We check if the character is uppercase. 37 | - If True. We print it in lowercase. (by adding 32 from it) 38 | - Else we print the char as it is. 39 | - Finally we print a new line. 40 | -------------------------------------------------------------------------------- /DAYS/C04/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_atoi 2 | + Reproduce the behavior of the function atoi (man atoi). 3 | + Here's how it should be prototyped: 4 | ```C 5 | int ft_atoi(char *str); 6 | ``` 7 | + Files to turn in: ft_atoi.c 8 | + Allowed functions: Nothing 9 | 10 | ## [atoi description](https://www.ibm.com/docs/en/i/7.4?topic=functions-atoi-convert-character-string-integer) 11 | + The atoi() function converts a character string to an integer value. The input string is a sequence of characters that can be interpreted as a numeric value of the specified return type. The function stops reading the input string at the first character that it cannot recognize as part of a number. This character can be the null character that ends the string. 12 | * The atoi() function does not recognize decimal points or exponents. The string argument for this function has the form:\ 13 | `whitespaces +/- digits` 14 | * whitespace characters are space `(' ')`, tab `('\t')`, carriage return `('\r')`, newline `('\n')`, vertical tab `('\v')` and formfeed `('\f')`. 15 | * where whitespace consists of the same characters for which the isspace() function is true, such as spaces and tabs. The atoi() function ignores leading white-space characters. The value digits represents one or more decimal digits. 16 | * Return value: The atoi() function returns an int value that is produced by interpreting the input characters as a number. The return value is 0 if the function cannot convert the input to a value of that type. The return value is undefined in the case of an overflow. 17 | 18 | ## Notes 19 | - Using (\*str++) instead of "**i**" won't work! it's gonna work just for the first time. 20 | - \*str++: pointer arithmetic. 21 | - i: using index. -------------------------------------------------------------------------------- /DAYS/C05/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 05: ft_sqrt 2 | - Create a function that returns the square root of a number (if it exists), or 0 if the square root is an irrational number. 3 | - Here's how it should be prototyped: 4 | ```C 5 | int ft_sqrt(int nb); 6 | ``` 7 | 8 | ## Understanding Squares and Square Roots 9 | ### Squares 10 | - To square a number: multiply it by itself. 11 | 12 | ![pic alt](https://github.com/achrafelkhnissi/Computer-Science/blob/master/1337/imgs/3_squared.png) 13 | 14 | - Squares From 0^2 to 6^2 15 | 16 | | | | | | ||| 17 | |--|--|--|--|--|--|--| 18 | |0 Square |=| 0^2 |=| 0 * 0 |=| 0 19 | |1 Square |=| 1^2 |=| 1 * 1 |=| 1 20 | |2 Square |=| 2^2 |=| 2 * 2 |=| 4 21 | |3 Square |=| 3^2 |=| 3 * 3 |=| 9 22 | |4 Square |=| 4^2 |=| 4 * 4 |=| 16 23 | |5 Square |=| 5^2 |=| 5 * 5 |=| 25 24 | |6 Square |=| 6^2 |=| 6 * 6 |=| 36 25 | 26 | - The squares are also on the [Multiplication - Times Tables](https://www.mathsisfun.com/tables.html). 27 | 28 | ### Negative Numbers 29 | - We can also square **negative numbers**. 30 | - Example: What happens when we square (-5)? 31 | - Answer: (-5) * (-5) = 25. (Because [Multiplying Negatives Makes A Positive](https://www.mathsisfun.com/multiplying-negatives.html)). 32 | - When a square is **negative** number we get a positive result, just the same as squaring positive numbers. 33 | 34 | ### Square Roots 35 | - A **square root** goes the other way: 3 squared is 9, so square root of 9 is 3. 36 | 37 | ![pic alt](https://github.com/achrafelkhnissi/Computer-Science/blob/master/1337/imgs/square_roots.png) 38 | 39 | - A square root of a number is a value that can be multiplied by itself to give the original number. It is like asking: What can we multiply by itself to get this? -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/inter/inter.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* inter.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | int check_doubles(char *str, char c, int pos) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (i < pos) 21 | { 22 | if (str[i] == c) 23 | return (0); 24 | i++; 25 | } 26 | return (1); 27 | } 28 | void inter(char *str, char *str1) 29 | { 30 | int i; 31 | int j; 32 | 33 | i = 0; 34 | while (str[i] != '\0') 35 | { 36 | j = 0; 37 | while (str1[j] != '\0') 38 | { 39 | if (str[i] == str1[j]) 40 | { 41 | if (check_doubles(str, str[i], i) == 1) 42 | { 43 | write(1, &str[i], 1); 44 | break; 45 | } 46 | } 47 | j++; 48 | } 49 | i++; 50 | } 51 | } 52 | int main(int ac, char **av) 53 | { 54 | 55 | if (ac == 3) 56 | inter(av[1], av[2]); 57 | write(1, "\n", 1); 58 | return (0); 59 | } -------------------------------------------------------------------------------- /RUSH/rush00.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush00.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou = 1 && y >= 1 ) 39 | { 40 | while (line_counter <= y) 41 | { 42 | if (line_counter == 1) 43 | ft_print(x, 'o', '-', 'o'); 44 | else if (line_counter == y) 45 | ft_print(x, 'o', '-', 'o'); 46 | else 47 | ft_print(x, '|', ' ', '|'); 48 | line_counter++; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /RUSH/rush02.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* rush03.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou = 1 && y >= 1 ) 39 | { 40 | while (line_counter <= y) 41 | { 42 | if (line_counter == 1) 43 | ft_print(x, 'A', 'B', 'A'); 44 | else if (line_counter == y) 45 | ft_print(x, 'C', 'B', 'C'); 46 | else 47 | ft_print(x, 'B', ' ', 'B'); 48 | line_counter++; 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/wdmatch/wdmatch2.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* wdmatch2.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | void ft_putstr(char *str) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | { 22 | write(1, &str[i], 1); 23 | i++; 24 | } 25 | } 26 | 27 | int ft_strlen(char *str) 28 | { 29 | int i; 30 | 31 | i = 0; 32 | while (str[i] != '\0') 33 | i++; 34 | return (i); 35 | } 36 | 37 | int main(int ac, char **av) 38 | { 39 | int i; 40 | int j; 41 | int wdlen; 42 | 43 | i = 0; 44 | j = 0; 45 | wdlen = 0; 46 | if (ac == 3) 47 | { 48 | while (av[1][i] != '\0') 49 | { 50 | while (av[2][j] != '\0') 51 | { 52 | if (av[1][i] == av[2][j]) 53 | { 54 | wdlen++; 55 | break ; 56 | } 57 | j++; 58 | } 59 | i++; 60 | } 61 | if (wdlen == ft_strlen(av[1])) 62 | ft_putstr(av[1]); 63 | } 64 | write(1, "\n", 1); 65 | return (0); 66 | } -------------------------------------------------------------------------------- /DAYS/C00/ex05/README.md: -------------------------------------------------------------------------------- 1 | ## EXERCISE 05 2 | * Create a function that displays all different combinations of three different digits in ascending order, listed by ascending order - yes, repetition is voluntary. 3 | * Here's the intended output: 4 | ``` 5 | $>./a.out | cat -e 6 | 012, 013, 014, 015, 016, 017, 018, 019, 023, ..., 789$> 7 | ``` 8 | * 987 isn't there because 789 already is. 9 | * 999 isn't there because digit 9 is present more than once. 10 | * Here's how it should be prototyped: 11 | ```C 12 | void ft_print_comb(void); 13 | ``` 14 | + Files to turn in: ft_print_comb.c 15 | + Allowed functions: ft_putchar 16 | 17 | 18 | ## Solution 19 | 20 | - Considering d = digit, so d3 d2 d1 21 | and because the digits has to be listed in ascending order 22 | we need to start from 000, but remember repetition isn't allowed. 23 | let's start with the possibilities. 24 | some number has to go fist and there is 10 possibilities. 25 | We gonna start with d1 because that's the first number 26 | we can put 10 possibilities there from 0 to 9, d3 d2 9 27 | now but things gets a little different for the second number 28 | we no longer have 10 options because whatever digit does first 29 | we can't use it again. 30 | So now there is only 9 possibilities (0 to 8): d3 8 9 31 | then for the third digit we there are now 8 possibilities 32 | (0 to 7): 7 8 9. 33 | 34 | - We notice that it starts with 012 and ends with 789 35 | in other words if 36 | - d3 = n 37 | - d2 = d3 + 1 38 | - d1 = d2 + 1 39 | 40 | - The ```ft_putchar(d + '0')``` 41 | We know that if the input is char representation of a digit 42 | and we want to get the actual value of that digit we need 43 | to use ```d - '0'``` taking in consideration that 'd' is 44 | a char data type. 45 | Therefore if we want to opsite we reverse the formula. -------------------------------------------------------------------------------- /DAYS/C05/ex03/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 03: ft_recursive_power 2 | - Create a recursive function that returns the value of a power applied to a number. 3 | - Same conditions as before. 4 | - Here's how it should be prototyped: 5 | ```C 6 | int ft_recursive_power(int nb, int power); 7 | ``` 8 | 9 | ## Understanding Power (exponent) 10 | - The power (exponent) of a number says how many times to use the number in a multiplication. 11 | - In **8^2** the "2" says to use 8 twice in a multiplication, so `8^2 = 8 * 8 = 64` 12 | - Exponents are also called Power or Indices. 13 | 14 | ### In General 15 | - **a^n** tells you to multiply **a** by itself, so there are **n** of those **a**'s: 16 | 17 | ![pic alt](https://github.com/achrafelkhnissi/Computer-Science/blob/master/1337/imgs/exponent-definition.gif) 18 | 19 | ### Negative Exponents 20 | - [Example](https://www.mathsisfun.com/exponent.html) 21 | - [Laws of Exponents](https://www.mathsisfun.com/algebra/exponent-laws.html) 22 | - [Negative Exponents Explained! - YouTube](https://www.youtube.com/watch?v=TKj8kEofbAw) 23 | 24 | ## Problems i faced 25 | - I tried to pass the number and the power from (argv) but i had unexpected results. 26 | - I Basically forgot the formula. Which is: `result = nb * recursive_power(nb, power)` 27 | - Forget the right base case: power == 0 28 | 29 | ## Notes 30 | - Works exactly the same way as the recursive power formula. 31 | - Assuming nb = 8, power = 3; 32 | - result = 1; 33 | - result = nb * r_power(nb, power - 1); 34 | - (1) result = 8 * r_power(8, 2); 35 | - (2) result = 8 * r_power(8, 1); 36 | - (3) result = 8 * r_power(8, 0); (when power reaches 0 the function returns result); 37 | 38 | - (3) result = 8 * 1 = 8 -> returns to (2) 39 | - (2) result = 8 * 8 = 64 -> returns to (1) 40 | - (1) result = 8 * 64 = 512 -> returns to main 41 | - result = 521 42 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/search_and_replace/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-0-search_and_replace.txt======================== 5 | Assignment name : search_and_replace 6 | Expected files : search_and_replace.c 7 | Allowed functions: write, exit 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program called search_and_replace that takes 3 arguments, the first 11 | arguments is a string in which to replace a letter (2nd argument) by 12 | another one (3rd argument). 13 | 14 | If the number of arguments is not 3, just display a newline. 15 | 16 | If the second argument is not contained in the first one (the string) 17 | then the program simply rewrites the string followed by a newline. 18 | 19 | Examples: 20 | $>./search_and_replace "Papache est un sabre" "a" "o" 21 | Popoche est un sobre 22 | $>./search_and_replace "zaz" "art" "zul" | cat -e 23 | $ 24 | $>./search_and_replace "zaz" "r" "u" | cat -e 25 | zaz$ 26 | $>./search_and_replace "jacob" "a" "b" "c" "e" | cat -e 27 | $ 28 | $>./search_and_replace "ZoZ eT Dovid oiME le METol." "o" "a" | cat -e 29 | ZaZ eT David aiME le METal.$ 30 | $>./search_and_replace "wNcOre Un ExEmPle Pas Facilw a Ecrirw " "w" "e" | cat -e 31 | eNcOre Un ExEmPle Pas Facile a Ecrire $ 32 | ========================================================================================== 33 | ``` 34 | 35 | ### Algorithm 36 | 37 | - We first check if the `argc == 4` and the length of `argv[2] == 1 && argv[3] == 1` 38 | - to make sure that the input is valid. 39 | - If the input is valid we go through the input string `argv[1]` character by character 40 | - Then we check if the current character if equal to the character in `argv[2]` 41 | - If so. We print the character in `argv[3]` 42 | - Else we print the character. 43 | - Finally we print a new line. 44 | -------------------------------------------------------------------------------- /DAYS/Shell00/ex01/testDay00.sh: -------------------------------------------------------------------------------- 1 | # **************************************************************************** # 2 | # # 3 | # ::: :::::::: # 4 | # testDay00.sh :+: :+: :+: # 5 | # +:+ +:+ +:+ # 6 | # By: marvin +#+ +:+ +#+ # 7 | # +#+#+#+#+#+ +#+ # 8 | # Created: 2021/11/28 09:31:29 by ael-khni #+# #+# # 9 | # Updated: 2023/04/29 18:40:11 by marvin ### ########.fr # 10 | # # 11 | # **************************************************************************** # 12 | 13 | #!/bin/bash 14 | 15 | #------------------------------------------------------------------------------- 16 | mkfile 40 testDay00 && touch -amt 202106012342 testDay00 17 | #Create and change file timestamp to a specified timeline. 18 | #------------------------------------------------------------------------------- 19 | #fallocate -l 40 testShell00 # Or use dd file. 20 | #Change file size, you can use dd file if you want, check man dd. 21 | #------------------------------------------------------------------------------- 22 | chmod 455 testDay00 23 | #Change file attributs. 24 | #------------------------------------------------------------------------------- 25 | tar -cf testDay00.tar testDay00 26 | tar --extract -f testDay00.tar 27 | #Archive the file && extract it 28 | #------------------------------------------------------------------------------- 29 | stat testDay00 30 | #Display file status. 31 | #------------------------------------------------------------------------------- -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/last_word/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./2-0-last_word.txt========================================= 5 | Assignment name : last_word 6 | Expected files : last_word.c 7 | Allowed functions: write 8 | -------------------------------------------------------------------------------------------------- 9 | 10 | Write a program that takes a string and displays its last word followed by a \n. 11 | 12 | A word is a section of string delimited by spaces/tabs or by the start/end of 13 | the string. 14 | 15 | If the number of parameters is not 1, or there are no words, display a newline. 16 | 17 | Example: 18 | 19 | $> ./last_word "FOR PONY" | cat -e 20 | PONY$ 21 | $> ./last_word "this ... is sparta, then again, maybe not" | cat -e 22 | not$ 23 | $> ./last_word " " | cat -e 24 | $ 25 | $> ./last_word "a" "b" | cat -e 26 | $ 27 | $> ./last_word " lorem,ipsum " | cat -e 28 | lorem,ipsum$ 29 | $> 30 | ================================================================================================== 31 | ``` 32 | 33 | ### Algorithm 34 | 35 | - First we check if the input arguments are 2. 36 | - If True. We get the index of the last word. 37 | - Then we go through the last word as long as it is not a whitespace character. 38 | - We print that word. 39 | - Finally we print a new line. 40 | 41 | #### Getting the index of the last word 42 | - First we get the length of the string (so we can start from the last character) 43 | - We go through each character from the last element. 44 | - We check if the current character is not a space as well as the character before it. 45 | - If true we break from the loop (mean we found a word) 46 | - Else we decrement the index variable. 47 | - If we found the word. 48 | - we go through each character backward and decrement the index as long as it's not a space 49 | - and the index is not 0. 50 | - We return the index. 51 | -------------------------------------------------------------------------------- /DAYS/C07/ex04/ft_convert_base.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char *ft_putnbr_base(int nbr, char *base); 5 | int space(char c); 6 | int g_bl; 7 | int g_res; 8 | int g_sig; 9 | int g_i; 10 | 11 | void start(char *str) 12 | { 13 | g_sig = 1; 14 | g_i = 0; 15 | while (str[g_i] == '\t' || str[g_i] == '\n' || str[g_i] == '\f' 16 | || str[g_i] == '\r' || str[g_i] == ' ' || str[g_i] == '\v' 17 | || str[g_i] == '+' || str[g_i] == '-') 18 | { 19 | if (str[g_i] == '+' || str[g_i] == '-') 20 | { 21 | if (str[g_i] == '-') 22 | g_sig *= -1; 23 | } 24 | g_i++; 25 | } 26 | } 27 | 28 | int valid(char *str) 29 | { 30 | int i; 31 | int j; 32 | int count; 33 | 34 | if (str[0] == '\0' || str[1] == '\0') 35 | return (0); 36 | i = 0; 37 | count = 0; 38 | while (str[i]) 39 | { 40 | if (str[i] == '-' || str[i] == '+' || space(str[i])) 41 | return (0); 42 | j = i + 1; 43 | while (str[j]) 44 | { 45 | if (str[i] == str[j]) 46 | return (0); 47 | j++; 48 | } 49 | i++; 50 | } 51 | return (1); 52 | } 53 | 54 | int pos(char *s, char c) 55 | { 56 | int i; 57 | 58 | i = 0; 59 | while (s[i]) 60 | { 61 | if (s[i] == c) 62 | return (i); 63 | i++; 64 | } 65 | return (-1); 66 | } 67 | 68 | int ft_atoi_base(char *str, char *base) 69 | { 70 | g_bl = 0; 71 | g_res = 0; 72 | if (!str || !base) 73 | return (0); 74 | while (base[g_bl]) 75 | g_bl++; 76 | if (valid(base)) 77 | { 78 | start(str); 79 | while (str[g_i] && pos(base, str[g_i]) != -1) 80 | { 81 | g_res = (g_res * g_bl) + pos(base, str[g_i]); 82 | g_i++; 83 | } 84 | } 85 | return (g_res * g_sig); 86 | } 87 | 88 | char *ft_convert_base(char *nbr, char *base_from, char *base_to) 89 | { 90 | char *output; 91 | int a; 92 | 93 | if (!nbr || !(valid(base_from)) || !(valid(base_to))) 94 | return (0); 95 | a = ft_atoi_base(nbr, base_from); 96 | output = ft_putnbr_base(a, base_to); 97 | return (output); 98 | } 99 | -------------------------------------------------------------------------------- /EXAMS/LEVEL 2/union/union.c: -------------------------------------------------------------------------------- 1 | /* ************************************************************************** */ 2 | /* */ 3 | /* ::: :::::::: */ 4 | /* union.c :+: :+: :+: */ 5 | /* +:+ +:+ +:+ */ 6 | /* By: abmouhou 14 | 15 | int check_doubles2(char *str, char c) 16 | { 17 | int i; 18 | 19 | i = 0; 20 | while (str[i] != '\0') 21 | { 22 | if (str[i] == c) 23 | return (0); 24 | i++; 25 | } 26 | return (1); 27 | } 28 | 29 | int check_doubles1(char *str, char c, int pos) 30 | { 31 | int i; 32 | 33 | i = 0; 34 | while (i < pos) 35 | { 36 | if (str[i] == c) 37 | return (0); 38 | i++; 39 | } 40 | return (1); 41 | } 42 | 43 | void ft_union(char *str, char *str1) 44 | { 45 | int i; 46 | 47 | i = 0; 48 | while (str[i] != '\0') 49 | { 50 | if (check_doubles1(str, str[i], i) == 1) 51 | write(1, &str[i], 1); 52 | i++; 53 | } 54 | i = 0; 55 | while (str1[i] != '\0') 56 | { 57 | if (check_doubles2(str, str1[i]) == 1) 58 | { 59 | if (check_doubles1(str1, str1[i], i) == 1) 60 | write(1, &str1[i], 1); 61 | } 62 | i++; 63 | } 64 | } 65 | 66 | int main(int ac, char **av) 67 | { 68 | if (ac == 3) 69 | ft_union(av[1], av[2]); 70 | write(1, "\n", 1); 71 | return (0); 72 | } -------------------------------------------------------------------------------- /DAYS/C02/ex01/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 04: ft_strncpy 2 | 3 | - Reproduce the behavior of the function __strncpy__ (man strncpy). 4 | - Here's how it should be prototyped: 5 | ```C 6 | char *ft_strncpy(char *dest, char *src, unsigned int n); 7 | ``` 8 | 9 | ## Understanding strncpy 10 | ### Description: 11 | The stpncpy() and strncpy() functions copy at most len characters 12 | from src into dst. If src is less than len characters long, the 13 | remainder of dst is filled with `\0' characters. Otherwise, dst is 14 | not terminated. 15 | 16 | ### Return Values 17 | The strcpy() and strncpy() functions return dst. The stpcpy() and 18 | stpncpy() functions return a pointer to the terminating `\0' character of dst. If stpncpy() does not terminate dst with a NUL character, it instead returns a pointer to dst[n] \(which does not necessarily refer to a valid memory location.) 19 | 20 | ### Examples 21 | - The following sets chararray to ''abc\0\0\0'': 22 | 23 | ```C 24 | char chararray[6]; 25 | 26 | (void)strncpy(chararray, "abc", sizeof(chararray)); 27 | ``` 28 | 29 | - The following sets chararray to ''abcdef'': 30 | 31 | ```C 32 | char chararray[6]; 33 | 34 | (void)strncpy(chararray, "abcdefgh", sizeof(chararray)); 35 | ``` 36 | 37 | Note that it does not NUL terminate chararray because the length ofthe source string is greater than or equal to the length argument. 38 | 39 | - The following copies as many characters from input to buf as will 40 | fit and NUL terminates the result. Because strncpy() does not guarantee to NUL terminate the string itself, this must be done explicitly. 41 | 42 | ```C 43 | char buf[1024]; 44 | 45 | (void)strncpy(buf, input, sizeof(buf) - 1); 46 | buf[sizeof(buf) - 1] = '\0'; 47 | ``` 48 | 49 | This could be better achieved using strlcpy(3), as shown in the following example: 50 | 51 | ```C 52 | (void)strlcpy(buf, input, sizeof(buf)); 53 | ``` 54 | 55 | Note that because strlcpy(3) is not defined in any standards, it should only be used when portability is not a concern. -------------------------------------------------------------------------------- /EXAMS/LEVEL 1/repeat_alpha/README.md: -------------------------------------------------------------------------------- 1 | ## Exercise 2 | 3 | ``` 4 | ======================================./1-0-repeat_alpha.txt============================== 5 | Assignment name : repeat_alpha 6 | Expected files : repeat_alpha.c 7 | Allowed functions: write 8 | ------------------------------------------------------------------------------------------ 9 | 10 | Write a program called repeat_alpha that takes a string and display it 11 | repeating each alphabetical character as many times as its alphabetical index, 12 | followed by a newline. 13 | 14 | 'a' becomes 'a', 'b' becomes 'bb', 'e' becomes 'eeeee', etc... 15 | 16 | Case remains unchanged. 17 | 18 | If the number of arguments is not 1, just display a newline. 19 | 20 | Examples: 21 | 22 | $>./repeat_alpha "abc" 23 | abbccc 24 | $>./repeat_alpha "Alex." | cat -e 25 | Alllllllllllleeeeexxxxxxxxxxxxxxxxxxxxxxxx.$ 26 | $>./repeat_alpha 'abacadaba 42!' | cat -e 27 | abbacccaddddabba 42!$ 28 | $>./repeat_alpha | cat -e 29 | $ 30 | $> 31 | $>./repeat_alpha "" | cat -e 32 | $ 33 | $> 34 | ========================================================================================== 35 | ``` 36 | 37 | ## Algorithm 38 | 39 | - First check if the `argc` is 2 40 | - If so. Go through each character of the second argument `argv[1]` because the first argument is the name of the program. 41 | - As long as the character isn't `\0` we check if the character is an alphabetical character. 42 | - If so we get the index of that character and store it in a variable. 43 | - Then we go through that index as long printing the same character and decrementing the index by 1. 44 | - If not we print the character. 45 | - Finally we print a new line. 46 | 47 | #### get_index funciton 48 | - We first declare two variables one to hold the index and we assign 'a' to the second. 49 | - We check if the character is upper chase. If so we convert (either that character to lowcase) or our variable to upper case. 50 | - Then as long as our letter isn't not equal to the input character. 51 | - We increment both out letter and the index. 52 | - Finally we return the index + 1 (because the first alphabet is index 1 not 0). 53 | --------------------------------------------------------------------------------