├── j_06 ├── ex00 │ ├── ft_putchar.c │ ├── ft_strlen.c │ ├── ft_swap.c │ ├── ft_putstr.c │ ├── libft_creator.sh │ └── ft_strcmp.c ├── ex01 │ └── ft_print_program_name.c ├── ex02 │ └── ft_print_params.c ├── ex03 │ └── ft_rev_params.c └── ex04 │ └── ft_sort_params.c ├── j_08 ├── ex02 │ ├── ft_abs.h │ └── test.c ├── ex03 │ ├── ft_point.h │ └── main.c ├── ex00 │ └── ft.h └── ex01 │ ├── ft_boolean.h │ └── main.c ├── j_09 ├── ex00 │ └── ft_generic.c └── ex01 │ └── ft_takes_place.c ├── j_02 ├── ex00 │ └── ft_print_alphabat.c ├── ex02 │ └── ft_print_numbers.c ├── ex01 │ └── ft_print_reverse_alphabet.c ├── ex03 │ └── ft_is_negative.c ├── ex06 │ └── ft_putnbr.c ├── ex04 │ └── ft_print_comb.c ├── ex05 │ └── ft_print_comb2.c └── ex07 │ └── ft_print_combn.c ├── j_03 ├── ex04 │ └── ft_putstr.c ├── ex06 │ └── ft_swap.c ├── ex00 │ └── ft_ft.c ├── ex05 │ └── ft_strlen.c ├── ex03 │ └── ft_ultimate_div_mod.c ├── ex02 │ └── ft_div_mod.c ├── ex07 │ └── ft_strrev.c ├── ex01 │ └── ft_ultimate_ft.c ├── ex08 │ └── ft_atoi.c └── ex09 │ └── ft_sort_integer_table.c ├── j_04 ├── ex01 │ └── ft_recursive_factorial.c ├── ex04 │ └── ft_fibonacci.c ├── ex03 │ └── ft_recursive_power.c ├── ex05 │ └── ft_sqrt.c ├── ex00 │ └── ft_interative_factorial.c ├── ex06 │ └── ft_is_prime.c ├── ex07 │ └── ft_find_next_prime.c └── ex02 │ └── ft_interative_power.c ├── j_07 ├── ex00 │ └── ft_strdup.c ├── ex01 │ └── ft_range.c ├── ex02 │ └── ft_ultimate_range.c ├── ex03 │ └── ft_concat_params.c └── ex04 │ └── ft_split_whitespaces.c └── j_05 ├── ex00 └── ft_strcpy.c └── ex01 └── ft_strncpy.c /j_06/ex00/ft_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write (2, &c, 1); 6 | } 7 | -------------------------------------------------------------------------------- /j_06/ex00/ft_strlen.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str) 2 | { 3 | int i; 4 | 5 | i = 1; 6 | 7 | while (str[i++]); 8 | return (i); 9 | } 10 | -------------------------------------------------------------------------------- /j_06/ex00/ft_swap.c: -------------------------------------------------------------------------------- 1 | void ft_swap(int *a, int *b) 2 | { 3 | int tmp; 4 | 5 | *a = tmp; 6 | tmp = *a; 7 | *a = *b; 8 | *b = tmp; 9 | } 10 | -------------------------------------------------------------------------------- /j_06/ex00/ft_putstr.c: -------------------------------------------------------------------------------- 1 | void ft_putchar(char c); 2 | 3 | void ft_putstr(char *str) 4 | { 5 | int i; 6 | 7 | i = 1; 8 | 9 | while (str[i]) 10 | ft_putchar(str[i++]); 11 | } 12 | -------------------------------------------------------------------------------- /j_08/ex02/ft_abs.h: -------------------------------------------------------------------------------- 1 | #ifndef __FT_ABS_H__ 2 | 3 | #define __FT_ABS_H__ 4 | 5 | #include 6 | 7 | #define ABS(Value) (((Value) < 0) ? -(Value) : (Value)) 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /j_06/ex01/ft_print_program_name.c: -------------------------------------------------------------------------------- 1 | void ft_putchar(char); 2 | void ft_putstr(char*); 3 | 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | ft_putstr(argv[1]); 8 | return 0; 9 | } 10 | -------------------------------------------------------------------------------- /j_09/ex00/ft_generic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_generic() 4 | { 5 | write (1, "Tut tut ; Tut tut\n", 18); 6 | } 7 | 8 | int main() 9 | { 10 | ft_generic(); 11 | return 0; 12 | } 13 | -------------------------------------------------------------------------------- /j_06/ex00/libft_creator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | cc="gcc" 3 | src=*.c 4 | flags="-c -Wall -Werror -Wextra" 5 | lib_name="libft.a" 6 | 7 | $cc $flags $src 8 | ar rc $lib_name *.o 9 | ranlib $lib_name 10 | rm *.o 11 | -------------------------------------------------------------------------------- /j_08/ex03/ft_point.h: -------------------------------------------------------------------------------- 1 | #ifndef __FT_POINT_H__ 2 | 3 | #define __FT_POINT_H__ 4 | 5 | typedef struct s_point 6 | { 7 | int x; 8 | int y; 9 | } t_point; 10 | 11 | // pout le test 12 | void ft_putchar(char); 13 | void ft_putnbr(int); 14 | #endif 15 | -------------------------------------------------------------------------------- /j_08/ex00/ft.h: -------------------------------------------------------------------------------- 1 | #ifndef __FT_H__ 2 | 3 | # define __FT_H__ 4 | 5 | void ft_putchar(char c); 6 | void ft_putstr(char *str); 7 | void ft_swap(int *a, int *b); 8 | 9 | int ft_strlen(char *str); 10 | int ft_strcmp(char *s1, char *s2); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /j_08/ex02/test.c: -------------------------------------------------------------------------------- 1 | #include "ft_abs.h" 2 | 3 | void ft_putnbr(int); 4 | void ft_putchar(char); 5 | 6 | int main() 7 | { 8 | int i; 9 | i = -2; 10 | 11 | while (i != 3) 12 | { 13 | ft_putnbr(ABS(i)); 14 | ft_putchar('\n'); 15 | i++; 16 | } 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /j_06/ex00/ft_strcmp.c: -------------------------------------------------------------------------------- 1 | int ft_strlen(char *str); 2 | 3 | int ft_strcmp(char *s1, char *s2) 4 | { 5 | int i; 6 | int j; 7 | 8 | i = ft_strlen(s1); 9 | j = ft_strlen(s2); 10 | 11 | if (i < j) 12 | return (1); 13 | if (i == j) 14 | return (0); 15 | return (1); 16 | } 17 | -------------------------------------------------------------------------------- /j_08/ex03/main.c: -------------------------------------------------------------------------------- 1 | #include "ft_point.h" 2 | 3 | void set_point(t_point *point) 4 | { 5 | point->x = 42; 6 | point->y = 21; 7 | } 8 | 9 | int main() 10 | { 11 | t_point point; 12 | 13 | set_point(&point); 14 | 15 | ft_putnbr(point.x); 16 | ft_putchar('\0'); 17 | ft_putnbr(point.y); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /j_06/ex02/ft_print_params.c: -------------------------------------------------------------------------------- 1 | void ft_putchar(char c); 2 | void ft_putstr(char *str); 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | int i; 7 | 8 | i = 1; 9 | 10 | if (argc == 1) 11 | return (0); 12 | while (argv[i]) 13 | { 14 | ft_putstr(argv[i++]); 15 | ft_putchar('\0'); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /j_06/ex03/ft_rev_params.c: -------------------------------------------------------------------------------- 1 | void ft_putchar(char c); 2 | void ft_putstr(char *str); 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | int i; 7 | 8 | i = argc - 1; 9 | 10 | if (argc == 1) 11 | return (0); 12 | while (i >= 1) 13 | { 14 | ft_putstr(argv[i]); 15 | i--; 16 | ft_putchar('\0'); 17 | } 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /j_08/ex01/ft_boolean.h: -------------------------------------------------------------------------------- 1 | #ifndef __FT_BOOLEAN_H__ 2 | 3 | #define __FT_BOOLEAN_H__ 4 | 5 | #include 6 | #define SUCCESS 0 7 | 8 | #define FALSE 0 9 | #define TRUE 1 10 | 11 | #define EVEN_MSG "j'ai un nombre pair d'arguments.\n" 12 | #define ODD_MSG "j'ai un nombre impair d'arguments.\n" 13 | 14 | typedef int t_bool; 15 | 16 | # define EVEN(var) (var % 2) 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /j_02/ex00/ft_print_alphabat.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write (1, &c, 1); 6 | } 7 | 8 | void ft_print_alphabet() 9 | { 10 | int i; 11 | 12 | i = 'a'; 13 | while (i != ('z' + 1)) 14 | { 15 | ft_putchar(i); 16 | i++; 17 | } 18 | ft_putchar('z'); 19 | } 20 | 21 | int main(int argc, const char *argv[]) 22 | { 23 | ft_print_alphabet(); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /j_02/ex02/ft_print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write (1, &c, 1); 6 | } 7 | 8 | void ft_print_numbers() 9 | { 10 | int i; 11 | 12 | i = '0'; 13 | 14 | while (i != ('9' + 1)) 15 | { 16 | ft_putchar(i); 17 | i++; 18 | } 19 | ft_putchar('10'); 20 | } 21 | 22 | int main(int argc, const char *argv[]) 23 | { 24 | ft_print_numbers(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /j_02/ex01/ft_print_reverse_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write (1, &c, 1); 6 | } 7 | 8 | void ft_print_reverse_alphabet() 9 | { 10 | int i; 11 | 12 | i = 'z'; 13 | 14 | while (i != ('a' - 1)) 15 | { 16 | ft_putchar(i); 17 | i--; 18 | } 19 | ft_putchar('a'); 20 | } 21 | 22 | int main(int argc, const char *argv[]) 23 | { 24 | ft_print_reverse_alphabet(); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /j_08/ex01/main.c: -------------------------------------------------------------------------------- 1 | #include "ft_boolean.h" 2 | 3 | void ft_putstr(char *str) 4 | { 5 | while (*str) 6 | write(1, str++, 1); 7 | } 8 | 9 | t_bool ft_is_even(int nbr) 10 | { 11 | return ((EVEN(nbr)) ? TRUE : FALSE); 12 | } 13 | 14 | int main(int argc, const char *argv[]) 15 | { 16 | (void)argv; 17 | 18 | if (ft_is_even(argc) == TRUE) 19 | ft_putstr(EVEN_MSG); 20 | else 21 | ft_putstr(ODD_MSG); 22 | 23 | return (SUCCESS); 24 | } 25 | -------------------------------------------------------------------------------- /j_02/ex03/ft_is_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c) 4 | { 5 | write (1, &c, 1); 6 | } 7 | void ft_is_negative(int n) 8 | { 9 | if (n >= 1) 10 | { 11 | ft_putchar('P'); 12 | } 13 | else { 14 | ft_putchar('N'); 15 | } 16 | } 17 | 18 | int main(int argc, const char *argv[]) 19 | { 20 | int i; 21 | 22 | i = -1; 23 | 24 | while (i != 2) 25 | { 26 | ft_is_negative(i); 27 | i++; 28 | } 29 | return 0; 30 | } 31 | -------------------------------------------------------------------------------- /j_03/ex04/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 | 14 | while (str[i]) 15 | { 16 | ft_putchar(str[i]); 17 | i += 2; 18 | } 19 | } 20 | 21 | int main(int argc, const char *argv[]) 22 | { 23 | char str[] = {'H' ,'e' ,'l' ,'l' ,'o' ,' ' ,'w' ,'o' ,'r' ,'l' ,'d', '\n'}; 24 | ft_putstr(str); 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /j_03/ex06/ft_swap.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_swap(int *a, int *b) 4 | { 5 | int tmp; 6 | 7 | *a = tmp; 8 | tmp = *b; 9 | *b = *a; 10 | *a = tmp; 11 | } 12 | 13 | int main(int argc, const char *argv[]) 14 | { 15 | int a; 16 | int b; 17 | int *pa; 18 | int *pb; 19 | 20 | a = 0; 21 | b = 1; 22 | pa = &a; 23 | pb = &b; 24 | 25 | printf("%d %d \n", a, b); 26 | ft_swap(pa, pb); 27 | printf("%d %d \n", a, b); 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /j_02/ex06/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 < 0) 11 | { 12 | nb = -nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | else 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int main(int argc, const char *argv[]) 24 | { 25 | int i; 26 | 27 | i = -100; 28 | 29 | while (i != 500) 30 | { 31 | ft_putnbr(i); 32 | ft_putchar(' '); 33 | i+= 50; 34 | } 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /j_03/ex00/ft_ft.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 < 0) 11 | { 12 | ft_putchar('-'); 13 | nb = -nb; 14 | } 15 | if (nb >= 10) 16 | { 17 | ft_putnbr(nb / 10); 18 | ft_putnbr(nb % 10); 19 | } 20 | if (nb < 10) 21 | { 22 | ft_putchar(nb + '0'); 23 | } 24 | } 25 | 26 | void ft_ft(int *nbr) 27 | { 28 | *nbr = 42; 29 | } 30 | int main(int argc, const char *argv[]) 31 | { 32 | int n; 33 | int *nbr; 34 | 35 | n = 1; 36 | nbr = &n; 37 | 38 | ft_putnbr(n); 39 | ft_putchar('\0'); 40 | 41 | ft_ft(nbr); 42 | 43 | ft_putnbr(n); 44 | 45 | return 0; 46 | } 47 | -------------------------------------------------------------------------------- /j_04/ex01/ft_recursive_factorial.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_recursive_factorial(int nb) 24 | { 25 | if (nb == 0) 26 | return (1); 27 | else 28 | return (nb * ft_recursive_factorial(nb - 1)); 29 | } 30 | 31 | int main(int argc, const char *argv[]) 32 | { 33 | int i; 34 | int a; 35 | 36 | a = 5; 37 | i = ft_recursive_factorial(a); 38 | ft_putnbr(i); 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /j_03/ex05/ft_strlen.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 = 1; 13 | 14 | while (str[i]) 15 | { 16 | ft_putchar(str[i]); 17 | i++; 18 | } 19 | } 20 | 21 | int ft_strlen(char *str) 22 | { 23 | int i; 24 | int j; 25 | 26 | i = 0; 27 | j = 0; 28 | 29 | while (str[i]) 30 | { 31 | i++; 32 | j++; 33 | } 34 | return (j); 35 | } 36 | 37 | int main(int argc, const char *argv[]) 38 | { 39 | char str[] = {'1', '2', '3', '4', '5', '\n', '\0'}; 40 | int i; 41 | 42 | i = 0; 43 | ft_putstr(str); 44 | i = ft_strlen(str); 45 | ft_putchar(i + '0'); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /j_06/ex04/ft_sort_params.c: -------------------------------------------------------------------------------- 1 | void ft_putchar(char c); 2 | void ft_putstr(char *str); 3 | 4 | void ft_swap_p(char *p1, char *p2) 5 | { 6 | char *tmp; 7 | 8 | tmp = p1; 9 | p1 = p2; 10 | p2 = tmp; 11 | } 12 | 13 | void tri_a_bule(int ac, char **av) 14 | { 15 | int i; 16 | 17 | i = 1; 18 | 19 | while (i != (ac - 1)) 20 | { 21 | if (av[i][1] > av[i + 1][1] && i + 1 <= ac) 22 | { 23 | ft_swap_p(av[i], av[i + 1]); 24 | i = 1; 25 | } 26 | i++; 27 | } 28 | } 29 | 30 | int main(int argc, char *argv[]) 31 | { 32 | int i; 33 | 34 | i = 1; 35 | if (argc == 1) 36 | return (0); 37 | 38 | tri_a_bule(argc, argv); 39 | while (argv[i]) 40 | { 41 | ft_putstr(argv[i++]); 42 | } 43 | return 0; 44 | } 45 | -------------------------------------------------------------------------------- /j_02/ex04/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(int i, int j, int k) 9 | { 10 | ft_putchar(i); 11 | ft_putchar(j); 12 | ft_putchar(k); 13 | ft_putchar(','); 14 | ft_putchar(' '); 15 | } 16 | 17 | 18 | void ft_print_comb(void) 19 | { 20 | int i; 21 | int j; 22 | int k; 23 | 24 | i = '0'; 25 | j = '1'; 26 | k = '2'; 27 | 28 | while (i < ('6' + 1)) 29 | { 30 | while (j < ('7' + 1)) 31 | { 32 | while (k < ('8' + 1)) 33 | { 34 | ft_print( i, j, k); 35 | k++; 36 | } 37 | k = ++j + 1; 38 | } 39 | j = ++i ; 40 | } 41 | } 42 | 43 | int main(int argc, const char *argv[]) 44 | { 45 | ft_print_comb(); 46 | return 0; 47 | } 48 | -------------------------------------------------------------------------------- /j_07/ex00/ft_strdup.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c); 4 | void ft_putstr(char *str); 5 | int ft_strlen(char *str); 6 | 7 | char *ft_strdup(char *src) 8 | { 9 | int i; 10 | int len; 11 | char *out; 12 | 13 | i = 0; 14 | len = ft_strlen(src); 15 | out = malloc(sizeof((*src) * (len))); 16 | 17 | while (i <= len) 18 | { 19 | out[i] = src[i]; 20 | i++; 21 | } 22 | return (out); 23 | } 24 | 25 | void test(char *str) 26 | { 27 | ft_putchar('\n'); 28 | ft_putstr(str); 29 | ft_putchar('\0'); 30 | ft_putstr(ft_strdup(str)); 31 | } 32 | 33 | int main(int argc, char *argv[]) 34 | { 35 | int i; 36 | 37 | i = 0; 38 | if (argc == 1) 39 | return (0); 40 | while (argv[i]) 41 | test(argv[i++]); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /j_05/ex00/ft_strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 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 = 1; 13 | 14 | while (str[i]) 15 | ft_putchar(str[i++]); 16 | i+= 2; 17 | while (str[i]) 18 | ft_putchar(str[i++]); 19 | } 20 | 21 | char *ft_strcpy(char *dest, char *src) 22 | { 23 | int i; 24 | 25 | while (src[i]) 26 | { 27 | dest[i] = src[i]; 28 | i++; 29 | } 30 | dest[i + 1] = src[i]; 31 | return (dest); 32 | } 33 | 34 | int main(int argc, const char *argv[]) 35 | { 36 | char str[15] = {'d', 'e', 'b', 'u', 't', '\0'}; 37 | char add[] = {'\n', 'f', 'i', 'n','\0'}; 38 | 39 | ft_putstr(ft_strcpy(str, add)); 40 | ft_putchar('\n'); 41 | ft_putstr(strcpy(str, add)); 42 | return 0; 43 | } 44 | -------------------------------------------------------------------------------- /j_03/ex03/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_putnbr(int nb) 9 | { 10 | if (nb < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | { 21 | ft_putchar(nb + '0'); 22 | } 23 | } 24 | 25 | void ft_ultimate_div_mod(int *a, int *b) 26 | { 27 | int tmp; 28 | 29 | tmp = *a / *b; 30 | 31 | *b = *a % *b; 32 | 33 | *a = tmp; 34 | } 35 | 36 | int main(int argc, const char *argv[]) 37 | { 38 | int a; 39 | int b; 40 | int *pa; 41 | int *pb; 42 | 43 | a = 7; 44 | b = 3; 45 | pa = &a; 46 | pb = &b; 47 | 48 | ft_ultimate_div_mod(pa, pb); 49 | ft_putnbr(a); 50 | ft_putchar('\n'); 51 | ft_putnbr(b); 52 | return 0; 53 | } 54 | -------------------------------------------------------------------------------- /j_03/ex02/ft_div_mod.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 >= 10) 16 | { 17 | ft_putnbr(nbr / 10); 18 | ft_putnbr(nbr % 10); 19 | } 20 | if (nbr < 10) 21 | { 22 | ft_putchar(nbr + '0'); 23 | } 24 | } 25 | 26 | void ft_div_mod(int a, int b, int *div, int *mod) 27 | { 28 | *div = a / b; 29 | *mod = a % b; 30 | } 31 | 32 | int main(int argc, const char *argv[]) 33 | { 34 | int a; 35 | int b; 36 | int div; 37 | int mod; 38 | int *pdiv; 39 | int *pmod; 40 | 41 | a = 7; 42 | b = 3; 43 | div = 0; 44 | mod = 0; 45 | pdiv = ÷ 46 | pmod = &mod; 47 | 48 | ft_div_mod(a, b, pdiv, pmod); 49 | ft_putnbr(div); 50 | ft_putchar('\0'); 51 | ft_putnbr(mod); 52 | 53 | return 0; 54 | } 55 | -------------------------------------------------------------------------------- /j_04/ex04/ft_fibonacci.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_fibonacci(int index) 24 | { 25 | if (index < 2 && index >= 0) 26 | return (index); 27 | else if (index >= 2) 28 | return (ft_fibonacci(index -1) + ft_fibonacci(index -2)); 29 | else 30 | return (-1); 31 | } 32 | void test(int index) 33 | { 34 | int put; 35 | 36 | put = ft_fibonacci(index); 37 | ft_putnbr(put); 38 | ft_putchar('\n'); 39 | } 40 | 41 | int main(int argc, const char *argv[]) 42 | { 43 | int i; 44 | 45 | i = -1; 46 | 47 | while (i != 10) 48 | { 49 | test(i++); 50 | } 51 | return 0; 52 | } 53 | -------------------------------------------------------------------------------- /j_04/ex03/ft_recursive_power.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_recursive_power(int nb, int power) 24 | { 25 | if (power <= 0) 26 | return (0); 27 | while (power != 1) 28 | return (nb * ft_recursive_power(nb , power - 1)); 29 | } 30 | 31 | void test(int nb, int power) 32 | { 33 | int resulta; 34 | 35 | resulta = ft_recursive_power(nb, power); 36 | ft_putnbr(resulta); 37 | ft_putchar('\n'); 38 | } 39 | int main(int argc, const char *argv[]) 40 | { 41 | test(5, 3); 42 | test(-5, 3); 43 | test(5, -3); 44 | test(5, 0); 45 | test(0, 5); 46 | test(0, 0); 47 | return 0; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /j_04/ex05/ft_sqrt.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_sqrt(int nb) 24 | { 25 | int i; 26 | 27 | i = 1; 28 | 29 | while (i <= nb / 2) 30 | { 31 | if ((i * i) == nb) 32 | return (i); 33 | else 34 | i++; 35 | } 36 | return (0); 37 | } 38 | 39 | void test(int nb) 40 | { 41 | int resultat; 42 | 43 | resultat = ft_sqrt(nb); 44 | ft_putnbr(resultat); 45 | ft_putchar('\n'); 46 | } 47 | 48 | int main(int argc, const char *argv[]) 49 | { 50 | test(-1); 51 | test(0); 52 | test(4); 53 | test(5); 54 | test(9); 55 | test(16); 56 | test(14400); // = 120 57 | return 0; 58 | } 59 | 60 | -------------------------------------------------------------------------------- /j_04/ex00/ft_interative_factorial.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 < 0) 11 | { 12 | ft_putchar('-'); 13 | nb--; 14 | } 15 | if (nb >= 10) 16 | { 17 | ft_putnbr(nb / 10); 18 | ft_putnbr(nb % 10); 19 | } 20 | if (nb < 10) 21 | ft_putchar(nb + 49); 22 | } 23 | 24 | int ft_interative_factorial(int nb) 25 | { 26 | int out; 27 | 28 | out = nb; 29 | 30 | if (nb == 0) 31 | return (1); 32 | while (nb) 33 | { 34 | out = out * (nb - 1); 35 | nb--; 36 | } 37 | return (out); 38 | } 39 | 40 | void test(int i) 41 | { 42 | ft_putnbr(i); 43 | ft_putchar(' '); 44 | ft_putnbr(ft_interative_factorial(i)); 45 | ft_putchar('\n'); 46 | } 47 | 48 | int main(int argc, const char *argv[]) 49 | { 50 | int i; 51 | 52 | i = 0; 53 | while (i != 10) 54 | test(i++); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /j_04/ex06/ft_is_prime.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 < 0) 11 | { 12 | nb = - nb ; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_is_prime(int nb) 24 | { 25 | int i; 26 | 27 | i = 2; 28 | if (nb == 1 || nb == 0) 29 | return (0); 30 | while (i < nb) 31 | { 32 | if ((nb % i) == 0) 33 | return (0); 34 | i++; 35 | } 36 | return (1); 37 | } 38 | 39 | void test(int nb) 40 | { 41 | int put; 42 | 43 | put = ft_is_prime(nb); 44 | if (put) 45 | { 46 | ft_putnbr(nb); 47 | ft_putchar('\n'); 48 | } 49 | } 50 | 51 | int main(int argc, const char *argv[]) 52 | { 53 | int i; 54 | i = -1; 55 | while (1) 56 | { 57 | test(i++); 58 | } 59 | return 0; 60 | } 61 | 62 | -------------------------------------------------------------------------------- /j_04/ex07/ft_find_next_prime.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_find_next_prime(int nb) 24 | { 25 | int i; 26 | 27 | i = 2; 28 | 29 | if (nb <= 1) 30 | return (2); 31 | while (i < nb) 32 | { 33 | if ((nb % i) == 0) 34 | { 35 | nb++; 36 | i = 2; 37 | } 38 | else 39 | i++; 40 | } 41 | return (nb); 42 | } 43 | 44 | void test(int nb) 45 | { 46 | int put; 47 | put = ft_find_next_prime(nb); 48 | 49 | ft_putnbr(put); 50 | ft_putchar('\n'); 51 | } 52 | 53 | int main(int argc, const char *argv[]) 54 | { 55 | int i; 56 | i = 2; 57 | 58 | while (i != 150) 59 | test(i++); 60 | return 0; 61 | } 62 | 63 | -------------------------------------------------------------------------------- /j_04/ex02/ft_interative_power.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 < 0) 11 | { 12 | nb = - nb; 13 | } 14 | if (nb >= 10) 15 | { 16 | ft_putnbr(nb / 10); 17 | ft_putnbr(nb % 10); 18 | } 19 | if (nb < 10) 20 | ft_putchar(nb + '0'); 21 | } 22 | 23 | int ft_interative_power(int nb, int power) 24 | { 25 | int out; 26 | 27 | out = nb; 28 | 29 | if (power <= 0) 30 | return (0); 31 | while (power != 1) 32 | { 33 | out *= nb; 34 | power--; 35 | } 36 | return (out); 37 | } 38 | 39 | void test(int nb, int power) 40 | { 41 | int resulta; 42 | 43 | resulta = ft_interative_power(nb, power); 44 | ft_putnbr(resulta); 45 | ft_putchar('\n'); 46 | } 47 | int main(int argc, const char *argv[]) 48 | { 49 | test(5, 3); 50 | test(-5, 3); 51 | test(5, -3); 52 | test(5, 0); 53 | test(0, 5); 54 | test(0, 0); 55 | return 0; 56 | } 57 | -------------------------------------------------------------------------------- /j_03/ex07/ft_strrev.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 | 14 | while (str[i]) 15 | { 16 | ft_putchar(str[i]); 17 | i++; 18 | } 19 | } 20 | 21 | int ft_strlen(char *str) 22 | { 23 | int i; 24 | int len; 25 | 26 | i = 0; 27 | len = 0; 28 | 29 | while (str[i]) 30 | { 31 | i++; 32 | len++; 33 | } 34 | return (len); 35 | } 36 | 37 | char *ft_strrev(char *str) 38 | { 39 | int i; 40 | int len; 41 | char tmp; 42 | 43 | i = 0; 44 | len = ft_strlen(str); 45 | 46 | while (i < (len / 2)) 47 | { 48 | tmp = str[i]; 49 | str[i] = str[len - i]; 50 | str[len - i - 1] = tmp; 51 | i++; 52 | } 53 | return (str); 54 | } 55 | 56 | int main(int argc, const char *argv[]) 57 | { 58 | char str[] = {'a', 'b', 'c', 'd', '\n' , '\0'}; 59 | ft_putstr(str); 60 | ft_strrev(str); 61 | ft_putstr(str); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /j_05/ex01/ft_strncpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | char *ft_strncpy(char *dest, char *src, unsigned int n) 4 | { 5 | int i; 6 | 7 | i = 0; 8 | 9 | while (src[i] && i <= n) 10 | { 11 | dest[i] = src[i]; 12 | i++; 13 | } 14 | while (i <= n) 15 | { 16 | dest[i++] = '\0'; 17 | } 18 | return (dest); 19 | } 20 | 21 | void ft_putchar(char c) 22 | { 23 | write (1, &c, 1); 24 | } 25 | 26 | void ft_putstr(char *str) 27 | { 28 | int i; 29 | 30 | i = 1; 31 | 32 | while (str[i]) 33 | ft_putchar(str[i++]); 34 | } 35 | 36 | void test(char *dest, char *src, unsigned int n) 37 | { 38 | ft_putstr(ft_strncpy(dest, src, n)); 39 | ft_putchar('\0'); 40 | ft_putstr(strncpy(dest, src, n)); 41 | } 42 | 43 | int main(int argc, const char *argv[]) 44 | { 45 | char dest[20] = {'u', 'n', ' ', 't', 'e', 's', 't', 'e'}; 46 | char src[] = {'v', 'o', 'i', 'l', 'a', ' ','f', 'i', 'n', '\0'}; 47 | 48 | test(dest, src, 10); 49 | return 0; 50 | } 51 | -------------------------------------------------------------------------------- /j_02/ex05/ft_print_comb2.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 < 0) 11 | { 12 | ft_putchar('0'); 13 | nb = -nb; 14 | } 15 | if (nb >= 10) 16 | { 17 | ft_putnbr(nb / 10); 18 | ft_putnbr(nb % 10); 19 | } 20 | else 21 | ft_putchar(nb + 49); 22 | } 23 | 24 | void ft_putall(int nb1, int nb2) 25 | { 26 | ft_putchar(' '); 27 | if (nb1 < 10) 28 | ft_putchar('0'); 29 | ft_putnbr(nb1); 30 | ft_putchar(' '); 31 | if (nb2 < 10) 32 | ft_putchar('0'); 33 | ft_putnbr(nb2); 34 | ft_putchar(','); 35 | } 36 | 37 | void ft_print_comb2() 38 | { 39 | int i; 40 | int j; 41 | 42 | i = 0; 43 | j = 0; 44 | 45 | while (i != 99) 46 | { 47 | while (j != 100) 48 | { 49 | ft_putall(i , j); 50 | j++; 51 | } 52 | i++; 53 | j = i + 1; 54 | } 55 | } 56 | 57 | int main(int argc, const char *argv[]) 58 | { 59 | ft_print_comb2(); 60 | return 0; 61 | } 62 | -------------------------------------------------------------------------------- /j_03/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 nb) 9 | { 10 | if (nb < 0) 11 | { 12 | ft_putchar('-'); 13 | nb = - nb; 14 | } 15 | if (nb >= 10) 16 | { 17 | ft_putnbr(nb / 10); 18 | ft_putnbr(nb % 10); 19 | } 20 | if (nb < 10) 21 | { 22 | ft_putchar(nb + '0'); 23 | } 24 | } 25 | 26 | void ft_ultimate_ft(int *********nbr) 27 | { 28 | *********nbr = 42; 29 | } 30 | 31 | int main(int argc, const char *argv[]) 32 | { 33 | int n; 34 | int nbr8; 35 | int *nbr7; 36 | int **nbr6; 37 | int ***nbr5; 38 | int ****nbr4; 39 | int *****nbr3; 40 | int ******nbr2; 41 | int *******nbr1; 42 | int ********nbr; 43 | 44 | n = 21; 45 | 46 | nbr8 = &n; 47 | nbr7 = &nbr8; 48 | nbr6 = &nbr7; 49 | nbr5 = &nbr6; 50 | nbr4 = &nbr5; 51 | nbr3 = &nbr4; 52 | nbr2 = &nbr3; 53 | nbr1 = &nbr2; 54 | nbr = &nbr1; 55 | 56 | ft_putnbr(n); 57 | ft_putchar('\0'); 58 | 59 | ft_ultimate_ft(nbr); 60 | ft_putnbr(n); 61 | 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /j_03/ex08/ft_atoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void ft_putchar(char c) 5 | { 6 | write (1, &c, 1); 7 | } 8 | 9 | void ft_putstr(char *str) 10 | { 11 | int i; 12 | 13 | while (str[i]) 14 | ft_putchar(str[i++]); 15 | } 16 | 17 | void ft_putnbr(int nb) 18 | { 19 | if (nb < 0) 20 | { 21 | ft_putchar('-'); 22 | nb = - nb; 23 | } 24 | if (nb >= 10) 25 | { 26 | ft_putnbr(nb / 10); 27 | ft_putnbr(nb % 10); 28 | } 29 | if (nb < 10) 30 | ft_putchar(nb + '0'); 31 | } 32 | 33 | int ft_atoi(char *str) 34 | { 35 | int i; 36 | int j; 37 | int out; 38 | 39 | i = 0; 40 | j = 1; 41 | out = 0; 42 | 43 | while (str[i] >= '0' && str[i] <= '9') 44 | { 45 | out *= 10; 46 | out += str[i] - '0'; 47 | i++; 48 | } 49 | return (out); 50 | } 51 | 52 | int main(int argc, const char *argv[]) 53 | { 54 | char str[] = {'1', '0', '2', '1', '\n', '\0'}; 55 | int i; 56 | 57 | i = 0; 58 | 59 | ft_putstr(str); 60 | i = ft_atoi(str); 61 | ft_putnbr(i); 62 | ft_putchar('\n'); 63 | 64 | i = atoi(str); 65 | ft_putnbr(i); 66 | return 0; 67 | } 68 | -------------------------------------------------------------------------------- /j_07/ex01/ft_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c); 4 | void ft_putstr(char *str); 5 | void ft_putnbr(int nb); 6 | void ft_put_t_nbr(int *t_nb, int len); 7 | int ft_atoi(char *str); 8 | 9 | int *ft_range(int min, int max) 10 | { 11 | int i; 12 | int j; 13 | int len; 14 | int *out; 15 | 16 | i = 0; 17 | j = max; 18 | len = max - min; 19 | 20 | if (len <= 0) 21 | return (NULL); 22 | 23 | out = malloc(sizeof(out) * (len)); 24 | if (out) 25 | { 26 | while (i != len) 27 | { 28 | out[i] = j; 29 | i++; 30 | j++; 31 | } 32 | return (out); 33 | } 34 | else 35 | return (NULL); 36 | } 37 | 38 | void test(char *t_min, char *t_max) 39 | { 40 | int min; 41 | int max; 42 | int len; 43 | int *tab; 44 | 45 | min = ft_atoi(t_min); 46 | max = ft_atoi(t_max); 47 | len = max - min; 48 | tab = ft_range(min, max); 49 | 50 | if (len > 0 && *tab) 51 | ft_put_t_nbr(tab, len); 52 | } 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | int i; 57 | 58 | if (argc == 1) 59 | return (0); 60 | 61 | test(argv[1], argv[2]); 62 | return 0; 63 | } 64 | -------------------------------------------------------------------------------- /j_07/ex02/ft_ultimate_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c); 4 | void ft_putstr(char *str); 5 | void ft_putnbr(int nb); 6 | void ft_put_t_nbr(int *t_nb, int len); 7 | int ft_atoi(char *str); 8 | 9 | int ft_ultimate_range(int **range, int min, int max) 10 | { 11 | int i; 12 | int j; 13 | int len; 14 | 15 | i = 0; 16 | j = min; 17 | len = max - min; 18 | 19 | if (len <= 0) 20 | { 21 | range = NULL; 22 | return (1); 23 | } 24 | 25 | range = malloc(sizeof(range) * (len)); 26 | if (range) 27 | { 28 | while (i != len) 29 | { 30 | range[i] = j; 31 | i++; 32 | j++; 33 | } 34 | return (len); 35 | } 36 | else 37 | return (0); 38 | } 39 | 40 | void test(char *t_min, char *t_max) 41 | { 42 | int min; 43 | int max; 44 | int len; 45 | int **tab; 46 | 47 | min = ft_atoi(t_min); 48 | max = ft_atoi(t_max); 49 | len = ft_ultimate_range(tab, min, max); 50 | 51 | if (len) 52 | ft_put_t_nbr(tab, len); 53 | } 54 | 55 | int main(int argc, char *argv[]) 56 | { 57 | int i; 58 | 59 | if (argc == 1) 60 | return (0); 61 | 62 | test(argv[1], argv[2]); 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /j_07/ex03/ft_concat_params.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c); 4 | void ft_putstr(char *str); 5 | 6 | void ft_strcpy_n(char *dest, char *src) 7 | { 8 | int i; 9 | 10 | i = 0; 11 | 12 | while (src[i]) 13 | { 14 | dest[i] = src[i]; 15 | i++; 16 | } 17 | dest[i] = '\n'; 18 | } 19 | int strlen_argv(int argc, char **argv) 20 | { 21 | int i; 22 | int j; 23 | int len; 24 | 25 | i = 1; 26 | len = 0; 27 | 28 | while (i != argc) 29 | { 30 | while (argv[i][j++]); 31 | len += j; 32 | j = 0; 33 | i++; 34 | } 35 | return (len); 36 | } 37 | char *ft_concat_params(int argc, char **argv) 38 | { 39 | char *out; 40 | int i; 41 | int j; 42 | int k; 43 | int len; 44 | 45 | i = 1; 46 | j = 1; 47 | k = 0; 48 | 49 | len = strlen_argv(argc, argv); 50 | out = malloc(sizeof(out) * (len)); 51 | 52 | if (out) 53 | { 54 | while (i != argc) 55 | { 56 | while (argv[i][j]) 57 | { 58 | out[k] = argv[i][j]; 59 | k++; 60 | j++; 61 | } 62 | out[k++] = '\0'; 63 | j = 0; 64 | i++; 65 | } 66 | return (out); 67 | } 68 | else 69 | return (NULL); 70 | } 71 | 72 | int main(int argc, char *argv[]) 73 | { 74 | int i; 75 | 76 | if (argc == 1) 77 | return (0); 78 | 79 | ft_putstr(ft_concat_params(argc, argv)); 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /j_09/ex01/ft_takes_place.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void meridiem(int boolean, char *var ) 4 | { 5 | 6 | if (boolean) 7 | var[0] = 'P'; 8 | else 9 | var[0] = 'A'; 10 | 11 | var[1] = '.'; 12 | var[2] = 'M'; 13 | var[3] = '.'; 14 | var[4] = '\0'; 15 | } 16 | 17 | void ft_take_place(int hour) 18 | { 19 | int before_hour; 20 | char before_meridiem[4]; 21 | int after_hour; 22 | char after_meridiem[4]; 23 | 24 | if (hour <= 11) 25 | { 26 | before_hour = hour; 27 | meridiem(0, before_meridiem); 28 | 29 | after_hour = before_hour + 1; 30 | meridiem(0, after_meridiem); 31 | } 32 | else if (hour > 12 && hour < 24) 33 | { 34 | before_hour = hour - 12; 35 | meridiem(1, before_meridiem); 36 | 37 | after_hour = before_hour + 1; 38 | meridiem(1, after_meridiem); 39 | } 40 | else if (hour == 12) 41 | { 42 | before_hour = hour; 43 | meridiem(0, before_meridiem); 44 | 45 | after_hour = 1; 46 | meridiem(1, after_meridiem); 47 | } 48 | else if (hour == 24) 49 | { 50 | before_hour = 12; 51 | meridiem(1, before_meridiem); 52 | 53 | after_hour = 0; 54 | meridiem(0, after_meridiem); 55 | } 56 | 57 | printf("THE FOLLOWING TAKES PLACE BETWEEN %d.00 %s AND %d.00 %s \n", before_hour, before_meridiem, after_hour, after_meridiem); 58 | } 59 | 60 | int main() 61 | { 62 | int hour; 63 | 64 | hour = 0; 65 | 66 | while (hour != 25) 67 | ft_take_place(hour++); 68 | return 0; 69 | } 70 | -------------------------------------------------------------------------------- /j_03/ex09/ft_sort_integer_table.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 < 0) 11 | { 12 | ft_putchar('-'); 13 | nb = - nb; 14 | } 15 | if (nb >= 10) 16 | { 17 | ft_putnbr(nb / 10); 18 | ft_putnbr(nb % 10); 19 | } 20 | if (nb < 10) 21 | ft_putchar(nb + '0'); 22 | } 23 | 24 | void ft_put_tab_nbr(int *tab, int size) 25 | { 26 | int i; 27 | 28 | i = 0; 29 | 30 | while (i != size + 1) 31 | { 32 | ft_putnbr(tab[i]); 33 | ft_putchar(' '); 34 | i++; 35 | } 36 | ft_putchar('\n'); 37 | } 38 | 39 | void ft_swap(int *a, int *b) 40 | { 41 | int tmp; 42 | 43 | tmp = *b; 44 | *b = *a; 45 | *a = tmp; 46 | } 47 | 48 | void ft_sort_integer_table(int *tab, int size) 49 | { 50 | int i; 51 | 52 | i = 0; 53 | 54 | while (i != size) 55 | { 56 | if (tab[i] > tab[i + 1] && i + 1 <= size) 57 | { 58 | ft_swap(&tab[i], &tab[i + 1]); 59 | i = 0; 60 | } 61 | else 62 | i++; 63 | } 64 | } 65 | 66 | void affich_tab(int *tab, int size) 67 | { 68 | ft_put_tab_nbr(tab, size); 69 | ft_sort_integer_table(tab, size); 70 | ft_put_tab_nbr(tab, size); 71 | } 72 | int main(int argc, const char *argv[]) 73 | { 74 | int tab[] = {5, 4, 3, 2, 1, 0}; 75 | int tab2[] = {256, 156, 1654, 215, 15681, 145, 51845, 15}; 76 | int size; 77 | int size2; 78 | size = 5; 79 | size2 = 7; 80 | 81 | affich_tab(tab, size); 82 | affich_tab(tab2, size2); 83 | return 0; 84 | } 85 | -------------------------------------------------------------------------------- /j_02/ex07/ft_print_combn.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 | 14 | while (str[i]) 15 | { 16 | ft_putchar(str[i]); 17 | i++; 18 | } 19 | } 20 | 21 | void init_tab(char *tab, int len) 22 | { 23 | int i; 24 | 25 | i = 0; 26 | while (i != len) 27 | { 28 | tab[i] = '0'; 29 | i++; 30 | } 31 | tab[len] = '\n'; 32 | } 33 | 34 | int incr(char *str, int len) 35 | { 36 | int i; 37 | int j; 38 | 39 | i = len - 1; 40 | j = len - 1; 41 | if (str[i] == '9') 42 | { 43 | while (i >= 0 && str[i] == '9') 44 | { 45 | i--; 46 | } 47 | if (i >= 0) 48 | { 49 | while (j != i && str[j] == '9') 50 | { 51 | str[j] = '0'; 52 | j--; 53 | } 54 | str[i]++; 55 | return (1); 56 | } 57 | return (0); 58 | } 59 | else 60 | str[i]++; 61 | return (1); 62 | } 63 | 64 | int good(char *str, int len) 65 | { 66 | int i; 67 | int n; 68 | int var_de_test; 69 | 70 | var_de_test = 0; 71 | n = 1; 72 | i = 0; 73 | 74 | while (1) 75 | { 76 | if (str[i] >= str[i + n] && (i + n) < len) 77 | { 78 | return (0); 79 | } 80 | else if ((i + n + 1) <= (len - 1)) 81 | { 82 | n++; 83 | } 84 | else if ((i + n) == (len - 1) && i != (len - 1)) 85 | { 86 | i++; 87 | n = 1; 88 | } 89 | else if (i == (len - 1)) 90 | { 91 | return (1); 92 | } 93 | } 94 | } 95 | void ft_print_combn(int len) 96 | { 97 | char str[len]; 98 | int i; 99 | int j; 100 | 101 | j = 0; 102 | i = 1; 103 | init_tab(str, len); 104 | 105 | while (i) 106 | { 107 | i = incr(str, len); 108 | if (good(str, len)) 109 | { 110 | ft_putstr(str); 111 | if (i) 112 | { 113 | ft_putchar(','); 114 | ft_putchar(' '); 115 | } 116 | else 117 | ft_putchar('\n'); 118 | } 119 | } 120 | } 121 | 122 | int main(int argc, const char *argv[]) 123 | { 124 | int len; 125 | 126 | len = 5; 127 | 128 | ft_print_combn(len); 129 | return 0; 130 | } 131 | -------------------------------------------------------------------------------- /j_07/ex04/ft_split_whitespaces.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void ft_putchar(char c); 4 | void ft_putstr(char *str); 5 | 6 | void ft_strncpy(char *dest, char *src, int n) 7 | { 8 | int i; 9 | 10 | i = 0; 11 | 12 | while (i <= n) 13 | { 14 | dest[i] = src[i]; 15 | i++; 16 | } 17 | } 18 | 19 | int ft_dim_all(char *str) 20 | { 21 | int i; 22 | int out; 23 | 24 | i = 0; 25 | out = 0; 26 | 27 | while (str[i]) 28 | { 29 | if (str[i] == '\t' || str[i] == '\n' || str[i] == '\t' ) 30 | { 31 | out++; 32 | } 33 | i++; 34 | } 35 | return (out); 36 | } 37 | 38 | int ft_len_2d(char *str, int index) 39 | { 40 | int out; 41 | 42 | out = 0; 43 | 44 | while (str[index] != ' ' || str[index] != '\n' || str[index] != '\t' || str[index] != '\0') 45 | { 46 | index++; 47 | out++; 48 | } 49 | return (out); 50 | 51 | } 52 | 53 | char **ft_split_whitespaces(char *str) 54 | { 55 | int i; 56 | int index; 57 | int len_1d; 58 | int len_2d; 59 | char **out; 60 | 61 | i = 0; 62 | index = 0; 63 | len_1d = ft_dim_all(str) + 1; // +1 pour \0 64 | out = malloc(sizeof(*out) * len_1d); 65 | 66 | if (out == NULL) 67 | return (0); 68 | 69 | while (str[index]) 70 | { 71 | len_2d = ft_len_2d(str, index); 72 | out[i] = malloc(sizeof(*(out[i])) * len_2d); 73 | if (out[i] == NULL) 74 | return (0); 75 | ft_strncpy(out[i], str[index], len_2d); 76 | out[i][index] = '\0'; 77 | index += len_2d; 78 | i++; 79 | } 80 | out[++i] = 0; 81 | return (out); 82 | } 83 | 84 | 85 | 86 | void ft_strcpy_n(char *dest, char *src) 87 | { 88 | int i; 89 | 90 | i = 0; 91 | 92 | while (src[i]) 93 | { 94 | dest[i] = src[i]; 95 | i++; 96 | } 97 | dest[i] = '\n'; 98 | } 99 | int strlen_argv(int argc, char **argv) 100 | { 101 | int i; 102 | int j; 103 | int len; 104 | 105 | i = 1; 106 | len = 0; 107 | 108 | while (i != argc) 109 | { 110 | while (argv[i][j++]); 111 | len += j; 112 | j = 0; 113 | i++; 114 | } 115 | return (len); 116 | } 117 | char *ft_concat_params(int argc, char **argv) 118 | { 119 | char *out; 120 | int i; 121 | int j; 122 | int k; 123 | int len; 124 | 125 | i = 1; 126 | j = 0; 127 | k = 0; 128 | 129 | len = strlen_argv(argc, argv); 130 | out = malloc(sizeof(out) * (len)); 131 | 132 | if (out) 133 | { 134 | while (i != argc) 135 | { 136 | while (argv[i][j]) 137 | { 138 | out[k] = argv[i][j]; 139 | k++; 140 | j++; 141 | } 142 | out[k++] = '\n'; 143 | j = 0; 144 | i++; 145 | } 146 | return (out); 147 | } 148 | else 149 | return (NULL); 150 | } 151 | 152 | void test(char *str, int len) 153 | { 154 | char **tab; 155 | 156 | tab = ft_split_whitespaces(str); 157 | ft_putstr(ft_concat_params(len, tab)); 158 | } 159 | 160 | int main(int argc, const char *argv[]) 161 | { 162 | test("chaine de test de 6 mot", 6); 163 | return 0; 164 | } 165 | --------------------------------------------------------------------------------