From e078efd32522539ead3af36d2ea676874e013447 Mon Sep 17 00:00:00 2001 From: Gregory Date: Sun, 20 Nov 2016 02:20:23 +0200 Subject: [PATCH] init commit --- brainfuck/Makefile | 32 +++++ brainfuck/README | 11 ++ brainfuck/hello_world.bf | 1 + brainfuck/inc/brnfck.h | 17 +++ brainfuck/src/brainfuck.c | 52 ++++++++ brainfuck/src/main.c | 23 ++++ brainfuck/src/output.c | 19 +++ d00/ex01/testDay00.tar | Bin 0 -> 2048 bytes d00/ex02/exo2.tar | Bin 0 -> 6144 bytes d00/ex03/klist.txt | 5 + d00/ex04/who_am_i.sh | 1 + d00/ex05/people.sh | 1 + d00/ex06/mobile-phone.ldif | 4 + d00/ex07/midLS | 1 + d00/ex08/z | 1 + d00/ex09/b | 11 ++ d00/ex10/clean | 1 + d00/ex11/ft_magic | 1 + d01/ex01/print_groups.sh | 1 + d01/ex02/find_sh.sh | 1 + d01/ex03/count_files.sh | 1 + d01/ex04/MAC.sh | 1 + "d01/ex05/\"?$*KwaMe*$?\\\"" | 0 "d01/ex05/\"\\?$*'KwaMe'*$?\\\"" | 1 + d01/ex06/skip.sh | 1 + d01/ex07/r_dwssap.sh | 1 + d01/ex08/bon.sh | 1 + d01/ex09/add_chelou.sh | 0 d02/ex00/ft_print_alphabet.c | 25 ++++ d02/ex01/ft_print_reverse_alphabet.c | 25 ++++ d02/ex02/ft_print_numbers.c | 25 ++++ d02/ex03/ft_is_negative.c | 25 ++++ d02/ex04/ft_print_comb.c | 49 +++++++ d02/ex06/ft_putnbr.c | 38 ++++++ d03/ex00/ft_ft.c | 16 +++ d03/ex01/ft_ultimate_ft.c | 16 +++ d03/ex02/ft_swap.c | 20 +++ d03/ex03/ft_div_mod | Bin 0 -> 8520 bytes d03/ex03/ft_div_mod.c | 17 +++ d03/ex04/ft_ultimate_div_mod.c | 20 +++ d03/ex05/ft_putstr.c | 22 ++++ d03/ex06/ft_strlen.c | 24 ++++ d03/ex07/ft_strrev.c | 37 ++++++ d03/ex08/ft_atoi.c | 24 ++++ d03/ex09/ft_sort_integer_table.c | 40 ++++++ d04/ex00/ft_iterative_factorial.c | 31 +++++ d04/ex01/ft_recursive_factorial.c | 24 ++++ d04/ex02/ft_iterative_power.c | 32 +++++ d04/ex03/ft_recursive_power.c | 25 ++++ d04/ex04/ft_fibonacci.c | 23 ++++ d04/ex05/ft_sqrt.c | 24 ++++ d04/ex06/ft_is_prime.c | 32 +++++ d05/ex00/ft_putstr.c | 22 ++++ d05/ex01/ft_putnbr.c | 58 +++++++++ d05/ex02/ft_atoi.c | 36 ++++++ d05/ex03/ft_strcpy.c | 26 ++++ d05/ex04/ft_strncpy.c | 29 +++++ d05/ex05/ft_strstr.c | 33 +++++ d05/ex06/ft_strcmp.c | 23 ++++ d05/ex07/ft_strncmp.c | 26 ++++ d05/ex08/ft_strupcase.c | 28 ++++ d05/ex09/ft_strlowcase.c | 28 ++++ d05/ex10/ft_strcapitalize.c | 46 +++++++ d05/ex11/ft_str_is_alpha.c | 24 ++++ d05/ex12/ft_str_is_numeric.c | 24 ++++ d05/ex13/ft_str_is_lowercase.c | 24 ++++ d05/ex14/ft_str_is_uppercase.c | 24 ++++ d05/ex15/ft_str_is_printable.c | 24 ++++ d05/ex16/ft_strcat.c | 30 +++++ d06/ex00/ft_putchar.c | 19 +++ d06/ex00/ft_putstr.c | 22 ++++ d06/ex00/ft_strcmp.c | 23 ++++ d06/ex00/ft_strlen.c | 24 ++++ d06/ex00/ft_swap.c | 20 +++ d06/ex00/libft_creator.sh | 15 +++ d06/ex01/ft_print_program_name.c | 30 +++++ d06/ex02/ft_print_params.c | 36 ++++++ d06/ex03/ft_rev_params.c | 32 +++++ d06/ex04/ft_sort_params.c | 74 +++++++++++ d07/ex00/ft_strdup.c | 38 ++++++ d07/ex01/ft_range.c | 30 +++++ d07/ex02/ft_ultimate_range.c | 34 +++++ d07/ex03/ft_concat_params.c | 71 ++++++++++ d07/ex04/ft_split_whitespaces.c | 91 +++++++++++++ d08/ex00/ft_split_whitespaces.c | 74 +++++++++++ .../ft_split_whitespaces_partialy_working.c | 104 +++++++++++++++ d08/ex01/ft.h | 38 ++++++ d08/ex02/ft_boolean.h | 26 ++++ d08/ex03/ft_abs.h | 18 +++ d08/ex04/ft_point.h | 22 ++++ d09/ex00/ft_generic.c | 18 +++ d09/ex01/ft_takes_place.c | 32 +++++ d09/ex02/find_nicolas_bomber.sh | 13 ++ d09/ex03/defuse.sh | 14 ++ d09/ex04/ft_rot42.c | 27 ++++ d09/ex05/ft_button.c | 39 ++++++ d09/ex06/ft_destroy.c | 28 ++++ d09/ex07/ft_collatz_conjecture.c | 24 ++++ d09/ex08/ft_spy.c | 81 ++++++++++++ d09/ex09/where_am_i.sh | 21 +++ d09/ex10/ft_scrambler.c | 28 ++++ d09/ex11/ft_perso.h | 25 ++++ d09/ex12/ft_door.c | 56 ++++++++ d09/ex12/ft_door.h | 34 +++++ d09/ex12/main.c | 27 ++++ d09/ex13/ft_compact.c | 35 +++++ d09/ex16/ft_active_bits.c | 27 ++++ d09/ex17/ft_max.c | 29 +++++ d09/ex18/ft_join.c | 65 ++++++++++ d09/ex20/cold_shower.sh | 0 d09/ex22/save_donnie.sh | 13 ++ d09/ex23/ft_generic.c | 18 +++ d10/d10.tar | Bin 0 -> 8048 bytes d10/ex00/Makefile | 38 ++++++ d10/ex00/includes/ft.h | 2 + d10/ex00/srcs/ft_putchar.c | 19 +++ d10/ex00/srcs/ft_putstr.c | 22 ++++ d10/ex00/srcs/ft_strcmp.c | 23 ++++ d10/ex00/srcs/ft_strlen.c | 24 ++++ d10/ex00/srcs/ft_swap.c | 20 +++ d10/ex01/ft_foreach.c | 22 ++++ d10/ex02/ft_map.c | 28 ++++ d10/ex03/ft_any.c | 24 ++++ d10/ex04/ft_count_if.c | 28 ++++ d10/ex05/ft_is_sort.c | 35 +++++ d10/ex06/ft_atoi.c | 37 ++++++ d10/ex06/ft_putchar.c | 19 +++ d10/ex06/ft_putnbr.c | 58 +++++++++ d10/ex06/ft_putstr.c | 22 ++++ d10/ex06/main.c | 83 ++++++++++++ d10/test/Makefile | 30 +++++ d10/test/main.c | 20 +++ d11/ex00/ft_create_elem.c | 27 ++++ d11/ex00/ft_list.h | 34 +++++ d11/ex01/ft_list.h | 34 +++++ d11/ex01/ft_list_push_back.c | 26 ++++ d11/ex02/ft_list.h | 34 +++++ d11/ex02/ft_list_push_front.c | 22 ++++ d11/ex03/ft_list.h | 34 +++++ d11/ex03/ft_list_size.c | 26 ++++ d11/ex04/ft_list.h | 34 +++++ d11/ex04/ft_list_last.c | 23 ++++ d11/ex05/ft_list.h | 34 +++++ d11/ex05/ft_list_push_params.c | 33 +++++ d11/ex06/ft_list.h | 34 +++++ d11/ex06/ft_list_clear.c | 26 ++++ d11/ex07/ft_list.h | 34 +++++ d11/ex07/ft_list_at.c | 30 +++++ d11/ex08/ft_list.h | 34 +++++ d11/ex08/ft_list_reverse.c | 32 +++++ d11/ex09/ft_list.h | 34 +++++ d11/ex09/ft_list_foreach.c | 22 ++++ d11/ex10/ft_list.h | 38 ++++++ d11/ex10/ft_list_foreach_if.c | 24 ++++ d11/ex11/ft_list.h | 38 ++++++ d11/ex11/ft_list_find.c | 24 ++++ d11_test/Makefile | 26 ++++ d11_test/ft_list.h | 38 ++++++ d11_test/ft_list_print.c | 23 ++++ d11_test/main.c | 92 +++++++++++++ d12/ex00/Makefile | 36 ++++++ d12/ex00/headers/ft.h | 40 ++++++ d12/ex00/main/display_file.c | 44 +++++++ d12/ex00/src/ft_putchar.c | 19 +++ d12/ex00/src/ft_putstr.c | 22 ++++ d12/ex01/Makefile | 36 ++++++ d12/ex01/headers/ft.h | 42 ++++++ d12/ex01/main/ft_cat.c | 35 +++++ d12/ex01/src/ft_putchar.c | 19 +++ d12/ex01/src/ft_putstr.c | 22 ++++ d12/ex01/src/loop.c | 41 ++++++ d12/ex01/src/print_err.c | 38 ++++++ d12_test/open.c | 50 ++++++++ d13/ex00/btree_create_node.c | 28 ++++ d13/ex00/ft_btree.h | 33 +++++ d13/ex01/btree_apply_prefix.c | 22 ++++ d13/ex01/ft_btree.h | 33 +++++ d13/ex02/btree_apply_infix.c | 22 ++++ d13/ex02/ft_btree.h | 33 +++++ d13/ex03/btree_apply_suffix.c | 22 ++++ d13/ex03/ft_btree.h | 33 +++++ d13/ex04/btree_insert_data.c | 28 ++++ d13/ex04/ft_btree.h | 33 +++++ d13/ex05/btree_search_item.c | 32 +++++ d13/ex05/ft_btree.h | 33 +++++ d13_test/Makefile | 26 ++++ d13_test/btree_print.c | 23 ++++ d13_test/ft_btree.h | 33 +++++ d13_test/main.c | 81 ++++++++++++ ft_lib/lib/ft.h | 33 +++++ ft_lib/lib/libft.a | Bin 0 -> 17348 bytes ft_lib/libft.a | 1 + ft_lib/libft_creator.sh | 35 +++++ ft_lib/src/ft_atoi.c | 37 ++++++ ft_lib/src/ft_putchar.c | 19 +++ ft_lib/src/ft_putnbr.c | 58 +++++++++ ft_lib/src/ft_putstr.c | 22 ++++ ft_lib/src/ft_str_is_alpha.c | 24 ++++ ft_lib/src/ft_str_is_lowercase.c | 24 ++++ ft_lib/src/ft_str_is_numeric.c | 24 ++++ ft_lib/src/ft_str_is_printable.c | 24 ++++ ft_lib/src/ft_str_is_uppercase.c | 24 ++++ ft_lib/src/ft_strcapitalize.c | 46 +++++++ ft_lib/src/ft_strcat.c | 30 +++++ ft_lib/src/ft_strcmp.c | 23 ++++ ft_lib/src/ft_strcpy.c | 26 ++++ ft_lib/src/ft_strlen.c | 24 ++++ ft_lib/src/ft_strlowcase.c | 28 ++++ ft_lib/src/ft_strncmp.c | 26 ++++ ft_lib/src/ft_strncpy.c | 29 +++++ ft_lib/src/ft_strstr.c | 33 +++++ ft_lib/src/ft_strupcase.c | 28 ++++ ft_lib/src/ft_swap.c | 20 +++ ft_lib/test/main.c | 19 +++ group_BSQ/Makefile | 40 ++++++ group_BSQ/auteur | 1 + group_BSQ/includes/bsq.h | 18 +++ group_BSQ/includes/corr_map.h | 20 +++ group_BSQ/includes/find_max.h | 26 ++++ group_BSQ/includes/output.h | 22 ++++ group_BSQ/includes/read.h | 21 +++ group_BSQ/map_gen.pl | 18 +++ group_BSQ/srcs/bsq.c | 121 ++++++++++++++++++ group_BSQ/srcs/corr_map.c | 32 +++++ group_BSQ/srcs/find_max.c | 96 ++++++++++++++ group_BSQ/srcs/main.c | 45 +++++++ group_BSQ/srcs/output.c | 57 +++++++++ group_BSQ/srcs/read.c | 113 ++++++++++++++++ my_bsq/Makefile | 35 +++++ my_bsq/headers/ft.h | 38 ++++++ my_bsq/lib_src/ft_atoi.c | 37 ++++++ my_bsq/lib_src/ft_putchar.c | 19 +++ my_bsq/lib_src/ft_putnbr.c | 58 +++++++++ my_bsq/lib_src/ft_putstr.c | 22 ++++ my_bsq/lib_src/ft_str_is_alpha.c | 24 ++++ my_bsq/lib_src/ft_str_is_lowercase.c | 24 ++++ my_bsq/lib_src/ft_str_is_numeric.c | 24 ++++ my_bsq/lib_src/ft_str_is_printable.c | 24 ++++ my_bsq/lib_src/ft_str_is_uppercase.c | 24 ++++ my_bsq/lib_src/ft_strcapitalize.c | 46 +++++++ my_bsq/lib_src/ft_strcat.c | 30 +++++ my_bsq/lib_src/ft_strcmp.c | 23 ++++ my_bsq/lib_src/ft_strcpy.c | 26 ++++ my_bsq/lib_src/ft_strlen.c | 24 ++++ my_bsq/lib_src/ft_strlowcase.c | 28 ++++ my_bsq/lib_src/ft_strncmp.c | 26 ++++ my_bsq/lib_src/ft_strncpy.c | 29 +++++ my_bsq/lib_src/ft_strstr.c | 33 +++++ my_bsq/lib_src/ft_strupcase.c | 28 ++++ my_bsq/lib_src/ft_swap.c | 20 +++ my_bsq/map_gen.pl | 18 +++ my_bsq/src/main.c | 85 ++++++++++++ rushes/rush00/ex00/ft_putchar.c | 19 +++ rushes/rush00/ex00/main.c | 29 +++++ rushes/rush00/ex00/rush00.c | 56 ++++++++ rushes/rush00/ex00/rush01.c | 56 ++++++++ rushes/rush00/ex00/rush02.c | 56 ++++++++ rushes/rush00/ex00/rush03.c | 56 ++++++++ rushes/rush00/ex00/rush04.c | 56 ++++++++ rushes/rush02/ex00/Makefile | 36 ++++++ rushes/rush02/ex00/bin/rush-00 | Bin 0 -> 8600 bytes rushes/rush02/ex00/bin/rush-01 | Bin 0 -> 8600 bytes rushes/rush02/ex00/bin/rush-02 | Bin 0 -> 8600 bytes rushes/rush02/ex00/bin/rush-03 | Bin 0 -> 8600 bytes rushes/rush02/ex00/bin/rush-04 | Bin 0 -> 8600 bytes rushes/rush02/ex00/bin/rush-2 | Bin 0 -> 13596 bytes rushes/rush02/ex00/headers/ft.h | 38 ++++++ rushes/rush02/ex00/headers/rush00.h | 18 +++ rushes/rush02/ex00/headers/rush02.h | 32 +++++ rushes/rush02/ex00/lib/libft.a | Bin 0 -> 17348 bytes rushes/rush02/ex00/src-rush-00/main.c | 27 ++++ rushes/rush02/ex00/src-rush-00/rush00.c | 56 ++++++++ rushes/rush02/ex00/src-rush-00/rush01.c | 56 ++++++++ rushes/rush02/ex00/src-rush-00/rush02.c | 56 ++++++++ rushes/rush02/ex00/src-rush-00/rush03.c | 56 ++++++++ rushes/rush02/ex00/src-rush-00/rush04.c | 56 ++++++++ rushes/rush02/ex00/src-rush-02/buf_concat.c | 28 ++++ .../rush02/ex00/src-rush-02/det_dimensions.c | 41 ++++++ rushes/rush02/ex00/src-rush-02/find_rush.c | 41 ++++++ rushes/rush02/ex00/src-rush-02/input_read.c | 30 +++++ rushes/rush02/ex00/src-rush-02/main.c | 26 ++++ rushes/rush02/ex00/src-rush-02/print_result.c | 55 ++++++++ rushes/rush02/ex00/src-rush-02/rush_creator.c | 43 +++++++ .../rush02/ex00/src-rush-02/rush_functions.c | 101 +++++++++++++++ 284 files changed, 8382 insertions(+) create mode 100644 brainfuck/Makefile create mode 100644 brainfuck/README create mode 100644 brainfuck/hello_world.bf create mode 100644 brainfuck/inc/brnfck.h create mode 100644 brainfuck/src/brainfuck.c create mode 100644 brainfuck/src/main.c create mode 100644 brainfuck/src/output.c create mode 100644 d00/ex01/testDay00.tar create mode 100644 d00/ex02/exo2.tar create mode 100644 d00/ex03/klist.txt create mode 100644 d00/ex04/who_am_i.sh create mode 100644 d00/ex05/people.sh create mode 100644 d00/ex06/mobile-phone.ldif create mode 100644 d00/ex07/midLS create mode 100644 d00/ex08/z create mode 100644 d00/ex09/b create mode 100644 d00/ex10/clean create mode 100644 d00/ex11/ft_magic create mode 100755 d01/ex01/print_groups.sh create mode 100755 d01/ex02/find_sh.sh create mode 100755 d01/ex03/count_files.sh create mode 100755 d01/ex04/MAC.sh create mode 100644 "d01/ex05/\"?$*KwaMe*$?\\\"" create mode 100644 "d01/ex05/\"\\?$*'KwaMe'*$?\\\"" create mode 100755 d01/ex06/skip.sh create mode 100755 d01/ex07/r_dwssap.sh create mode 100755 d01/ex08/bon.sh create mode 100644 d01/ex09/add_chelou.sh create mode 100644 d02/ex00/ft_print_alphabet.c create mode 100644 d02/ex01/ft_print_reverse_alphabet.c create mode 100644 d02/ex02/ft_print_numbers.c create mode 100644 d02/ex03/ft_is_negative.c create mode 100644 d02/ex04/ft_print_comb.c create mode 100644 d02/ex06/ft_putnbr.c create mode 100644 d03/ex00/ft_ft.c create mode 100644 d03/ex01/ft_ultimate_ft.c create mode 100644 d03/ex02/ft_swap.c create mode 100755 d03/ex03/ft_div_mod create mode 100644 d03/ex03/ft_div_mod.c create mode 100644 d03/ex04/ft_ultimate_div_mod.c create mode 100644 d03/ex05/ft_putstr.c create mode 100644 d03/ex06/ft_strlen.c create mode 100644 d03/ex07/ft_strrev.c create mode 100644 d03/ex08/ft_atoi.c create mode 100644 d03/ex09/ft_sort_integer_table.c create mode 100644 d04/ex00/ft_iterative_factorial.c create mode 100644 d04/ex01/ft_recursive_factorial.c create mode 100644 d04/ex02/ft_iterative_power.c create mode 100644 d04/ex03/ft_recursive_power.c create mode 100644 d04/ex04/ft_fibonacci.c create mode 100644 d04/ex05/ft_sqrt.c create mode 100644 d04/ex06/ft_is_prime.c create mode 100644 d05/ex00/ft_putstr.c create mode 100644 d05/ex01/ft_putnbr.c create mode 100644 d05/ex02/ft_atoi.c create mode 100644 d05/ex03/ft_strcpy.c create mode 100644 d05/ex04/ft_strncpy.c create mode 100644 d05/ex05/ft_strstr.c create mode 100644 d05/ex06/ft_strcmp.c create mode 100644 d05/ex07/ft_strncmp.c create mode 100644 d05/ex08/ft_strupcase.c create mode 100644 d05/ex09/ft_strlowcase.c create mode 100644 d05/ex10/ft_strcapitalize.c create mode 100644 d05/ex11/ft_str_is_alpha.c create mode 100644 d05/ex12/ft_str_is_numeric.c create mode 100644 d05/ex13/ft_str_is_lowercase.c create mode 100644 d05/ex14/ft_str_is_uppercase.c create mode 100644 d05/ex15/ft_str_is_printable.c create mode 100644 d05/ex16/ft_strcat.c create mode 100644 d06/ex00/ft_putchar.c create mode 100644 d06/ex00/ft_putstr.c create mode 100644 d06/ex00/ft_strcmp.c create mode 100644 d06/ex00/ft_strlen.c create mode 100644 d06/ex00/ft_swap.c create mode 100755 d06/ex00/libft_creator.sh create mode 100644 d06/ex01/ft_print_program_name.c create mode 100644 d06/ex02/ft_print_params.c create mode 100644 d06/ex03/ft_rev_params.c create mode 100644 d06/ex04/ft_sort_params.c create mode 100644 d07/ex00/ft_strdup.c create mode 100644 d07/ex01/ft_range.c create mode 100644 d07/ex02/ft_ultimate_range.c create mode 100644 d07/ex03/ft_concat_params.c create mode 100644 d07/ex04/ft_split_whitespaces.c create mode 100644 d08/ex00/ft_split_whitespaces.c create mode 100644 d08/ex00/ft_split_whitespaces_partialy_working.c create mode 100644 d08/ex01/ft.h create mode 100644 d08/ex02/ft_boolean.h create mode 100644 d08/ex03/ft_abs.h create mode 100644 d08/ex04/ft_point.h create mode 100644 d09/ex00/ft_generic.c create mode 100644 d09/ex01/ft_takes_place.c create mode 100755 d09/ex02/find_nicolas_bomber.sh create mode 100755 d09/ex03/defuse.sh create mode 100644 d09/ex04/ft_rot42.c create mode 100644 d09/ex05/ft_button.c create mode 100644 d09/ex06/ft_destroy.c create mode 100644 d09/ex07/ft_collatz_conjecture.c create mode 100644 d09/ex08/ft_spy.c create mode 100644 d09/ex09/where_am_i.sh create mode 100644 d09/ex10/ft_scrambler.c create mode 100644 d09/ex11/ft_perso.h create mode 100644 d09/ex12/ft_door.c create mode 100644 d09/ex12/ft_door.h create mode 100644 d09/ex12/main.c create mode 100644 d09/ex13/ft_compact.c create mode 100644 d09/ex16/ft_active_bits.c create mode 100644 d09/ex17/ft_max.c create mode 100644 d09/ex18/ft_join.c create mode 100644 d09/ex20/cold_shower.sh create mode 100755 d09/ex22/save_donnie.sh create mode 100644 d09/ex23/ft_generic.c create mode 100644 d10/d10.tar create mode 100644 d10/ex00/Makefile create mode 100644 d10/ex00/includes/ft.h create mode 100644 d10/ex00/srcs/ft_putchar.c create mode 100644 d10/ex00/srcs/ft_putstr.c create mode 100644 d10/ex00/srcs/ft_strcmp.c create mode 100644 d10/ex00/srcs/ft_strlen.c create mode 100644 d10/ex00/srcs/ft_swap.c create mode 100644 d10/ex01/ft_foreach.c create mode 100644 d10/ex02/ft_map.c create mode 100644 d10/ex03/ft_any.c create mode 100644 d10/ex04/ft_count_if.c create mode 100644 d10/ex05/ft_is_sort.c create mode 100644 d10/ex06/ft_atoi.c create mode 100644 d10/ex06/ft_putchar.c create mode 100644 d10/ex06/ft_putnbr.c create mode 100644 d10/ex06/ft_putstr.c create mode 100644 d10/ex06/main.c create mode 100644 d10/test/Makefile create mode 100644 d10/test/main.c create mode 100644 d11/ex00/ft_create_elem.c create mode 100644 d11/ex00/ft_list.h create mode 100644 d11/ex01/ft_list.h create mode 100644 d11/ex01/ft_list_push_back.c create mode 100644 d11/ex02/ft_list.h create mode 100644 d11/ex02/ft_list_push_front.c create mode 100644 d11/ex03/ft_list.h create mode 100644 d11/ex03/ft_list_size.c create mode 100644 d11/ex04/ft_list.h create mode 100644 d11/ex04/ft_list_last.c create mode 100644 d11/ex05/ft_list.h create mode 100644 d11/ex05/ft_list_push_params.c create mode 100644 d11/ex06/ft_list.h create mode 100644 d11/ex06/ft_list_clear.c create mode 100644 d11/ex07/ft_list.h create mode 100644 d11/ex07/ft_list_at.c create mode 100644 d11/ex08/ft_list.h create mode 100644 d11/ex08/ft_list_reverse.c create mode 100644 d11/ex09/ft_list.h create mode 100644 d11/ex09/ft_list_foreach.c create mode 100644 d11/ex10/ft_list.h create mode 100644 d11/ex10/ft_list_foreach_if.c create mode 100644 d11/ex11/ft_list.h create mode 100644 d11/ex11/ft_list_find.c create mode 100644 d11_test/Makefile create mode 100644 d11_test/ft_list.h create mode 100644 d11_test/ft_list_print.c create mode 100644 d11_test/main.c create mode 100644 d12/ex00/Makefile create mode 100644 d12/ex00/headers/ft.h create mode 100644 d12/ex00/main/display_file.c create mode 100644 d12/ex00/src/ft_putchar.c create mode 100644 d12/ex00/src/ft_putstr.c create mode 100644 d12/ex01/Makefile create mode 100644 d12/ex01/headers/ft.h create mode 100644 d12/ex01/main/ft_cat.c create mode 100644 d12/ex01/src/ft_putchar.c create mode 100644 d12/ex01/src/ft_putstr.c create mode 100644 d12/ex01/src/loop.c create mode 100644 d12/ex01/src/print_err.c create mode 100644 d12_test/open.c create mode 100644 d13/ex00/btree_create_node.c create mode 100644 d13/ex00/ft_btree.h create mode 100644 d13/ex01/btree_apply_prefix.c create mode 100644 d13/ex01/ft_btree.h create mode 100644 d13/ex02/btree_apply_infix.c create mode 100644 d13/ex02/ft_btree.h create mode 100644 d13/ex03/btree_apply_suffix.c create mode 100644 d13/ex03/ft_btree.h create mode 100644 d13/ex04/btree_insert_data.c create mode 100644 d13/ex04/ft_btree.h create mode 100644 d13/ex05/btree_search_item.c create mode 100644 d13/ex05/ft_btree.h create mode 100644 d13_test/Makefile create mode 100644 d13_test/btree_print.c create mode 100644 d13_test/ft_btree.h create mode 100644 d13_test/main.c create mode 100644 ft_lib/lib/ft.h create mode 100644 ft_lib/lib/libft.a create mode 100644 ft_lib/libft.a create mode 100755 ft_lib/libft_creator.sh create mode 100644 ft_lib/src/ft_atoi.c create mode 100644 ft_lib/src/ft_putchar.c create mode 100644 ft_lib/src/ft_putnbr.c create mode 100644 ft_lib/src/ft_putstr.c create mode 100644 ft_lib/src/ft_str_is_alpha.c create mode 100644 ft_lib/src/ft_str_is_lowercase.c create mode 100644 ft_lib/src/ft_str_is_numeric.c create mode 100644 ft_lib/src/ft_str_is_printable.c create mode 100644 ft_lib/src/ft_str_is_uppercase.c create mode 100644 ft_lib/src/ft_strcapitalize.c create mode 100644 ft_lib/src/ft_strcat.c create mode 100644 ft_lib/src/ft_strcmp.c create mode 100644 ft_lib/src/ft_strcpy.c create mode 100644 ft_lib/src/ft_strlen.c create mode 100644 ft_lib/src/ft_strlowcase.c create mode 100644 ft_lib/src/ft_strncmp.c create mode 100644 ft_lib/src/ft_strncpy.c create mode 100644 ft_lib/src/ft_strstr.c create mode 100644 ft_lib/src/ft_strupcase.c create mode 100644 ft_lib/src/ft_swap.c create mode 100644 ft_lib/test/main.c create mode 100644 group_BSQ/Makefile create mode 100644 group_BSQ/auteur create mode 100644 group_BSQ/includes/bsq.h create mode 100644 group_BSQ/includes/corr_map.h create mode 100755 group_BSQ/includes/find_max.h create mode 100755 group_BSQ/includes/output.h create mode 100755 group_BSQ/includes/read.h create mode 100755 group_BSQ/map_gen.pl create mode 100644 group_BSQ/srcs/bsq.c create mode 100644 group_BSQ/srcs/corr_map.c create mode 100755 group_BSQ/srcs/find_max.c create mode 100755 group_BSQ/srcs/main.c create mode 100755 group_BSQ/srcs/output.c create mode 100755 group_BSQ/srcs/read.c create mode 100644 my_bsq/Makefile create mode 100644 my_bsq/headers/ft.h create mode 100644 my_bsq/lib_src/ft_atoi.c create mode 100644 my_bsq/lib_src/ft_putchar.c create mode 100644 my_bsq/lib_src/ft_putnbr.c create mode 100644 my_bsq/lib_src/ft_putstr.c create mode 100644 my_bsq/lib_src/ft_str_is_alpha.c create mode 100644 my_bsq/lib_src/ft_str_is_lowercase.c create mode 100644 my_bsq/lib_src/ft_str_is_numeric.c create mode 100644 my_bsq/lib_src/ft_str_is_printable.c create mode 100644 my_bsq/lib_src/ft_str_is_uppercase.c create mode 100644 my_bsq/lib_src/ft_strcapitalize.c create mode 100644 my_bsq/lib_src/ft_strcat.c create mode 100644 my_bsq/lib_src/ft_strcmp.c create mode 100644 my_bsq/lib_src/ft_strcpy.c create mode 100644 my_bsq/lib_src/ft_strlen.c create mode 100644 my_bsq/lib_src/ft_strlowcase.c create mode 100644 my_bsq/lib_src/ft_strncmp.c create mode 100644 my_bsq/lib_src/ft_strncpy.c create mode 100644 my_bsq/lib_src/ft_strstr.c create mode 100644 my_bsq/lib_src/ft_strupcase.c create mode 100644 my_bsq/lib_src/ft_swap.c create mode 100755 my_bsq/map_gen.pl create mode 100644 my_bsq/src/main.c create mode 100644 rushes/rush00/ex00/ft_putchar.c create mode 100644 rushes/rush00/ex00/main.c create mode 100644 rushes/rush00/ex00/rush00.c create mode 100644 rushes/rush00/ex00/rush01.c create mode 100644 rushes/rush00/ex00/rush02.c create mode 100644 rushes/rush00/ex00/rush03.c create mode 100644 rushes/rush00/ex00/rush04.c create mode 100644 rushes/rush02/ex00/Makefile create mode 100755 rushes/rush02/ex00/bin/rush-00 create mode 100755 rushes/rush02/ex00/bin/rush-01 create mode 100755 rushes/rush02/ex00/bin/rush-02 create mode 100755 rushes/rush02/ex00/bin/rush-03 create mode 100755 rushes/rush02/ex00/bin/rush-04 create mode 100755 rushes/rush02/ex00/bin/rush-2 create mode 100644 rushes/rush02/ex00/headers/ft.h create mode 100644 rushes/rush02/ex00/headers/rush00.h create mode 100644 rushes/rush02/ex00/headers/rush02.h create mode 100644 rushes/rush02/ex00/lib/libft.a create mode 100644 rushes/rush02/ex00/src-rush-00/main.c create mode 100644 rushes/rush02/ex00/src-rush-00/rush00.c create mode 100644 rushes/rush02/ex00/src-rush-00/rush01.c create mode 100644 rushes/rush02/ex00/src-rush-00/rush02.c create mode 100644 rushes/rush02/ex00/src-rush-00/rush03.c create mode 100644 rushes/rush02/ex00/src-rush-00/rush04.c create mode 100644 rushes/rush02/ex00/src-rush-02/buf_concat.c create mode 100644 rushes/rush02/ex00/src-rush-02/det_dimensions.c create mode 100644 rushes/rush02/ex00/src-rush-02/find_rush.c create mode 100644 rushes/rush02/ex00/src-rush-02/input_read.c create mode 100644 rushes/rush02/ex00/src-rush-02/main.c create mode 100644 rushes/rush02/ex00/src-rush-02/print_result.c create mode 100644 rushes/rush02/ex00/src-rush-02/rush_creator.c create mode 100644 rushes/rush02/ex00/src-rush-02/rush_functions.c diff --git a/brainfuck/Makefile b/brainfuck/Makefile new file mode 100644 index 0000000..a61d6fc --- /dev/null +++ b/brainfuck/Makefile @@ -0,0 +1,32 @@ +# MAkefile +# AUTHOR: foton +# FILE: Makefile +# ROLE: to compile them all +# CREATED: 2016-11-20 00:59:16 +# MODIFIED: 2016-11-20 01:14:41 + +NAME = brainfuck +CC = clang +FLAGS = -Wall -Werror -Wextra +SRC = src/main.c \ + src/output.c \ + src/brainfuck.c +OBJ = $(SRC:.c=.o) +INC = -I inc/ + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(FLAGS) $(OBJ) $(INC) -o $(NAME) + +.c.o: $(SRC) + $(CC) $(FLAGS) $(INC) -c $< -o $@ + +clean: + rm -f $(OBJ) + +fclean: clean + rm -f $(BIN)$(NAME) + +re: + fclean all diff --git a/brainfuck/README b/brainfuck/README new file mode 100644 index 0000000..ebb5bfd --- /dev/null +++ b/brainfuck/README @@ -0,0 +1,11 @@ +# Text File +# AUTHOR: foton +# FILE: README +# ROLE: to rule them all +# CREATED: 2016-11-20 01:18:23 +# MODIFIED: 2016-11-20 01:20:33 + +Simple brainfuck interpreter. + +compile: "make fclean, make" or "make re" +test: "cat hello_world.bf | xargs ./brainfuck" diff --git a/brainfuck/hello_world.bf b/brainfuck/hello_world.bf new file mode 100644 index 0000000..e0a8381 --- /dev/null +++ b/brainfuck/hello_world.bf @@ -0,0 +1 @@ +++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>. \ No newline at end of file diff --git a/brainfuck/inc/brnfck.h b/brainfuck/inc/brnfck.h new file mode 100644 index 0000000..0268c73 --- /dev/null +++ b/brainfuck/inc/brnfck.h @@ -0,0 +1,17 @@ +// C/C++ File +// AUTHOR: foton +// FILE: brnfck.h +// ROLE: to rule them all +// CREATED: 2016-11-20 00:52:13 +// MODIFIED: 2016-11-20 00:54:35 + +#ifndef BRNFCK_H +# define BRNFCK_H + +# define SIZE 30000 + +int brainfuck(char *source); +void my_putchar(char c); +void my_putstr(char *str); + +#endif diff --git a/brainfuck/src/brainfuck.c b/brainfuck/src/brainfuck.c new file mode 100644 index 0000000..f9c0704 --- /dev/null +++ b/brainfuck/src/brainfuck.c @@ -0,0 +1,52 @@ +// C/C++ File +// AUTHOR: foton +// FILE: brainfuck.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 01:13:18 +// TODO: nested loops +// read user input +// handle errors (incorrect source) +// read from file and stdin + +#include +#include "brnfck.h" + +int brainfuck(char *source) +{ + char *array; + int i; + int head; + int start_loop; + + i = 0; + array = malloc(sizeof(char) * SIZE); + while (i < SIZE) + array[i++] = 0; + i = 0; + head = 0; + start_loop = 0; + while (source[i]) + { + if (source[i] == '+') + array[head]++; + if (source[i] == '-') + array[head]--; + if (source[i] == '>') + head++; + if (source[i] == '<') + head--; + if (source[i] == '.') + my_putchar(array[head]); + if (source[i] == '[') + start_loop = i; + if (source[i] == ']') + { + if (!(array[head] == 0)) + i = start_loop - 1; + } + i++; + } + free(array); + return (0); +} diff --git a/brainfuck/src/main.c b/brainfuck/src/main.c new file mode 100644 index 0000000..e374629 --- /dev/null +++ b/brainfuck/src/main.c @@ -0,0 +1,23 @@ +// C/C++ File +// AUTHOR: foton +// FILE: main.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 01:15:58 + +#include "brnfck.h" + +int main(int argc, char **argv) +{ + if (argc < 2) + { + my_putstr("Dude, put some source to work with!\n"); + return (0); + } + if (brainfuck(argv[1]) == 1) + { + my_putstr("Something goes wrong :(\n"); + return (1); + } + return (0); +} diff --git a/brainfuck/src/output.c b/brainfuck/src/output.c new file mode 100644 index 0000000..a2fb8fc --- /dev/null +++ b/brainfuck/src/output.c @@ -0,0 +1,19 @@ +// C/C++ File +// AUTHOR: foton +// FILE: output.c +// ROLE: to rule them all +// CREATED: 2016-11-19 22:28:26 +// MODIFIED: 2016-11-20 00:51:42 + +#include + +void my_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +void my_putchar(char c) +{ + write(1, &c, 1); +} diff --git a/d00/ex01/testDay00.tar b/d00/ex01/testDay00.tar new file mode 100644 index 0000000000000000000000000000000000000000..b5e01563b0c603b6bc9f4783750ee02c1b201577 GIT binary patch literal 2048 zcmeH@yA6Oa3`9MOM>r>OSb#-RAgB{lusxqhNYEou_!|3sjqlmiY%Ci<-w8lcWrBzd zI4Al%f=ddPFoc*>3K0y6P!NCl)7^G$Rw@CrP1Uxx+`(%Jko-D5Y;SUuyTp&ojT3MJ MPQVE`fu9lB0W0MeasU7T literal 0 HcmV?d00001 diff --git a/d00/ex02/exo2.tar b/d00/ex02/exo2.tar new file mode 100644 index 0000000000000000000000000000000000000000..183d63917279750afd8f46c80fb7b1c41258ae3b GIT binary patch literal 6144 zcmeHLyK=-J4CGVzgXjhNo)kApeI`ZzKFHv7N1Bu8G8PRU;}K%ly9nBCYw(s_8vrPl zoB$COtcTI}f!Q*W5?9npk^xCjQ!cJq&EQ{Kd%q`uk9NDa@9p!^oCH`OjoJILkiNLR z<<+OJG}b!*=$ueTL{V1!%jBPGDPa6Fmz2RduRZ+5`9A~VnB#R3F#VIi{})*5AEy4f zhz|cJ2>(ChuQC4Fd7|$BvgRKr{~|)e|4G9CooR{ifj~0-i!%;g|5b2R|Ix4hdDQ>R zp?_yqB77i_cKv&wv;W@zkNWS}|Ctd}#xshOi=Y1t;^n=@6GUR?f7O-$AN(^FvHFku ZL&{{yd0zrtoc|}#8zBOLK;WMu@B?GYm|*|_ literal 0 HcmV?d00001 diff --git a/d00/ex03/klist.txt b/d00/ex03/klist.txt new file mode 100644 index 0000000..8de2bf7 --- /dev/null +++ b/d00/ex03/klist.txt @@ -0,0 +1,5 @@ +Credentials cache: API:4728 + Principal: gtertysh@UNIT.UA + + Issued Expires Principal +Oct 26 12:13:24 2016 Oct 26 22:13:16 2016 krbtgt/UNIT.UA@UNIT.UA diff --git a/d00/ex04/who_am_i.sh b/d00/ex04/who_am_i.sh new file mode 100644 index 0000000..d39dfcb --- /dev/null +++ b/d00/ex04/who_am_i.sh @@ -0,0 +1 @@ +ldapwhoami -Q | cut -c4- | cut -d , -f1,3- diff --git a/d00/ex05/people.sh b/d00/ex05/people.sh new file mode 100644 index 0000000..3f30bf6 --- /dev/null +++ b/d00/ex05/people.sh @@ -0,0 +1 @@ +ldapsearch -Q -LLL "uid=z*" | grep "^cn" | sort -r diff --git a/d00/ex06/mobile-phone.ldif b/d00/ex06/mobile-phone.ldif new file mode 100644 index 0000000..0ac129d --- /dev/null +++ b/d00/ex06/mobile-phone.ldif @@ -0,0 +1,4 @@ +dn: uid=gtertysh,ou=november,ou=2016,ou=people,dc=unit,dc=ua +changetype: modify +add: mobile +mobile: 0930351607 diff --git a/d00/ex07/midLS b/d00/ex07/midLS new file mode 100644 index 0000000..f5883a8 --- /dev/null +++ b/d00/ex07/midLS @@ -0,0 +1 @@ +ls -mpU diff --git a/d00/ex08/z b/d00/ex08/z new file mode 100644 index 0000000..e900b1c --- /dev/null +++ b/d00/ex08/z @@ -0,0 +1 @@ +Z diff --git a/d00/ex09/b b/d00/ex09/b new file mode 100644 index 0000000..c2dab24 --- /dev/null +++ b/d00/ex09/b @@ -0,0 +1,11 @@ +Episode V, A NEW H0PE It is a period of civil war +Rebel spaceships, striking from a hidden base, have won their first victory against the evil Galactic Empire. +During the battle, Rebel spies managed to steal secret plans to the Empire's ultimate weapon, the STAR DEATH, an armored space station with enough power to destroy an entire planet. + + +Pursued by the Empire's sinister agents, +Princess Mehdi races home aboard her starship, custodian of the stolen plans that can save her people and restore the dictatorship to the galaxie.. + + + + diff --git a/d00/ex10/clean b/d00/ex10/clean new file mode 100644 index 0000000..a38380e --- /dev/null +++ b/d00/ex10/clean @@ -0,0 +1 @@ +find . -type f \( -name '*~' -o -name '#*' -o -name '*#' \) -print -delete diff --git a/d00/ex11/ft_magic b/d00/ex11/ft_magic new file mode 100644 index 0000000..42b581f --- /dev/null +++ b/d00/ex11/ft_magic @@ -0,0 +1 @@ +41 string 42 42 file diff --git a/d01/ex01/print_groups.sh b/d01/ex01/print_groups.sh new file mode 100755 index 0000000..f2606fd --- /dev/null +++ b/d01/ex01/print_groups.sh @@ -0,0 +1 @@ +groups $FT_USER | tr ' ' ',' | tr -d '\n' diff --git a/d01/ex02/find_sh.sh b/d01/ex02/find_sh.sh new file mode 100755 index 0000000..0fc8f6b --- /dev/null +++ b/d01/ex02/find_sh.sh @@ -0,0 +1 @@ +find . -name "*.sh" | rev | cut -d '.' -f 2 | cut -d '/' -f 1 | rev diff --git a/d01/ex03/count_files.sh b/d01/ex03/count_files.sh new file mode 100755 index 0000000..dae8dc2 --- /dev/null +++ b/d01/ex03/count_files.sh @@ -0,0 +1 @@ +find . | wc -l | tr -d " " diff --git a/d01/ex04/MAC.sh b/d01/ex04/MAC.sh new file mode 100755 index 0000000..b5c33a8 --- /dev/null +++ b/d01/ex04/MAC.sh @@ -0,0 +1 @@ +ifconfig | tr -d "\t" | grep "^ether" | cut -d " " -f 2 diff --git "a/d01/ex05/\"?$*KwaMe*$?\\\"" "b/d01/ex05/\"?$*KwaMe*$?\\\"" new file mode 100644 index 0000000..e69de29 diff --git "a/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" "b/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" new file mode 100644 index 0000000..f70d7bb --- /dev/null +++ "b/d01/ex05/\"\\?$*'KwaMe'*$?\\\"" @@ -0,0 +1 @@ +42 \ No newline at end of file diff --git a/d01/ex06/skip.sh b/d01/ex06/skip.sh new file mode 100755 index 0000000..002c1e5 --- /dev/null +++ b/d01/ex06/skip.sh @@ -0,0 +1 @@ +ls -l | sed -n "p;n" diff --git a/d01/ex07/r_dwssap.sh b/d01/ex07/r_dwssap.sh new file mode 100755 index 0000000..ea1e8ae --- /dev/null +++ b/d01/ex07/r_dwssap.sh @@ -0,0 +1 @@ +cat /etc/passwd | grep -v ^# | sed -n 'n;p' | cut -d ":" -f1 | rev | sort -r | sed -n "$FT_LINE1,$FT_LINE2 p" | sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/, /g' | tr "\n" "." diff --git a/d01/ex08/bon.sh b/d01/ex08/bon.sh new file mode 100755 index 0000000..5ae96d3 --- /dev/null +++ b/d01/ex08/bon.sh @@ -0,0 +1 @@ +ldapsearch -Q | grep ^givenName | grep -i "bon" | wc -l | tr -d " " diff --git a/d01/ex09/add_chelou.sh b/d01/ex09/add_chelou.sh new file mode 100644 index 0000000..e69de29 diff --git a/d02/ex00/ft_print_alphabet.c b/d02/ex00/ft_print_alphabet.c new file mode 100644 index 0000000..0eebf83 --- /dev/null +++ b/d02/ex00/ft_print_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/26 17:23:25 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 20:23:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_alphabet(void) +{ + char a; + + a = 'a'; + while (a <= 'z') + { + ft_putchar(a); + a = a + 1; + } +} diff --git a/d02/ex01/ft_print_reverse_alphabet.c b/d02/ex01/ft_print_reverse_alphabet.c new file mode 100644 index 0000000..467f1c3 --- /dev/null +++ b/d02/ex01/ft_print_reverse_alphabet.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_reverse_alphabet.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:58:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:39:26 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_reverse_alphabet(void) +{ + char z; + + z = 'z'; + while (z >= 'a') + { + ft_putchar(z); + z = z - 1; + } +} diff --git a/d02/ex02/ft_print_numbers.c b/d02/ex02/ft_print_numbers.c new file mode 100644 index 0000000..7417c25 --- /dev/null +++ b/d02/ex02/ft_print_numbers.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_numbers.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:59:11 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:40:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_print_numbers(void) +{ + char z; + + z = '0'; + while (z <= '9') + { + ft_putchar(z); + z = z + 1; + } +} diff --git a/d02/ex03/ft_is_negative.c b/d02/ex03/ft_is_negative.c new file mode 100644 index 0000000..9a484b8 --- /dev/null +++ b/d02/ex03/ft_is_negative.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_negative.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:59:43 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 20:23:36 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_is_negative(int n) +{ + if (n >= 0) + { + ft_putchar('P'); + } + else + { + ft_putchar('N'); + } +} diff --git a/d02/ex04/ft_print_comb.c b/d02/ex04/ft_print_comb.c new file mode 100644 index 0000000..f244c21 --- /dev/null +++ b/d02/ex04/ft_print_comb.c @@ -0,0 +1,49 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_comb.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 10:26:03 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 11:46:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnumb(char a, char b, char c) +{ + ft_putchar(a); + ft_putchar(b); + ft_putchar(c); + if (!(a == '7' && b == '8' && c == '9')) + { + ft_putchar(','); + ft_putchar(' '); + } +} + +void ft_print_comb(void) +{ + int a; + int b; + int c; + + a = 0; + while (a <= 7) + { + b = a + 1; + while (b <= 8) + { + c = b + 1; + while (c <= 9) + { + ft_putnumb(a + '0', b + '0', c + '0'); + c++; + } + b++; + } + a++; + } +} diff --git a/d02/ex06/ft_putnbr.c b/d02/ex06/ft_putnbr.c new file mode 100644 index 0000000..5d097ac --- /dev/null +++ b/d02/ex06/ft_putnbr.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 17:17:51 by gtertysh #+# #+# */ +/* Updated: 2016/10/27 21:46:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_printnbr(int nb) +{ + int temp; + long div; + + temp = nb; + div = 1; + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } +} diff --git a/d03/ex00/ft_ft.c b/d03/ex00/ft_ft.c new file mode 100644 index 0000000..3306ab7 --- /dev/null +++ b/d03/ex00/ft_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft-ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/27 12:09:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 12:29:49 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ft(int *nbr) +{ + *nbr = 42; +} diff --git a/d03/ex01/ft_ultimate_ft.c b/d03/ex01/ft_ultimate_ft.c new file mode 100644 index 0000000..24dfcc6 --- /dev/null +++ b/d03/ex01/ft_ultimate_ft.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_ft.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 09:49:54 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 19:17:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ultimate_ft(int *********nbr) +{ + *********nbr = 42; +} diff --git a/d03/ex02/ft_swap.c b/d03/ex02/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d03/ex02/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d03/ex03/ft_div_mod b/d03/ex03/ft_div_mod new file mode 100755 index 0000000000000000000000000000000000000000..1c9d25c22fe82ec63d1a8e8fec0145ea903b9135 GIT binary patch literal 8520 zcmeHN&1(}u6rWf>Y88`Q#IM$+SkWHR6g&umB-+Ilt+uuW6=Y0IN&-n*lU=n3Ay9>^ zrI3q)2f>>t9z1vvq%Bm`dhwzM{{SU|LJp!qg7Nnzv*{+)f=6K5&eD5HYRoC#@2z6k|55__%%~15UueRwqP=_FG&~DoxZ}fmgVIuAvn*ORy5Zz zwZ^*zKq%gN>EY;3hjtmyd0&sm6Yl9_hapb$_9CvA~O0QDH(xY0fHe*$$Uj{>kvUjdhIwuU@Uhapb$_9CYkd3>ILoGUrmEwN{5Fu)7s93L@1IHYkWU1}U OfQxBK9995@aO^j +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:16:49 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:28:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_div_mod(int a, int b, int *div, int *mod) +{ + *div = a / b; + *mod = a % b; +} diff --git a/d03/ex04/ft_ultimate_div_mod.c b/d03/ex04/ft_ultimate_div_mod.c new file mode 100644 index 0000000..5010329 --- /dev/null +++ b/d03/ex04/ft_ultimate_div_mod.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_div_mode.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:30:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:17:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_ultimate_div_mod(int *a, int *b) +{ + int temp; + + temp = *a / *b; + *b = *a % *b; + *a = temp; +} diff --git a/d03/ex05/ft_putstr.c b/d03/ex05/ft_putstr.c new file mode 100644 index 0000000..ddff1c2 --- /dev/null +++ b/d03/ex05/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:45:38 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:09:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d03/ex06/ft_strlen.c b/d03/ex06/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d03/ex06/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d03/ex07/ft_strrev.c b/d03/ex07/ft_strrev.c new file mode 100644 index 0000000..113a0f2 --- /dev/null +++ b/d03/ex07/ft_strrev.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strrev.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:30:14 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:01:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strrev(char *str) +{ + int count; + int char_numb; + char *temp_ptr; + char temp; + + count = 0; + char_numb = 0; + temp_ptr = str; + while (*temp_ptr != '\0') + { + char_numb++; + temp_ptr++; + } + while (char_numb > count) + { + temp = *(str + char_numb - 1); + *(str + char_numb - 1) = *(str + count); + *(str + count) = temp; + count++; + char_numb--; + } + return (str); +} diff --git a/d03/ex08/ft_atoi.c b/d03/ex08/ft_atoi.c new file mode 100644 index 0000000..3512f12 --- /dev/null +++ b/d03/ex08/ft_atoi.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 12:27:05 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 21:02:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *p) +{ + int numb; + + numb = 0; + while (*p != '\0') + { + numb = numb * 10 + (*p) - '0'; + p++; + } + return (numb); +} diff --git a/d03/ex09/ft_sort_integer_table.c b/d03/ex09/ft_sort_integer_table.c new file mode 100644 index 0000000..c8bd2ac --- /dev/null +++ b/d03/ex09/ft_sort_integer_table.c @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_integer_table.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 10:16:57 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 12:03:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_sort_integer_table(int *tab, int size) +{ + int temp; + int i; + int a; + int swapped; + + i = 0; + a = 0; + while(i < size - 1) + { + swapped = 0; + while(a < size - 1 - i) + { + if (*(tab + a) > *(tab + a + 1)) + { + temp = *(tab + a); + *(tab + a) = *(tab + a + 1); + *(tab + a + 1) = temp; + swapped = 1; + } + a++; + } + i++; + if(!swapped) + break; + } +} diff --git a/d04/ex00/ft_iterative_factorial.c b/d04/ex00/ft_iterative_factorial.c new file mode 100644 index 0000000..e6dbe57 --- /dev/null +++ b/d04/ex00/ft_iterative_factorial.c @@ -0,0 +1,31 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 15:38:54 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 15:38:59 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_factorial(int nb) +{ + int fac; + + fac = 1; + if (nb > 12 || nb < 0) + { + return (0); + } + else + { + while (nb > 0) + { + fac *= nb; + nb--; + } + } + return (fac); +} diff --git a/d04/ex01/ft_recursive_factorial.c b/d04/ex01/ft_recursive_factorial.c new file mode 100644 index 0000000..8756682 --- /dev/null +++ b/d04/ex01/ft_recursive_factorial.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_factorial.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 12:29:58 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 14:34:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_factorial(int nb) +{ + if (nb < 0 || nb > 12) + { + return (0); + } + else if (nb >= 1 && nb <= 12) + { + return (nb *= ft_recursive_factorial(nb - 1)); + } + return (1); +} diff --git a/d04/ex02/ft_iterative_power.c b/d04/ex02/ft_iterative_power.c new file mode 100644 index 0000000..7397720 --- /dev/null +++ b/d04/ex02/ft_iterative_power.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_iterative_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 14:35:08 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 14:56:28 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_iterative_power(int nb, int power) +{ + int result; + + if (power < 0) + { + return (0); + } + else if (power == 0) + { + return (1); + } + result = nb; + while (power > 1) + { + result *= nb; + power--; + } + return (result); +} diff --git a/d04/ex03/ft_recursive_power.c b/d04/ex03/ft_recursive_power.c new file mode 100644 index 0000000..ef044e4 --- /dev/null +++ b/d04/ex03/ft_recursive_power.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_recursive_power.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 14:57:08 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 15:46:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_recursive_power(int nb, int power) +{ + if (power < 0) + { + return (0); + } + else if (power == 0) + { + return (1); + } + nb = ft_recursive_power(nb, power - 1) * nb; + return (nb); +} diff --git a/d04/ex04/ft_fibonacci.c b/d04/ex04/ft_fibonacci.c new file mode 100644 index 0000000..2f1ba9a --- /dev/null +++ b/d04/ex04/ft_fibonacci.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_fibonacci.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 15:51:02 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 17:46:07 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_fibonacci(int index) +{ + if (index < 0) + return (-1); + else if (index == 0) + return (0); + else if (index == 1) + return (1); + else + return (ft_fibonacci(index - 1) + ft_fibonacci(index - 2)); +} diff --git a/d04/ex05/ft_sqrt.c b/d04/ex05/ft_sqrt.c new file mode 100644 index 0000000..edd6d65 --- /dev/null +++ b/d04/ex05/ft_sqrt.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sqrt.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 17:56:37 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 21:53:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_sqrt(int numb) +{ + int i; + + i = 0; + while (i * i < nb) + i++; + if (i * i == nb) + return (i); + else + return (0); +} diff --git a/d04/ex06/ft_is_prime.c b/d04/ex06/ft_is_prime.c new file mode 100644 index 0000000..bc84885 --- /dev/null +++ b/d04/ex06/ft_is_prime.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_prime.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/29 20:00:31 by gtertysh #+# #+# */ +/* Updated: 2016/10/29 22:06:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_prime(int nb) +{ + int i; + + i = 2; + if (nb < 0) + return (0); + else if (nb < 3) + return (0); + else + { + while (i < nb / 2) + { + if (nb % i == 0) + return (0); + i++; + } + } + return (1); +} diff --git a/d05/ex00/ft_putstr.c b/d05/ex00/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d05/ex00/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d05/ex01/ft_putnbr.c b/d05/ex01/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/d05/ex01/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/d05/ex02/ft_atoi.c b/d05/ex02/ft_atoi.c new file mode 100644 index 0000000..2e739ad --- /dev/null +++ b/d05/ex02/ft_atoi.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:43:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/d05/ex03/ft_strcpy.c b/d05/ex03/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/d05/ex03/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/d05/ex04/ft_strncpy.c b/d05/ex04/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/d05/ex04/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/d05/ex05/ft_strstr.c b/d05/ex05/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/d05/ex05/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/d05/ex06/ft_strcmp.c b/d05/ex06/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d05/ex06/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d05/ex07/ft_strncmp.c b/d05/ex07/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/d05/ex07/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/d05/ex08/ft_strupcase.c b/d05/ex08/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/d05/ex08/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/d05/ex09/ft_strlowcase.c b/d05/ex09/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/d05/ex09/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/d05/ex10/ft_strcapitalize.c b/d05/ex10/ft_strcapitalize.c new file mode 100644 index 0000000..e4b4f6c --- /dev/null +++ b/d05/ex10/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 16:19:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/d05/ex11/ft_str_is_alpha.c b/d05/ex11/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/d05/ex11/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex12/ft_str_is_numeric.c b/d05/ex12/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/d05/ex12/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex13/ft_str_is_lowercase.c b/d05/ex13/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/d05/ex13/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex14/ft_str_is_uppercase.c b/d05/ex14/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/d05/ex14/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex15/ft_str_is_printable.c b/d05/ex15/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/d05/ex15/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/d05/ex16/ft_strcat.c b/d05/ex16/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/d05/ex16/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/d06/ex00/ft_putchar.c b/d06/ex00/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d06/ex00/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d06/ex00/ft_putstr.c b/d06/ex00/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d06/ex00/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d06/ex00/ft_strcmp.c b/d06/ex00/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d06/ex00/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d06/ex00/ft_strlen.c b/d06/ex00/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d06/ex00/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d06/ex00/ft_swap.c b/d06/ex00/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d06/ex00/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d06/ex00/libft_creator.sh b/d06/ex00/libft_creator.sh new file mode 100755 index 0000000..d7f4c12 --- /dev/null +++ b/d06/ex00/libft_creator.sh @@ -0,0 +1,15 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# libft_creator.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/02 12:08:36 by gtertysh #+# #+# # +# Updated: 2016/11/02 19:05:47 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +gcc -c ./*.c +ar cr libft.a ./*.o +rm ./*.o diff --git a/d06/ex01/ft_print_program_name.c b/d06/ex01/ft_print_program_name.c new file mode 100644 index 0000000..ae8bba3 --- /dev/null +++ b/d06/ex01/ft_print_program_name.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_program_name.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 12:58:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:06:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + argc = -argc; + ft_putstr(argv[0]); + ft_putchar('\n'); + return (0); +} diff --git a/d06/ex02/ft_print_params.c b/d06/ex02/ft_print_params.c new file mode 100644 index 0000000..632651b --- /dev/null +++ b/d06/ex02/ft_print_params.c @@ -0,0 +1,36 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_print_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 15:59:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:07:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + ft_putstr(argv[i]); + ft_putchar('\n'); + i++; + } + return (0); +} diff --git a/d06/ex03/ft_rev_params.c b/d06/ex03/ft_rev_params.c new file mode 100644 index 0000000..184a79b --- /dev/null +++ b/d06/ex03/ft_rev_params.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rev_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 16:16:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:08:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +int main(int argc, char **argv) +{ + while (argc-- > 1) + { + ft_putstr(argv[argc]); + ft_putchar('\n'); + } + return (0); +} diff --git a/d06/ex04/ft_sort_params.c b/d06/ex04/ft_sort_params.c new file mode 100644 index 0000000..901291b --- /dev/null +++ b/d06/ex04/ft_sort_params.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_sort_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 16:33:17 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 19:02:25 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str) + { + ft_putchar(*str); + str++; + } +} + +void print_argv(int argc, char **argv) +{ + int i; + + i = 1; + while (i < argc) + { + ft_putstr(argv[i]); + ft_putchar('\n'); + i++; + } +} + +int cmp(char *s1, char *s2) +{ + while (*s1 && s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (!*s1) + return (0); + return (*s1 - *s2); +} + +int main(int argc, char **argv) +{ + int i; + int j; + char *temp; + + i = 1; + j = 1; + while (i < argc) + { + j = 1; + while (j < argc - 1) + { + if (cmp(argv[j], argv[j + 1]) > 0) + { + temp = argv[j]; + argv[j] = argv[j + 1]; + argv[j + 1] = temp; + } + j++; + } + i++; + } + print_argv(argc, argv); + return (0); +} diff --git a/d07/ex00/ft_strdup.c b/d07/ex00/ft_strdup.c new file mode 100644 index 0000000..0d0e257 --- /dev/null +++ b/d07/ex00/ft_strdup.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strdup.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 20:38:00 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:41:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +char *ft_strdup(char *src) +{ + int size; + int i; + char *new_str; + char *begin; + + begin = src; + size = 0; + while (*src != '\0') + { + src++; + size++; + } + new_str = (char*)malloc(sizeof(*new_str) * (size + 1)); + i = 0; + while (i <= size) + { + new_str[i] = begin[i]; + i++; + } + new_str[i] = '\0'; + return (new_str); +} diff --git a/d07/ex01/ft_range.c b/d07/ex01/ft_range.c new file mode 100644 index 0000000..97bd9d2 --- /dev/null +++ b/d07/ex01/ft_range.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 10:45:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 18:58:22 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *ft_range(int min, int max) +{ + int *array; + int i; + + if (min >= max) + return (0); + array = (int*)malloc(sizeof(int*) * (max - min)); + i = 0; + while (i < max - min) + { + array[i] = min + i; + i++; + } + return (array); +} diff --git a/d07/ex02/ft_ultimate_range.c b/d07/ex02/ft_ultimate_range.c new file mode 100644 index 0000000..4082818 --- /dev/null +++ b/d07/ex02/ft_ultimate_range.c @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_ultimate_range.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 11:21:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 21:53:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_ultimate_range(int **range, int min, int max) +{ + int i; + int *new_array; + + i = 0; + if (min >= max) + { + *range = 0; + return (0); + } + new_array = (int*)malloc(sizeof(int) * (max - min)); + while (i < max - min) + { + new_array[i] = min + i; + i++; + } + *range = new_array; + return (max - min); +} diff --git a/d07/ex03/ft_concat_params.c b/d07/ex03/ft_concat_params.c new file mode 100644 index 0000000..65b4137 --- /dev/null +++ b/d07/ex03/ft_concat_params.c @@ -0,0 +1,71 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_concat_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 15:34:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 19:20:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int count_chars(int argc, char **argv) +{ + int i; + int j; + int chars; + + i = 1; + j = 0; + chars = 0; + while (i < argc) + { + j = 0; + while (argv[i][j]) + { + j++; + chars++; + } + i++; + } + return (chars); +} + +void fill_string(int argc, char **argv, char *concat) +{ + int i; + int j; + int c; + + i = 1; + j = 0; + c = 0; + while (i < argc) + { + j = 0; + while (argv[i][j] != '\0') + { + concat[c] = argv[i][j]; + j++; + c++; + } + concat[c] = '\n'; + c++; + i++; + } + concat[--c] = '\0'; +} + +char *ft_concat_params(int argc, char **argv) +{ + char *concat; + int chars; + + chars = count_chars(argc, argv); + concat = (char*)malloc(sizeof(char) * (chars + argc)); + fill_string(argc, argv, concat); + return (concat); +} diff --git a/d07/ex04/ft_split_whitespaces.c b/d07/ex04/ft_split_whitespaces.c new file mode 100644 index 0000000..45f0deb --- /dev/null +++ b/d07/ex04/ft_split_whitespaces.c @@ -0,0 +1,91 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 12:01:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +char **ft_split_whitespaces(char *str) +{ + char **table; + char *str_begin; + int words; + int word_exist; + int chars_in_word; + int word_position; + int char_position; + + // count words in string + str_begin = str; + words = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + word_exist = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + word_exist = 1; + } + if (word_exist) + words++; + } + + // allocate memory for word pointers + table = (char **)malloc(sizeof(char *) * (words + 1)); + + // count chars in word, allocate memory for current word + // and fill allocated memory + str = str_begin; + word_position = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + chars_in_word = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + chars_in_word++; + } + table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1)); + if (!chars_in_word) + break; + char_position = 0; + while (chars_in_word) + { + table[word_position][char_position] = *(str - chars_in_word); + chars_in_word--; + char_position++; + } + table[word_position][char_position] = '\0'; + word_position++; + } + printf("%d\n", word_position); + table[word_position] = 0; + return (table); +} + +int main(int argc, char **argv) +{ + char **a; + int i; + + i = 0; + //a = ft_split_whitespaces(argv[1]); + a = ft_split_whitespaces("a1 234 "); + while (a[i]) + { + printf("%s\n", a[i++]); + } + return(0); +} diff --git a/d08/ex00/ft_split_whitespaces.c b/d08/ex00/ft_split_whitespaces.c new file mode 100644 index 0000000..b482d1c --- /dev/null +++ b/d08/ex00/ft_split_whitespaces.c @@ -0,0 +1,74 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/06 17:47:48 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +char **ft_split_whitespaces(char *str) +{ + char **table; + char *str_begin; + int words; + int word_exist; + int chars_in_word; + int word_position; + + // count words in string + str_begin = str; + words = 0; + while (*str) + { + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + word_exist = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + word_exist = 1; + } + if (word_exist) + words++; + } + + // allocate memory for word pointers + table = (char **)malloc(sizeof(char *) * (words + 1)); + + // count chars in word, allocate memory for current word + // and fill allocated memory + str = str_begin; + while (*str) + { + word_position = 0; + while (*str == ' ' || *str == '\t' || *str == '\n') + str++; + chars_in_word = 0; + while (*str != ' ' && *str != '\t' && *str != '\n' && *str) + { + str++; + chars_in_word++; + } + table[word_position] = (char *)malloc(sizeof(char) * (chars_in_word + 1)); + while(chars_in_word) + {} + printf("%d\n", chars_in_word); + } + printf("%d\n", words); + return (table); +} + +int main(void) +{ + char **a; + + a = ft_split_whitespaces(" asfa asfa saf af "); + return(0); +} diff --git a/d08/ex00/ft_split_whitespaces_partialy_working.c b/d08/ex00/ft_split_whitespaces_partialy_working.c new file mode 100644 index 0000000..2f5a239 --- /dev/null +++ b/d08/ex00/ft_split_whitespaces_partialy_working.c @@ -0,0 +1,104 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_split_whitespaces.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 12:42:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/06 13:40:45 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include + +void table_mem(char *string, char ***table) +{ + int word_exist; + int words; + + words = 0; + while (*string) + { + while (*string == ' ' || *string == '\t' || *string == '\n') + string++; + word_exist = 0; + while (*string != ' ' && *string != '\t' && *string != '\n' && *string) + { + string++; + word_exist = 1; + } + if (word_exist) + words++; + } + *table = (char **)malloc(sizeof(char *) * (words + 1)); +} + +int word_mem(char **table, int word_index, int char_in_word) +{ + table[word_index] = (char *)malloc(sizeof(char) * (char_in_word + 1)); + if (char_in_word != 0) + { + return (1); + } + else + { + table[word_index] = 0; + return (0); + } +} + +int count_chars(char **begin, char **word_begin) +{ + int char_in_word; + + while (**begin == ' ' || **begin == '\t' || **begin == '\n') + (*begin)++; + char_in_word = 0; + *word_begin = *begin; + while (**begin != ' ' && **begin != '\t' && **begin != '\n' && **begin) + { + (*begin)++; + char_in_word++; + } + return (char_in_word); +} + +char **ft_split_whitespaces(char *str) +{ + char **table; + int char_in_word; + int word_index; + int char_index; + char *word_begin; + + word_index = 0; + char_index = 0; + table_mem(str, &table); + while (*str) + { + char_in_word = count_chars(&str, &word_begin); + word_mem(table, word_index, char_in_word); + char_index = 0; + while (char_in_word--) + { + table[word_index][char_index++] = *word_begin; + word_begin++; + } + table[word_index][char_index] = '\0'; + word_index++; + } + return (table); +} + +int main(void) +{ + char **a; + int i; + + i = 0; + a = ft_split_whitespaces(" asfa asfa saf af "); + printf("%s\n", a[2]); + return(0); +} diff --git a/d08/ex01/ft.h b/d08/ex01/ft.h new file mode 100644 index 0000000..09fcd1e --- /dev/null +++ b/d08/ex01/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/d08/ex02/ft_boolean.h b/d08/ex02/ft_boolean.h new file mode 100644 index 0000000..c3a180d --- /dev/null +++ b/d08/ex02/ft_boolean.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_boolean.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:04:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BOOLEAN_H +# define FT_BOOLEAN_H + +# include +# define TRUE 1 +# define FALSE 0 +# define SUCCESS 0 +# define EVEN_MSG "I have an even number of arguments.\n" +# define ODD_MSG "I have an odd number of arguments.\n" +# define EVEN(x) (!(x % 2)) + +typedef int t_bool; + +#endif diff --git a/d08/ex03/ft_abs.h b/d08/ex03/ft_abs.h new file mode 100644 index 0000000..0b3d697 --- /dev/null +++ b/d08/ex03/ft_abs.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_abs.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:32:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:34:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_ABS_H +# define FT_ABS_H + +# define ABS(Value) ((Value < 0) ? -Value : Value) + +#endif diff --git a/d08/ex04/ft_point.h b/d08/ex04/ft_point.h new file mode 100644 index 0000000..941dc27 --- /dev/null +++ b/d08/ex04/ft_point.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_point.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/05 22:35:46 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 22:38:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_POINT_H +# define FT_POINT_H + +typedef struct s_point +{ + int x; + int y; +} t_point; + +#endif diff --git a/d09/ex00/ft_generic.c b/d09/ex00/ft_generic.c new file mode 100644 index 0000000..4b3ddae --- /dev/null +++ b/d09/ex00/ft_generic.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_generic.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 17:52:10 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:17:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_generic(void) +{ + write(1, "Tu tu tu tu ; Tu tu tu tu\n", 26); +} diff --git a/d09/ex01/ft_takes_place.c b/d09/ex01/ft_takes_place.c new file mode 100644 index 0000000..253e889 --- /dev/null +++ b/d09/ex01/ft_takes_place.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_takes_place.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 19:21:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:01:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_take_place(int hour) +{ + char *a; + + a = "THE FOLLOWING TAKES PLACE BETWEEN "; + if (hour == 0) + printf("%s12.00 A.M. AND 1.00 A.M\n", a); + else if (hour == 23) + printf("%s11.00 P.M. AND 12.00 A.M\n", a); + else if (hour == 11) + printf("%s11.00 A.M. AND 12.00 P.M\n", a); + else if (hour == 12) + printf("%s12.00 P.M. AND 1.00 P.M\n", a); + else if (hour > 12) + printf("%s%d.00 P.M. AND %d.00 P.M\n", a, hour - 12, hour - 12 + 1); + else + printf("%s%d.00 A.M. AND %d.00 A.M\n", a, hour, hour + 1); +} diff --git a/d09/ex02/find_nicolas_bomber.sh b/d09/ex02/find_nicolas_bomber.sh new file mode 100755 index 0000000..75aa511 --- /dev/null +++ b/d09/ex02/find_nicolas_bomber.sh @@ -0,0 +1,13 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# find_nicolas_bomber.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/03 20:27:43 by gtertysh #+# #+# # +# Updated: 2016/11/04 02:01:26 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +cat $1 | grep -i ^nicolas | cut -d $'\t' -f2- | grep -i ^bomber | cut -d$'\t' -f2 | grep [0-9] diff --git a/d09/ex03/defuse.sh b/d09/ex03/defuse.sh new file mode 100755 index 0000000..48dfaab --- /dev/null +++ b/d09/ex03/defuse.sh @@ -0,0 +1,14 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# defuse.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/03 21:41:01 by gtertysh #+# #+# # +# Updated: 2016/11/04 02:01:19 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +LAST_ACCESS_TIME=$(stat -f %a bomb.txt) +echo "$LAST_ACCESS_TIME - 1" | bc diff --git a/d09/ex04/ft_rot42.c b/d09/ex04/ft_rot42.c new file mode 100644 index 0000000..69cecd3 --- /dev/null +++ b/d09/ex04/ft_rot42.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_rot42.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 21:58:10 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 02:01:11 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_rot42(char *str) +{ + char *begin; + + begin = str; + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + *str = (*str - 65 + 42) % 26 + 65; + else if (*str >= 'a' && *str <= 'z') + *str = (*str - 97 + 42) % 26 + 97; + str++; + } + return (begin); +} diff --git a/d09/ex05/ft_button.c b/d09/ex05/ft_button.c new file mode 100644 index 0000000..29d92df --- /dev/null +++ b/d09/ex05/ft_button.c @@ -0,0 +1,39 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_button.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 22:46:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/03 23:15:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_button(int i, int j, int k) +{ + int temp[3]; + int x; + int swap; + + x = 0; + temp[0] = i; + temp[1] = j; + temp[2] = k; + while (x < 3) + { + j = 0; + while (j < 2) + { + if (temp[j] > temp[j + 1]) + { + swap = temp[j]; + temp[j] = temp[j + 1]; + temp[j + 1] = swap; + } + j++; + } + x++; + } + return (temp[1]); +} diff --git a/d09/ex06/ft_destroy.c b/d09/ex06/ft_destroy.c new file mode 100644 index 0000000..ee47bc0 --- /dev/null +++ b/d09/ex06/ft_destroy.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_destroy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/03 23:41:05 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:33 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_ultimator.h" + +void ft_destroy(char ***factory) +{ + while (*factory != 0) + { + while (**factory != 0) + { + free(**factory); + **factory++; + } + free(*factory); + *factory++; + } +} diff --git a/d09/ex07/ft_collatz_conjecture.c b/d09/ex07/ft_collatz_conjecture.c new file mode 100644 index 0000000..3288eab --- /dev/null +++ b/d09/ex07/ft_collatz_conjecture.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_collatz_conjecture.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 01:39:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:26 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_collatz_conjecture(unsigned int base) +{ + static unsigned int i = 0; + + i++; + if (base == 1) + return (i); + else if (base % 2 == 0) + return (ft_collatz_conjecture(base / 2)); + else + return (ft_collatz_conjecture(base * 3 + 1)); +} diff --git a/d09/ex08/ft_spy.c b/d09/ex08/ft_spy.c new file mode 100644 index 0000000..a0d91e9 --- /dev/null +++ b/d09/ex08/ft_spy.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_spy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 01:58:29 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 04:01:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_putstr(char *str) +{ + while (*str) + { + write(1, str, 1); + str++; + } +} + +void low(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'Z') + { + *str += 32; + } + str++; + } +} + +int is_alert(char *str, char *find) +{ + while (*str == ' ' || *str == '\t') + str++; + while (*str && *find && *str == *find) + { + str++; + find++; + } + if (*find == '\0' && (*str == '\0' || *str < 33)) + { + return (1); + } + else + return (0); +} + +void ft_spy(int argc, char **argv) +{ + int i; + int j; + char *a; + char *b; + char *c; + + a = "president"; + b = "attack"; + c = "powers"; + i = 1; + j = 0; + while (i < argc) + { + low(argv[i]); + if (is_alert(argv[i], a) || + is_alert(argv[i], b) || + is_alert(argv[i], c)) + ft_putstr("Alert!!!\n"); + i++; + } +} + +int main(int argc, char **argv) +{ + ft_spy(argc, argv); + return (0); +} diff --git a/d09/ex09/where_am_i.sh b/d09/ex09/where_am_i.sh new file mode 100644 index 0000000..5bcdc33 --- /dev/null +++ b/d09/ex09/where_am_i.sh @@ -0,0 +1,21 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# where_am_i.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/04 03:35:14 by gtertysh #+# #+# # +# Updated: 2016/11/04 04:01:02 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + + +IPS=$(ifconfig | grep "inet " | cut -d " " -f2) + +if [ -z "$IPS" ] +then + echo "Je suis perdu!" +else + echo $IPS | tr " " "\n" +fi diff --git a/d09/ex10/ft_scrambler.c b/d09/ex10/ft_scrambler.c new file mode 100644 index 0000000..80e6f15 --- /dev/null +++ b/d09/ex10/ft_scrambler.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_scrambler.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 04:05:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 17:14:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_scrambler(int ***a, int *b, int *******c, int ****d) +{ + int tempa; + int tempb; + int tempc; + int tempd; + + tempa = ***a; + tempb = *b; + tempc = *******c; + tempd = ****d; + *******c = tempa; + ****d = tempc; + *b = tempd; + ***a = tempb; +} diff --git a/d09/ex11/ft_perso.h b/d09/ex11/ft_perso.h new file mode 100644 index 0000000..8ed7417 --- /dev/null +++ b/d09/ex11/ft_perso.h @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_perso.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 04:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 05:13:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_PERSO_H +# define FT_PERSO_H + +typedef struct s_perso +{ + char *name; + float life; + int age; + char *profession; + +} t_perso; + +#endif diff --git a/d09/ex12/ft_door.c b/d09/ex12/ft_door.c new file mode 100644 index 0000000..522f9f7 --- /dev/null +++ b/d09/ex12/ft_door.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_door.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 05:24:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:11:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_door.h" + +void ft_putstr(char *str) +{ + while (*str) + { + write(1, str, 1); + str++; + } + write(1, "\n", 1); +} + +t_bool close_door(t_door *door) +{ + ft_putstr("Door closing..."); + door->state = CLOSE; + return (TRUE); +} + +t_bool is_door_open(t_door *door) +{ + ft_putstr("Door is open ?"); + if (door->state == OPEN) + return (TRUE); + else + return (FALSE); +} + +t_bool is_door_close(t_door *door) +{ + ft_putstr("Door is close ?"); + if (door->state == CLOSE) + return (TRUE); + else + return (FALSE); +} + +t_bool open_door(t_door *door) +{ + ft_putstr("Door opening..."); + door->state = OPEN; + return (TRUE); +} diff --git a/d09/ex12/ft_door.h b/d09/ex12/ft_door.h new file mode 100644 index 0000000..4ba9955 --- /dev/null +++ b/d09/ex12/ft_door.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_door.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 05:14:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:16:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_DOOR_H +# define FT_DOOR_H +# define EXIT_SUCCESS 0 +# define OPEN 1 +# define CLOSE 0 +# define TRUE 1 +# define FALSE 0 + +typedef int t_bool; + +typedef struct s_door +{ + int state; +} t_door; + +void ft_putstr(char *str); +t_bool close_door(t_door *door); +t_bool is_door_open(t_door *door); +t_bool is_door_close(t_door *door); +t_bool open_door(t_door *door); + +#endif diff --git a/d09/ex12/main.c b/d09/ex12/main.c new file mode 100644 index 0000000..fa46d70 --- /dev/null +++ b/d09/ex12/main.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 06:08:21 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 06:08:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_door.h" + +int main() +{ + t_door door; + open_door(&door); + if (is_door_close(&door)) + open_door(&door); + if (is_door_open(&door)) + close_door(&door); + if (door.state == OPEN) + close_door(&door); + return (EXIT_SUCCESS); +} diff --git a/d09/ex13/ft_compact.c b/d09/ex13/ft_compact.c new file mode 100644 index 0000000..745e145 --- /dev/null +++ b/d09/ex13/ft_compact.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_compact.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 06:46:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 07:21:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_compact(char **tab, int length) +{ + int i; + int j; + + i = 0; + while (i < length) + { + if (tab[i] == 0) + { + while (i + 1 < length) + { + tab[i] = tab[i + 1]; + i++; + } + length--; + tab[i] = 0; + i = -1; + } + i++; + } + return (length); +} diff --git a/d09/ex16/ft_active_bits.c b/d09/ex16/ft_active_bits.c new file mode 100644 index 0000000..dfd6cb2 --- /dev/null +++ b/d09/ex16/ft_active_bits.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_active_bits.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 10:20:14 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 11:40:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +unsigned int ft_active_bits(int value) +{ + unsigned int bits; + + bits = 0; + if (value < 0) + bits++; + value = value & 0x7FFFFFFF; + while (value) + { + bits += value & 1; + value = value >> 1; + } + return (bits); +} diff --git a/d09/ex17/ft_max.c b/d09/ex17/ft_max.c new file mode 100644 index 0000000..c86a714 --- /dev/null +++ b/d09/ex17/ft_max.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 10:45:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 11:04:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_max(int *tab, int length) +{ + int i; + int max; + + i = 1; + if (length == 0) + return (0); + max = tab[0]; + while (i < length) + { + if (tab[i] > max) + max = tab[i]; + i++; + } + return (max); +} diff --git a/d09/ex18/ft_join.c b/d09/ex18/ft_join.c new file mode 100644 index 0000000..f6d5a1e --- /dev/null +++ b/d09/ex18/ft_join.c @@ -0,0 +1,65 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_join.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 11:08:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 13:32:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void fill(char *str, char **tab, char *sep) +{ + int i; + int j; + int c; + + i = 0; + j = 0; + c = 0; + while (tab[i]) + { + j = 0; + while (tab[i][j]) + { + str[c++] = tab[i][j++]; + } + j = 0; + while (sep[j] && tab[i + 1]) + { + str[c++] = sep[j++]; + } + i++; + } + str[c] = '\0'; +} + +char *ft_join(char **tab, char *sep) +{ + int i; + int j; + int chars; + char *str; + + i = 0; + chars = 0; + if (tab[i] == 0) + return (0); + while (tab[i]) + { + j = 0; + while (tab[i][j++]) + chars++; + i++; + } + j = 0; + while (sep[j]) + j++; + str = (char *)malloc(sizeof(char) * (chars + j * (i - 1) + 1)); + fill(str, tab, sep); + return (str); +} diff --git a/d09/ex20/cold_shower.sh b/d09/ex20/cold_shower.sh new file mode 100644 index 0000000..e69de29 diff --git a/d09/ex22/save_donnie.sh b/d09/ex22/save_donnie.sh new file mode 100755 index 0000000..aa9f958 --- /dev/null +++ b/d09/ex22/save_donnie.sh @@ -0,0 +1,13 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# save_donnie.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/04 15:13:54 by gtertysh #+# #+# # +# Updated: 2016/11/04 17:02:14 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +chmod a-w . diff --git a/d09/ex23/ft_generic.c b/d09/ex23/ft_generic.c new file mode 100644 index 0000000..5ce2a1d --- /dev/null +++ b/d09/ex23/ft_generic.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_generic.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/04 15:45:40 by gtertysh #+# #+# */ +/* Updated: 2016/11/04 15:50:27 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +void ft_generic(void) +{ + write(1, "Tu tu tu tu ; Tu tu tu tu\n", 26); +} diff --git a/d10/d10.tar b/d10/d10.tar new file mode 100644 index 0000000000000000000000000000000000000000..9bf2d7240a75c6802f22d8e18c9f406067ca9c5b GIT binary patch literal 8048 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 literal 0 HcmV?d00001 diff --git a/d10/ex00/Makefile b/d10/ex00/Makefile new file mode 100644 index 0000000..7a7d985 --- /dev/null +++ b/d10/ex00/Makefile @@ -0,0 +1,38 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/07 13:45:08 by gtertysh #+# #+# # +# Updated: 2016/11/07 16:09:06 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = libft.a +SRCS = ./srcs +OBJ = ./objs +INC = ./includes +all: $(NAME) + +$(NAME): + @gcc -c ./srcs/ft_putchar.c \ + ./srcs/ft_putstr.c \ + ./srcs/ft_swap.c \ + ./srcs/ft_strlen.c \ + ./srcs/ft_strcmp.c \ + -I $(INC) + @ar cr $(NAME) ./ft_putchar.o \ + ./ft_putstr.o \ + ./ft_strcmp.o \ + ./ft_swap.o \ + ./ft_strlen.o + +clean: + @/bin/rm -f ./*.o + +fclean: clean + @/bin/rm -f $(NAME) + +re: fclean all diff --git a/d10/ex00/includes/ft.h b/d10/ex00/includes/ft.h new file mode 100644 index 0000000..12cf6e7 --- /dev/null +++ b/d10/ex00/includes/ft.h @@ -0,0 +1,2 @@ +void ft_putstr(char *str); +int ft_putchar(char c); diff --git a/d10/ex00/srcs/ft_putchar.c b/d10/ex00/srcs/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d10/ex00/srcs/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d10/ex00/srcs/ft_putstr.c b/d10/ex00/srcs/ft_putstr.c new file mode 100644 index 0000000..35f2c5c --- /dev/null +++ b/d10/ex00/srcs/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 15:03:16 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d10/ex00/srcs/ft_strcmp.c b/d10/ex00/srcs/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/d10/ex00/srcs/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/d10/ex00/srcs/ft_strlen.c b/d10/ex00/srcs/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/d10/ex00/srcs/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/d10/ex00/srcs/ft_swap.c b/d10/ex00/srcs/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/d10/ex00/srcs/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/d10/ex01/ft_foreach.c b/d10/ex01/ft_foreach.c new file mode 100644 index 0000000..1a457e6 --- /dev/null +++ b/d10/ex01/ft_foreach.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:24:51 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 16:51:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_foreach(int *tab, int length, void (*f)(int)) +{ + int i; + + i = 0; + while (i < length) + { + f(tab[i++]); + } +} diff --git a/d10/ex02/ft_map.c b/d10/ex02/ft_map.c new file mode 100644 index 0000000..c191899 --- /dev/null +++ b/d10/ex02/ft_map.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 16:54:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 17:25:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *ft_map(int *tab, int length, int (*f)(int)) +{ + int *arr; + int i; + + i = 0; + arr = (int *)malloc(sizeof(int) * (length)); + while (i < length) + { + arr[i] = f(tab[i]); + i++; + } + return (arr); +} diff --git a/d10/ex03/ft_any.c b/d10/ex03/ft_any.c new file mode 100644 index 0000000..3c8f0d6 --- /dev/null +++ b/d10/ex03/ft_any.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_any.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 17:28:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 18:17:41 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_any(char **tab, int (*f)(char *)) +{ + int i; + + i = 0; + while (tab[i]) + { + if (f(tab[i++])) + return (1); + } + return (0); +} diff --git a/d10/ex04/ft_count_if.c b/d10/ex04/ft_count_if.c new file mode 100644 index 0000000..280b186 --- /dev/null +++ b/d10/ex04/ft_count_if.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_count_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 17:54:32 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 18:17:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_count_if(char **tab, int (*f)(char *)) +{ + int count; + + count = 0; + while(*tab) + { + if(f(*tab)) + { + count++; + (*tab)++; + } + tab++; + } + return (count); +} diff --git a/d10/ex05/ft_is_sort.c b/d10/ex05/ft_is_sort.c new file mode 100644 index 0000000..e6e1147 --- /dev/null +++ b/d10/ex05/ft_is_sort.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_is_sort.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 18:18:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 19:37:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_is_sort(int *tab, int length, int (*f)(int, int)) +{ + int i; + + i = 0; + while (i < length - 1) + { + if (f(tab[i], tab[i + 1]) == -1 || f(tab[i], tab[i + 1]) == 0) + i++; + else + { + i = 0; + while (i < length - 1) + { + if (f(tab[i], tab[i + 1]) == 1 || f(tab[i], tab[i + 1]) == 0) + i++; + else + return (0); + } + } + } + return (1); +} diff --git a/d10/ex06/ft_atoi.c b/d10/ex06/ft_atoi.c new file mode 100644 index 0000000..f8e0b24 --- /dev/null +++ b/d10/ex06/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 20:27:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/d10/ex06/ft_putchar.c b/d10/ex06/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d10/ex06/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d10/ex06/ft_putnbr.c b/d10/ex06/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/d10/ex06/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/d10/ex06/ft_putstr.c b/d10/ex06/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/d10/ex06/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d10/ex06/main.c b/d10/ex06/main.c new file mode 100644 index 0000000..b459d8e --- /dev/null +++ b/d10/ex06/main.c @@ -0,0 +1,83 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 19:46:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 21:41:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str); +void ft_putnbr(int nb); +int ft_putchar(char c); +void ft_putstr(char *str); + +typedef int (*operations)(int, int); + +int add(int a, int b) +{ + return (a + b); +} + +int sub(int a, int b) +{ + return (a - b); +} + +int div(int a, int b) +{ + return (a / b); +} + +int mul(int a, int b) +{ + return (a * b); +} + +int mod(int a, int b) +{ + return (a % b); +} + +int calculator(int a, int b, operations o) +{ + return (o(a, b)); +} + +int main(int argc, char **argv) +{ + operations a[5]; + char *op = "+-/*%"; + int i; + + i = 0; + a[0] = &add; + a[1] = ⊂ + a[2] = ÷ + a[3] = &mul; + a[4] = &mod; + + if (argc != 4) + return (0); + while (i < 5) + { + if (argv[2][0] == op[i] && argv[2][1] == 0) + { + if (argv[2][0] == '/' && ft_atoi(argv[3]) == 0) + ft_putstr("Stop : division by zero"); + else if (argv[2][0] == '%' && ft_atoi(argv[3]) == 0) + ft_putstr("Stop : modulus by zero"); + else + ft_putnbr(calculator(ft_atoi(argv[1]), ft_atoi(argv[3]), a[i])); + ft_putchar('\n'); + break; + } + i++; + if (i == 5) + ft_putstr("0\n"); + } + return (0); +} diff --git a/d10/test/Makefile b/d10/test/Makefile new file mode 100644 index 0000000..d0a460b --- /dev/null +++ b/d10/test/Makefile @@ -0,0 +1,30 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/07 12:38:53 by gtertysh #+# #+# # +# Updated: 2016/11/07 13:10:27 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = prog +SRC = main.c + +all: compile + +compile: + @gcc -o $(NAME) $(SRC) + +clean: + @/bin/rm -f *.o + +fclean: clean + @/bin/rm -f $(NAME) + +re: fclean all + +test: fclean all + @./$(NAME) diff --git a/d10/test/main.c b/d10/test/main.c new file mode 100644 index 0000000..b88dbfa --- /dev/null +++ b/d10/test/main.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/07 12:53:44 by gtertysh #+# #+# */ +/* Updated: 2016/11/07 14:13:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int main(void) +{ + int a; + printf("Hello!"); + return (0); +} diff --git a/d11/ex00/ft_create_elem.c b/d11/ex00/ft_create_elem.c new file mode 100644 index 0000000..3f96364 --- /dev/null +++ b/d11/ex00/ft_create_elem.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_create_elem.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 14:02:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:35:30 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +t_list *ft_create_elem(void *data) +{ + t_list *new; + + new = NULL; + if ((new = malloc(sizeof(t_list)))) + { + new->data = data; + new->next = NULL; + } + return (new); +} diff --git a/d11/ex00/ft_list.h b/d11/ex00/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex00/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex01/ft_list.h b/d11/ex01/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex01/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex01/ft_list_push_back.c b/d11/ex01/ft_list_push_back.c new file mode 100644 index 0000000..c4492d0 --- /dev/null +++ b/d11/ex01/ft_list_push_back.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_back.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:19:18 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:13:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_push_back(t_list **begin_list, void *data) +{ + if (*begin_list == NULL) + (*begin_list) = ft_create_elem(data); + else + { + while ((*begin_list)->next) + begin_list = &(*begin_list)->next; + (*begin_list)->next = ft_create_elem(data); + } +} diff --git a/d11/ex02/ft_list.h b/d11/ex02/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex02/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex02/ft_list_push_front.c b/d11/ex02/ft_list_push_front.c new file mode 100644 index 0000000..9eb73b1 --- /dev/null +++ b/d11/ex02/ft_list_push_front.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_front.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 17:31:25 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 12:05:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_push_front(t_list **begin_list, void *data) +{ + t_list *first; + + first = ft_create_elem(data); + first->next = *begin_list; + *begin_list = first; +} diff --git a/d11/ex03/ft_list.h b/d11/ex03/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex03/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex03/ft_list_size.c b/d11/ex03/ft_list_size.c new file mode 100644 index 0000000..c23551d --- /dev/null +++ b/d11/ex03/ft_list_size.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_size.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 19:16:58 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:31:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +int ft_list_size(t_list *begin_list) +{ + int size; + + size = 0; + while (begin_list) + { + size++; + begin_list = begin_list->next; + } + return (size); +} diff --git a/d11/ex04/ft_list.h b/d11/ex04/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex04/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex04/ft_list_last.c b/d11/ex04/ft_list_last.c new file mode 100644 index 0000000..6e015de --- /dev/null +++ b/d11/ex04/ft_list_last.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_last.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 20:12:36 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 20:44:33 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +t_list *ft_list_last(t_list *begin_list) +{ + while (begin_list && begin_list->next) + { + begin_list = begin_list->next; + } + return (begin_list); +} diff --git a/d11/ex05/ft_list.h b/d11/ex05/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex05/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex05/ft_list_push_params.c b/d11/ex05/ft_list_push_params.c new file mode 100644 index 0000000..4a49a55 --- /dev/null +++ b/d11/ex05/ft_list_push_params.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_push_params.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 21:02:05 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:30:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +t_list *ft_list_push_params(int ac, char **av) +{ + t_list *begin; + t_list *temp; + int i; + + i = 1; + begin = NULL; + temp = NULL; + while (i < ac) + { + temp = ft_create_elem(av[i]); + temp->next = begin; + begin = temp; + i++; + } + return (begin); +} diff --git a/d11/ex06/ft_list.h b/d11/ex06/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex06/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex06/ft_list_clear.c b/d11/ex06/ft_list_clear.c new file mode 100644 index 0000000..e4684f3 --- /dev/null +++ b/d11/ex06/ft_list_clear.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_clear.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 15:09:41 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 15:21:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_clear(t_list **begin_list) +{ + t_list *temp; + + while (*begin_list) + { + temp = (*begin_list)->next; + free(*begin_list); + *begin_list = temp; + } +} diff --git a/d11/ex07/ft_list.h b/d11/ex07/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex07/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex07/ft_list_at.c b/d11/ex07/ft_list_at.c new file mode 100644 index 0000000..f44a20a --- /dev/null +++ b/d11/ex07/ft_list_at.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_at.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 15:31:04 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 16:27:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +t_list *ft_list_at(t_list *begin_list, unsigned int nbr) +{ + unsigned int i; + t_list *temp; + + i = 0; + temp = begin_list; + while (i < nbr && begin_list != NULL) + { + temp = begin_list->next; + begin_list = temp; + i++; + } + return (temp); +} diff --git a/d11/ex08/ft_list.h b/d11/ex08/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex08/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex08/ft_list_reverse.c b/d11/ex08/ft_list_reverse.c new file mode 100644 index 0000000..b0ffaf0 --- /dev/null +++ b/d11/ex08/ft_list_reverse.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_reverse.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 16:28:30 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 17:06:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_list.h" + +void ft_list_reverse(t_list **begin_list) +{ + t_list *prev; + t_list *next; + t_list *curr; + + prev = NULL; + curr = *begin_list; + while (curr) + { + next = curr->next; + curr->next = prev; + prev = curr; + curr = next; + } + *begin_list = prev; +} diff --git a/d11/ex09/ft_list.h b/d11/ex09/ft_list.h new file mode 100644 index 0000000..e1dad71 --- /dev/null +++ b/d11/ex09/ft_list.h @@ -0,0 +1,34 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:18:23 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex09/ft_list_foreach.c b/d11/ex09/ft_list_foreach.c new file mode 100644 index 0000000..b3ff00e --- /dev/null +++ b/d11/ex09/ft_list_foreach.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_foreach.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 17:51:36 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 18:19:44 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_foreach(t_list *begin_list, void (*f)(void *)) +{ + while (begin_list) + { + f(begin_list->data); + begin_list = begin_list->next; + } +} diff --git a/d11/ex10/ft_list.h b/d11/ex10/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11/ex10/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex10/ft_list_foreach_if.c b/d11/ex10/ft_list_foreach_if.c new file mode 100644 index 0000000..ac0b1a8 --- /dev/null +++ b/d11/ex10/ft_list_foreach_if.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_foreach_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 18:46:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:22:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()) +{ + while (begin_list) + { + if ((cmp(begin_list->data, data_ref) == 0)) + f(begin_list->data); + begin_list = begin_list->next; + } +} diff --git a/d11/ex11/ft_list.h b/d11/ex11/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11/ex11/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11/ex11/ft_list_find.c b/d11/ex11/ft_list_find.c new file mode 100644 index 0000000..0928341 --- /dev/null +++ b/d11/ex11/ft_list_find.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_find.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/09 21:18:19 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:46:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +t_list *ft_list_find(t_list *begin_list, void *data_ref, int (*cmp)()) +{ + while (begin_list) + { + if ((cmp(begin_list->data, data_ref) == 0)) + return (begin_list); + begin_list = begin_list->next; + } + return (0); +} diff --git a/d11_test/Makefile b/d11_test/Makefile new file mode 100644 index 0000000..fd87be9 --- /dev/null +++ b/d11_test/Makefile @@ -0,0 +1,26 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/09 11:55:54 by gtertysh #+# #+# # +# Updated: 2016/11/09 18:40:42 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = list +SRC = ../d11/*/*.c +INC = . +FLAGS = -Wall -Wextra + +all: compile + +compile: + @gcc $(FLAGS) main.c ft_list_print.c $(SRC) -I $(INC) -o $(NAME) + +clean: + rm -f $(NAME) + +re: clean compile diff --git a/d11_test/ft_list.h b/d11_test/ft_list.h new file mode 100644 index 0000000..8a53822 --- /dev/null +++ b/d11_test/ft_list.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 15:12:28 by gtertysh #+# #+# */ +/* Updated: 2016/11/09 21:53:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_LIST_H +# define FT_LIST_H + +typedef struct s_list +{ + void *data; + struct s_list *next; +} t_list; + +t_list *ft_create_elem(void *data); +t_list *ft_list_last(t_list *begin_list); +t_list *ft_list_push_params(int ac, char **av); +t_list *ft_list_at(t_list *begin_list, unsigned int nbr); +void ft_list_print(t_list *list); +void ft_list_push_back(t_list **begin_list, void *data); +void ft_list_push_front(t_list **begin_list, void *data); +void ft_list_clear(t_list **begin_list); +void ft_list_reverse(t_list **begin_list); +void ft_list_foreach(t_list *begin_list, void (*f)(void *)); +void ft_list_foreach_if(t_list *begin_list, void (*f)(void *), + void *data_ref, int (*cmp)()); +t_list *ft_list_find(t_list *begin_list, + void *data_ref, int (*cmp)()); +int ft_list_size(t_list *begin_list); + +#endif diff --git a/d11_test/ft_list_print.c b/d11_test/ft_list_print.c new file mode 100644 index 0000000..6497e44 --- /dev/null +++ b/d11_test/ft_list_print.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 17:52:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/08 19:00:56 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" +#include + +void ft_list_print(t_list *list) +{ + while (list) + { + printf("%s\n", list->data); + list = list->next; + } +} diff --git a/d11_test/main.c b/d11_test/main.c new file mode 100644 index 0000000..9e71e17 --- /dev/null +++ b/d11_test/main.c @@ -0,0 +1,92 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/08 18:35:38 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 18:07:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft_list.h" +#include + +void print_data(void *data) +{ + printf("%s\n", data); +} + +void find(void *data) +{ + + printf("find: %s!\n", data); +} + +int main(int argc, char **argv) +{ + t_list *new_list; + + new_list = NULL; + + //push_back + ft_list_push_back(&new_list, "ads"); + ft_list_push_back(&new_list, "addsd"); + + //push_front + ft_list_push_front(&new_list, "a"); + ft_list_push_front(&new_list, "b"); + ft_list_push_front(&new_list, "c"); + ft_list_push_front(&new_list, "d"); + printf("\nFirst list: \n"); + + ////print_list + ft_list_print(new_list); + + //////list_size + printf("Number of elements: %d\n", ft_list_size(new_list)); + + ////list_last + printf("last elemet: %s\n\n", (ft_list_last(new_list))->data); + + //push_params + printf("\nList with program arguments:\n"); + ft_list_print(ft_list_push_params(argc, argv)); + + //clear list + printf("\nFirst list after free: \n"); + ft_list_clear(&new_list); + ft_list_print(new_list); + + //list_at + ft_list_push_back(&new_list, "asd"); + ft_list_push_back(&new_list, "dsa"); + printf("Element of new_list at 0: %s\n", ft_list_at(new_list, 0)->data); + + //reverse_list + ft_list_clear(&new_list); + ft_list_push_back(&new_list, "1"); + ft_list_push_back(&new_list, "2"); + ft_list_push_back(&new_list, "3"); + ft_list_push_back(&new_list, "4"); + printf("new_list before reverse: \n"); + ft_list_print(new_list); + ft_list_reverse(&new_list); + printf("new_list after reverse: \n"); + ft_list_print(new_list); + + //list_foreach + printf("new_list print foreach: \n"); + ft_list_foreach(new_list, print_data); + ft_list_push_front(&new_list, "asd"); + ft_list_push_front(&new_list, "asd"); + ft_list_foreach(new_list, print_data); + + //list_foreach_if + ft_list_foreach_if(new_list, find, "", strcmp); + printf(" find data: %s\n", (ft_list_find(new_list, "4", strcmp)->data)); + return (0); +} diff --git a/d12/ex00/Makefile b/d12/ex00/Makefile new file mode 100644 index 0000000..4c1390a --- /dev/null +++ b/d12/ex00/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/10 16:39:11 by gtertysh #+# #+# # +# Updated: 2016/11/10 18:24:50 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = ft_display_file +SRC = src/ +INC = headers/ +MAIN = main/ +FLAGS = -Wall -Wextra -Werror +LIB = libft.a + + +all: $(NAME) + +lib: + gcc -c $(SRC)*.c -I $(INC) + ar cr $(LIB) *.o + +$(NAME): lib + gcc $(FLAGS) $(MAIN)*.c -L . -lft -I $(INC) -o $(NAME) + +clean: + rm -f *.o + +fclean: clean + rm -f $(LIB) + rm -f $(NAME) + diff --git a/d12/ex00/headers/ft.h b/d12/ex00/headers/ft.h new file mode 100644 index 0000000..59ca30c --- /dev/null +++ b/d12/ex00/headers/ft.h @@ -0,0 +1,40 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 20:23:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +# define BUF_SIZE 10000 + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/d12/ex00/main/display_file.c b/d12/ex00/main/display_file.c new file mode 100644 index 0000000..0789605 --- /dev/null +++ b/d12/ex00/main/display_file.c @@ -0,0 +1,44 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* display_file.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 16:40:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 20:42:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +int main(int argc, char **argv) +{ + int fd; + int readed; + char buf[BUF_SIZE + 1]; + + if (argc < 2) + { + ft_putstr("File name missing.\n"); + return (1); + } + else if (argc > 2) + { + ft_putstr("Too many arguments.\n"); + return (1); + } + fd = open(argv[1], O_RDONLY); + if (fd == -1) + return (1); + while ((readed = read(fd, buf, BUF_SIZE))) + { + buf[readed] = '\0'; + ft_putstr(buf); + } + if ((close(fd) == -1)) + return (1); + return (0); +} diff --git a/d12/ex00/src/ft_putchar.c b/d12/ex00/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d12/ex00/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d12/ex00/src/ft_putstr.c b/d12/ex00/src/ft_putstr.c new file mode 100644 index 0000000..83bf980 --- /dev/null +++ b/d12/ex00/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 18:23:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d12/ex01/Makefile b/d12/ex01/Makefile new file mode 100644 index 0000000..f502e55 --- /dev/null +++ b/d12/ex01/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/10 16:39:11 by gtertysh #+# #+# # +# Updated: 2016/11/10 21:44:18 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = ft_cat +SRC = src/ +INC = headers/ +MAIN = main/ +FLAGS = -Wall -Wextra -Werror +LIB = libft.a + + +all: $(NAME) + +lib: + gcc -c $(SRC)*.c -I $(INC) + ar cr $(LIB) *.o + +$(NAME): lib + gcc $(FLAGS) $(MAIN)*.c -L . -lft -I $(INC) -o $(NAME) + +clean: + rm -f *.o + +fclean: clean + rm -f $(LIB) + rm -f $(NAME) + diff --git a/d12/ex01/headers/ft.h b/d12/ex01/headers/ft.h new file mode 100644 index 0000000..a34b774 --- /dev/null +++ b/d12/ex01/headers/ft.h @@ -0,0 +1,42 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:39:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +# define BUF_SIZE 10 + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); +int print_err(char *argvstr); +void loop(int argc, char **argv, char *buf); + +#endif diff --git a/d12/ex01/main/ft_cat.c b/d12/ex01/main/ft_cat.c new file mode 100644 index 0000000..13c8853 --- /dev/null +++ b/d12/ex01/main/ft_cat.c @@ -0,0 +1,35 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_cat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 18:36:22 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:40:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +int main(int argc, char **argv) +{ + int readed; + char buf[BUF_SIZE + 1]; + + if (argc == 1) + { + while ((readed = read(0, buf, BUF_SIZE))) + { + buf[readed] = '\0'; + ft_putstr(buf); + } + } + else + { + loop(argc, argv, buf); + } + return (0); +} diff --git a/d12/ex01/src/ft_putchar.c b/d12/ex01/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/d12/ex01/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/d12/ex01/src/ft_putstr.c b/d12/ex01/src/ft_putstr.c new file mode 100644 index 0000000..5dab2f3 --- /dev/null +++ b/d12/ex01/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:20:53 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/d12/ex01/src/loop.c b/d12/ex01/src/loop.c new file mode 100644 index 0000000..b9db132 --- /dev/null +++ b/d12/ex01/src/loop.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* loop.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 21:31:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:43:30 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include +#include + +void loop(int argc, char **argv, char *buf) +{ + int i; + int fd; + int readed; + + i = 1; + while (i < argc) + { + if (argv[i][0] == '-' && argv[i][1] == 0) + fd = 0; + else + fd = open(argv[i], O_RDONLY); + print_err(argv[i]); + while ((readed = read(fd, buf, BUF_SIZE)) && fd != -1) + { + if (print_err(argv[i])) + break ; + buf[readed] = '\0'; + ft_putstr(buf); + } + close(fd); + i++; + } +} diff --git a/d12/ex01/src/print_err.c b/d12/ex01/src/print_err.c new file mode 100644 index 0000000..c666345 --- /dev/null +++ b/d12/ex01/src/print_err.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_err.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 21:35:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 21:43:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include + +int print_err(char *argvstr) +{ + if (errno == 2) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": No such file or directory\n"); + } + else if (errno == 13) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": Permission denied\n"); + } + else if (errno == 21) + { + ft_putstr("cat: "); + ft_putstr(argvstr); + ft_putstr(": Is a directory\n"); + return (1); + } + return (0); +} diff --git a/d12_test/open.c b/d12_test/open.c new file mode 100644 index 0000000..c794dc2 --- /dev/null +++ b/d12_test/open.c @@ -0,0 +1,50 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* open.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/10 12:22:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/10 16:37:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "ft.h" + +#define BUF_SIZE 100 + +int main(int argc, char **argv) +{ + int fd; + int ret; + char buffer[BUF_SIZE + 1]; + + if (argc < 2) + { + ft_putstr("File name missing.\n"); + return (1); + } + else if (argc > 2) + { + ft_putstr("Too many arguments.\n"); + return (1); + } + fd = open(argv[1], O_RDONLY); + if (fd == -1) + { + return (1); + } + while((ret = read(fd, buffer, BUF_SIZE))) + { + buffer[ret] = '\0'; + ft_putstr(buffer); + } + if (close(fd) == -1) + { + return (1); + } + return (0); +} diff --git a/d13/ex00/btree_create_node.c b/d13/ex00/btree_create_node.c new file mode 100644 index 0000000..14b0154 --- /dev/null +++ b/d13/ex00/btree_create_node.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_create_node.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:24:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 14:54:08 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +t_btree *btree_create_node(void *item) +{ + t_btree *new_node; + + new_node = NULL; + if ((new_node = malloc(sizeof(t_btree)))) + { + new_node->left = NULL; + new_node->right = NULL; + new_node->item = item; + } + return (new_node); +} diff --git a/d13/ex00/ft_btree.h b/d13/ex00/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex00/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex01/btree_apply_prefix.c b/d13/ex01/btree_apply_prefix.c new file mode 100644 index 0000000..ea24c4d --- /dev/null +++ b/d13/ex01/btree_apply_prefix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_prefix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:50:38 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 19:57:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)) +{ + if (!root) + return ; + applyf(root->item); + btree_apply_prefix(root->left, applyf); + btree_apply_prefix(root->right, applyf); +} diff --git a/d13/ex01/ft_btree.h b/d13/ex01/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex01/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex02/btree_apply_infix.c b/d13/ex02/btree_apply_infix.c new file mode 100644 index 0000000..235e551 --- /dev/null +++ b/d13/ex02/btree_apply_infix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_infix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 13:21:21 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 18:49:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_infix(t_btree *root, void (*applyf)(void *)) +{ + if (!root) + return ; + btree_apply_infix(root->left, applyf); + applyf(root->item); + btree_apply_infix(root->right, applyf); +} diff --git a/d13/ex02/ft_btree.h b/d13/ex02/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex02/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex03/btree_apply_suffix.c b/d13/ex03/btree_apply_suffix.c new file mode 100644 index 0000000..965fb2b --- /dev/null +++ b/d13/ex03/btree_apply_suffix.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_apply_suffix.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 18:59:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:21:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" + +void btree_apply_suffix(t_btree *root, void (*apply)(void *)) +{ + if (!root) + return ; + btree_apply_suffix(root->left, apply); + btree_apply_suffix(root->right, apply); + apply(root->item); +} diff --git a/d13/ex03/ft_btree.h b/d13/ex03/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex03/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex04/btree_insert_data.c b/d13/ex04/btree_insert_data.c new file mode 100644 index 0000000..a22e388 --- /dev/null +++ b/d13/ex04/btree_insert_data.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_insert_data.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 19:17:19 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:21:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "ft_btree.h" + +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)) +{ + if (*root == NULL) + { + *root = btree_create_node(item); + return ; + } + if (cmpf(item, (*root)->item) >= 0) + btree_insert_data(&(*root)->right, item, cmpf); + else if (cmpf(item, (*root)->item) < 0) + btree_insert_data(&(*root)->left, item, cmpf); +} diff --git a/d13/ex04/ft_btree.h b/d13/ex04/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex04/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13/ex05/btree_search_item.c b/d13/ex05/btree_search_item.c new file mode 100644 index 0000000..5741d21 --- /dev/null +++ b/d13/ex05/btree_search_item.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_search_item.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 21:22:08 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:24:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)) +{ + void *ret; + + ret = NULL; + if (!root) + return (0); + { + ret = btree_search_item(root->left, data_ref, cmpf); + if (ret) + return (ret); + if (cmpf(data_ref, root->item) == 0) + return (root->item); + return (btree_search_item(root->right, data_ref, cmpf)); + } +} diff --git a/d13/ex05/ft_btree.h b/d13/ex05/ft_btree.h new file mode 100644 index 0000000..eb9ed73 --- /dev/null +++ b/d13/ex05/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 22:27:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13_test/Makefile b/d13_test/Makefile new file mode 100644 index 0000000..36465f5 --- /dev/null +++ b/d13_test/Makefile @@ -0,0 +1,26 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/09 11:55:54 by gtertysh #+# #+# # +# Updated: 2016/11/11 21:12:34 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = btree +SRC = ../d13/*/*.c +INC = . +FLAGS = -Wall -Werror -Wextra + +all: compile + +compile: + @clang main.c btree_print.c $(SRC) -I $(INC) -o $(NAME) + +clean: + rm -f $(NAME) + +re: clean compile diff --git a/d13_test/btree_print.c b/d13_test/btree_print.c new file mode 100644 index 0000000..7fb05d7 --- /dev/null +++ b/d13_test/btree_print.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* btree_print.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:06:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 12:43:25 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include + +void btree_print(t_btree *tree) +{ + if(!tree) + return ; + printf("%s\n", tree->item); + btree_print(tree->left); + btree_print(tree->right); +} diff --git a/d13_test/ft_btree.h b/d13_test/ft_btree.h new file mode 100644 index 0000000..507f7c9 --- /dev/null +++ b/d13_test/ft_btree.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_btree.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 11:52:39 by gtertysh #+# #+# */ +/* Updated: 2016/11/11 21:45:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_BTREE_H +# define FT_BTREE_H + +typedef struct s_btree +{ + struct s_btree *left; + struct s_btree *right; + void *item; + +} t_btree; + +t_btree *btree_create_node(void *item); +void btree_print(t_btree *tree); +void btree_apply_prefix(t_btree *root, void (*applyf)(void *)); +void btree_apply_infix(t_btree *root, void (*applyf)(void *)); +void btree_apply_suffix(t_btree *root, void (*applyf)(void *)); +void btree_insert_data(t_btree **root, void *item, + int (*cmpf)(void *, void *)); +void *btree_search_item(t_btree *root, void *data_ref, + int (*cmpf)(void *, void *)); +#endif diff --git a/d13_test/main.c b/d13_test/main.c new file mode 100644 index 0000000..dec42c9 --- /dev/null +++ b/d13_test/main.c @@ -0,0 +1,81 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/11 12:24:31 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 14:46:43 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_btree.h" +#include +#include +#include + +void print_item(void *item) +{ + printf("%s\n", (char *)item); +} + +int void_strcmp(void *s1, void *s2) +{ + while (*((char *)s1) && *((char *)s2) && *((char *)s1) == *((char *)s2)) + { + s1++; + s2++; + } + if (*((char *)s1) > *((char *)s2)) + return (*((char *)s1) - *((char *)s2)); + if (*((char *)s1) < *((char *)s2)) + return (*((char *)s1) - *((char *)s2)); + return (0); +} + +int main(void) +{ + t_btree *tree; + t_btree *new_tree; + + tree = NULL; + new_tree = NULL; + + //create nodes + tree = btree_create_node("F"); + tree->left = btree_create_node("B"); + tree->left->left = btree_create_node("A"); + tree->left->right = btree_create_node("D"); + tree->left->right->left = btree_create_node("C"); + tree->left->right->right = btree_create_node("E"); + tree->right = btree_create_node("G"); + tree->right->right = btree_create_node("I"); + tree->right->right->left = btree_create_node("H"); + + //prefix traersal + printf("prefix\n"); + btree_apply_prefix(tree, print_item); + + //infix traversal + printf("infix\n"); + btree_apply_infix(tree, print_item); + + //suffix traversal + printf("suffix\n"); + btree_apply_suffix(tree, print_item); + + //inserting item + btree_insert_data(&new_tree, "1", void_strcmp); + btree_insert_data(&new_tree, "2", void_strcmp); + btree_insert_data(&new_tree, "3", void_strcmp); + btree_insert_data(&new_tree, "4", void_strcmp); + printf("inserting item. prefix output:\n"); + btree_apply_prefix(new_tree, print_item); + + //searching with infix traversal + printf("searching with infix traversal: \n"); + printf("%s\n", btree_search_item(new_tree, "2", void_strcmp)); + + return (0); +} diff --git a/ft_lib/lib/ft.h b/ft_lib/lib/ft.h new file mode 100644 index 0000000..b55a9d2 --- /dev/null +++ b/ft_lib/lib/ft.h @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 12:02:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); diff --git a/ft_lib/lib/libft.a b/ft_lib/lib/libft.a new file mode 100644 index 0000000000000000000000000000000000000000..e14cca65c42ade321ca6482583f598a3c860b9b8 GIT binary patch literal 17348 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 F;lFv diff --git a/ft_lib/libft_creator.sh b/ft_lib/libft_creator.sh new file mode 100755 index 0000000..7d56adf --- /dev/null +++ b/ft_lib/libft_creator.sh @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# libft_creator.sh :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/02 12:08:36 by gtertysh #+# #+# # +# Updated: 2016/11/12 15:04:26 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +ROOT=~/42/ft_lib +SRC=~/42/ft_lib/src +OBJ=~/42/ft_lib/obj +LIB=~/42/ft_lib/lib + +cd $OBJ + +for f in "$SRC"/*.c +do + gcc -c "${f}" +done + +cd $LIB + +for f in "$OBJ"/*.o +do + ar r libft.a "${f}" +done + +for f in "$OBJ"/*.o +do + rm "${f}" +done diff --git a/ft_lib/src/ft_atoi.c b/ft_lib/src/ft_atoi.c new file mode 100644 index 0000000..28b53be --- /dev/null +++ b/ft_lib/src/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:02:46 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/ft_lib/src/ft_putchar.c b/ft_lib/src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/ft_lib/src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/ft_lib/src/ft_putnbr.c b/ft_lib/src/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/ft_lib/src/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/ft_lib/src/ft_putstr.c b/ft_lib/src/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/ft_lib/src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/ft_lib/src/ft_str_is_alpha.c b/ft_lib/src/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/ft_lib/src/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_lowercase.c b/ft_lib/src/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/ft_lib/src/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_numeric.c b/ft_lib/src/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/ft_lib/src/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_printable.c b/ft_lib/src/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/ft_lib/src/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_str_is_uppercase.c b/ft_lib/src/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/ft_lib/src/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/ft_lib/src/ft_strcapitalize.c b/ft_lib/src/ft_strcapitalize.c new file mode 100644 index 0000000..83fbea2 --- /dev/null +++ b/ft_lib/src/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 16:18:12 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/ft_lib/src/ft_strcat.c b/ft_lib/src/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/ft_lib/src/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/ft_lib/src/ft_strcmp.c b/ft_lib/src/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/ft_lib/src/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/ft_lib/src/ft_strcpy.c b/ft_lib/src/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/ft_lib/src/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/ft_lib/src/ft_strlen.c b/ft_lib/src/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/ft_lib/src/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/ft_lib/src/ft_strlowcase.c b/ft_lib/src/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/ft_lib/src/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/ft_lib/src/ft_strncmp.c b/ft_lib/src/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/ft_lib/src/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/ft_lib/src/ft_strncpy.c b/ft_lib/src/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/ft_lib/src/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/ft_lib/src/ft_strstr.c b/ft_lib/src/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/ft_lib/src/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/ft_lib/src/ft_strupcase.c b/ft_lib/src/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/ft_lib/src/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/ft_lib/src/ft_swap.c b/ft_lib/src/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/ft_lib/src/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/ft_lib/test/main.c b/ft_lib/test/main.c new file mode 100644 index 0000000..f8e1da3 --- /dev/null +++ b/ft_lib/test/main.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 13:00:54 by gtertysh #+# #+# */ +/* Updated: 2016/11/05 20:24:06 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../lib/ft.h" + +int main(void) +{ + ft_putstr("Hello\n"); + return (0); +} diff --git a/group_BSQ/Makefile b/group_BSQ/Makefile new file mode 100644 index 0000000..1dddc00 --- /dev/null +++ b/group_BSQ/Makefile @@ -0,0 +1,40 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/16 20:23:31 by gtertysh #+# #+# # +# Updated: 2016/11/16 20:57:41 by ykolomie ### ########.fr # +# # +# **************************************************************************** # + +CC = gcc +FLAGS = -Wall -Wextra -Werror +SRC = ./srcs/main.c \ + ./srcs/read.c \ + ./srcs/bsq.c \ + ./srcs/find_max.c \ + ./srcs/output.c \ + ./srcs/corr_map.c +OBJ = $(SRC:.c=.o) +INC = -I ./includes +NAME = bsq + +all: $(NAME) + +$(NAME): $(OBJ) + $(CC) $(FLAGS) $(INC) $(OBJ) -o $(NAME) + +.c.o: + $(CC) $(FLAGS) $(INC) -c $< -o $@ + +clean: + rm -f $(OBJ) + +fclean: clean + rm -f $(NAME) + +re: fclean all + diff --git a/group_BSQ/auteur b/group_BSQ/auteur new file mode 100644 index 0000000..61f51c1 --- /dev/null +++ b/group_BSQ/auteur @@ -0,0 +1 @@ +ykolomie:gtertysh diff --git a/group_BSQ/includes/bsq.h b/group_BSQ/includes/bsq.h new file mode 100644 index 0000000..fbed142 --- /dev/null +++ b/group_BSQ/includes/bsq.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* bsq.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 19:17:51 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:18:37 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef BSQ_H +# define BSQ_H + +void bsq(char *buf); + +#endif diff --git a/group_BSQ/includes/corr_map.h b/group_BSQ/includes/corr_map.h new file mode 100644 index 0000000..11f20fa --- /dev/null +++ b/group_BSQ/includes/corr_map.h @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* corr_map.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:21:29 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:13:51 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef CORR_MAP_H +# define CORR_MAP_H + +# include "find_max.h" + +void corr_map(char **map, t_coord max, char full); + +#endif diff --git a/group_BSQ/includes/find_max.h b/group_BSQ/includes/find_max.h new file mode 100755 index 0000000..aea6937 --- /dev/null +++ b/group_BSQ/includes/find_max.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_max.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:13:45 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 18:57:41 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FIND_MAX_H +# define FIND_MAX_H + +typedef struct s_coord +{ + int x; + int y; + int size; +} t_coord; + +int *create_matrix(char **buf, int rows, int cols, char empty); +t_coord find_max_square(int *m, int rows, int cols); + +#endif diff --git a/group_BSQ/includes/output.h b/group_BSQ/includes/output.h new file mode 100755 index 0000000..045ea47 --- /dev/null +++ b/group_BSQ/includes/output.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* output.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:42:08 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 18:58:39 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef OUTPUT_H +# define OUTPUT_H + +void ft_putchar(char c); +void ft_putstr(char *str); +void ft_puterror(char *str); +void print_map(char **map); +int ft_strlen(char *str); + +#endif diff --git a/group_BSQ/includes/read.h b/group_BSQ/includes/read.h new file mode 100755 index 0000000..2d41412 --- /dev/null +++ b/group_BSQ/includes/read.h @@ -0,0 +1,21 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:09:31 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:22:47 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef READ_H +# define READ_H + +char *expand_buf(char *buf, unsigned int *size); +char *read_file(int fd); +int ft_atoi(char *str); +char **ft_split_linebreak(char *buf); + +#endif diff --git a/group_BSQ/map_gen.pl b/group_BSQ/map_gen.pl new file mode 100755 index 0000000..a72422f --- /dev/null +++ b/group_BSQ/map_gen.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; + +die "program x y density" unless (scalar(@ARGV) == 3); +my ($x, $y, $density) = @ARGV; +print "$y.ox\n"; +for (my $i = 0; $i < $y; $i++) { + for (my $j = 0; $j < $x; $j++) { + if (int(rand($y) * 2) < $density) { + print "o"; + } + else { + print "."; + } + } + print "\n"; +} diff --git a/group_BSQ/srcs/bsq.c b/group_BSQ/srcs/bsq.c new file mode 100644 index 0000000..eb02656 --- /dev/null +++ b/group_BSQ/srcs/bsq.c @@ -0,0 +1,121 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* init.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:00:48 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 22:00:13 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "corr_map.h" +#include "read.h" +#include "output.h" +#include "find_max.h" + +int check_one(char *str, char *chset) +{ + int len; + + len = 0; + while (str[len] != '\0') + len++; + chset[2] = str[len - 1]; + chset[1] = str[len - 2]; + chset[0] = str[len - 3]; + if (chset[0] == chset[1] || chset[0] == chset[2] || chset[1] == chset[2]) + return (0); + str[len - 3] = '\0'; + return (1); +} + +int check_two(char **start, int *rows, int *cols, char *chset) +{ + int columns_count; + + if ((*cols = ft_strlen(*start)) < 1) + return (0); + *rows = 0; + while (*start) + { + columns_count = 0; + while ((*start)[columns_count] != '\0') + { + if (((*start)[columns_count] != chset[0]) + && ((*start)[columns_count] != chset[1])) + return (0); + columns_count++; + } + if (columns_count != *cols) + return (0); + start++; + (*rows)++; + } + return (1); +} + +char **check(char *buf, int *rows, int *cols, char *chset) +{ + char **table; + int first_line_rows; + + if ((table = ft_split_linebreak(buf))) + { + if (ft_strlen(table[0]) <= 3) + return (0); + if (!(check_one(*table, chset))) + return (0); + if ((first_line_rows = ft_atoi(*table)) < 0) + return (0); + table++; + if (!(*table)) + return (0); + if (!(check_two(table, rows, cols, chset))) + return (0); + if (*rows != first_line_rows) + return (0); + return (table); + } + return (0); +} + +void bsq_work(char **table, int rows, int cols, char *charset) +{ + int *matrix; + t_coord max; + int i; + + matrix = create_matrix(table, rows, cols, charset[0]); + max = find_max_square(matrix, rows, cols); + matrix = 0; + corr_map(table, max, charset[2]); + print_map(table); + i = 0; + --table; + while (table[i]) + { + free(table[i]); + i++; + } + free(table); +} + +void bsq(char *buf) +{ + char **table; + int cols; + int rows; + char charset[3]; + + if ((table = check(buf, &rows, &cols, charset))) + { + bsq_work(table, rows, cols, charset); + table = 0; + } + else + ft_puterror("map error\n"); +} diff --git a/group_BSQ/srcs/corr_map.c b/group_BSQ/srcs/corr_map.c new file mode 100644 index 0000000..38b49f8 --- /dev/null +++ b/group_BSQ/srcs/corr_map.c @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* corr_map.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 16:46:45 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 19:33:45 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "find_max.h" + +char **corr_map(char **map, t_coord max, char full) +{ + int i; + int j; + + i = 0; + while (i < max.size) + { + j = 0; + while (j < max.size) + { + map[max.y - i][max.x - j] = full; + j++; + } + i++; + } + return (map); +} diff --git a/group_BSQ/srcs/find_max.c b/group_BSQ/srcs/find_max.c new file mode 100755 index 0000000..6a67042 --- /dev/null +++ b/group_BSQ/srcs/find_max.c @@ -0,0 +1,96 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_max.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:57:16 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 20:28:27 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "find_max.h" +#include + +int *create_matrix(char **buf, int rows, int cols, char empty) +{ + int *matrix; + int i; + int j; + + matrix = malloc(sizeof(int) * rows * cols); + i = 0; + while (i < rows) + { + j = 0; + while (j < cols) + { + if (buf[i][j] == empty) + matrix[i * cols + j] = 1; + else + matrix[i * cols + j] = 0; + j++; + } + i++; + } + return (matrix); +} + +int min(int a, int b, int c) +{ + if (a <= b && a <= c) + return (a); + if (b <= a && b <= c) + return (b); + if (c <= a && c <= b) + return (c); + return (0); +} + +void find_all_square(int *m, int rows, int cols) +{ + int i; + int j; + + i = 1; + while (i < rows) + { + j = 1; + while (j < cols) + { + if (m[i * cols + j] == 1) + m[i * cols + j] = min(m[(i - 1) * cols + j], + m[i * cols + j - 1], + m[(i - 1) * cols + j - 1]) + 1; + j++; + } + i++; + } +} + +t_coord find_max_square(int *m, int rows, int cols) +{ + int i; + int j; + t_coord max; + + find_all_square(m, rows, cols); + max.x = 0; + max.y = 0; + max.size = m[0]; + i = -1; + while (++i < rows) + { + j = -1; + while (++j < cols) + if (max.size < m[i * cols + j]) + { + max.size = m[i * cols + j]; + max.y = i; + max.x = j; + } + } + free(m); + return (max); +} diff --git a/group_BSQ/srcs/main.c b/group_BSQ/srcs/main.c new file mode 100755 index 0000000..f3ddf08 --- /dev/null +++ b/group_BSQ/srcs/main.c @@ -0,0 +1,45 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 19:14:37 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 22:11:48 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "bsq.h" +#include "output.h" +#include "read.h" +#include +#include + +int main(int argc, char **argv) +{ + int fd; + int i; + char *buf; + + if (argc == 1) + { + buf = read_file(0); + bsq(buf); + } + else + { + i = 0; + while (++i < argc) + { + if ((fd = open(argv[i], O_RDONLY)) == -1) + continue ; + buf = read_file(fd); + bsq(buf); + if (i != argc - 1) + ft_putchar('\n'); + close(fd); + } + } + return (0); +} diff --git a/group_BSQ/srcs/output.c b/group_BSQ/srcs/output.c new file mode 100755 index 0000000..64e9619 --- /dev/null +++ b/group_BSQ/srcs/output.c @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* output.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 17:58:15 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 21:53:11 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "output.h" +#include + +void ft_putchar(char c) +{ + write(1, &c, 1); +} + +void ft_putstr(char *str) +{ + while (*str) + write(1, str++, 1); +} + +void ft_puterror(char *str) +{ + while (*str) + write(2, str++, 1); +} + +void print_map(char **map) +{ + int i; + int j; + + i = 0; + while (map[i]) + { + j = 0; + while (map[i][j] != '\0') + write(1, &map[i][j++], 1); + write(1, "\n", 1); + i++; + } +} + +int ft_strlen(char *str) +{ + int length; + + length = 0; + while (str[length]) + length++; + return (length); +} diff --git a/group_BSQ/srcs/read.c b/group_BSQ/srcs/read.c new file mode 100755 index 0000000..a06707d --- /dev/null +++ b/group_BSQ/srcs/read.c @@ -0,0 +1,113 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* read.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: ykolomie +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/16 18:04:02 by ykolomie #+# #+# */ +/* Updated: 2016/11/16 21:36:05 by ykolomie ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "read.h" +#include +#include + +char *expand_buf(char *buf, unsigned int *size) +{ + char *new_buf; + unsigned int i; + + new_buf = malloc(sizeof(char) * (*size) * 2); + i = 0; + while (i < *size) + { + new_buf[i] = buf[i]; + i++; + } + *size *= 2; + free(buf); + return (new_buf); +} + +char *read_file(int fd) +{ + char *buf; + unsigned int length; + unsigned int buf_size; + int readed; + + length = 0; + buf_size = 16; + buf = malloc(sizeof(char) * buf_size); + while ((readed = read(fd, buf + length, buf_size - length))) + { + length += readed; + if (length == buf_size) + buf = expand_buf(buf, &buf_size); + } + buf[length] = '\0'; + return (buf); +} + +int ft_atoi(char *str) +{ + int result; + + result = 0; + while (*str >= '0' && *str <= '9') + { + result = result * 10 + *str - '0'; + str++; + } + if (*str != '\0') + return (0); + return (result); +} + +char *fill_line(char **str) +{ + char *res; + int length; + int i; + + length = 0; + while (!((*str)[length] == '\n' || (*str)[length] == '\0')) + length++; + res = malloc(sizeof(char) * length + 1); + res[length--] = '\0'; + i = 0; + while (i <= length) + { + res[i++] = **str; + (*str)++; + } + (*str)++; + return (res); +} + +char **ft_split_linebreak(char *buf) +{ + char **res; + int lines; + char *stepbuf; + int i; + char *for_delete; + + lines = 0; + for_delete = buf; + stepbuf = buf; + while (*stepbuf) + if (*stepbuf++ == '\n') + lines++; + if (*(stepbuf - 1) != '\n') + return (0); + res = malloc(sizeof(char*) * lines + 1); + res[lines] = 0; + i = 0; + while (i < lines) + res[i++] = fill_line(&buf); + free(for_delete); + return (res); +} diff --git a/my_bsq/Makefile b/my_bsq/Makefile new file mode 100644 index 0000000..e72f78e --- /dev/null +++ b/my_bsq/Makefile @@ -0,0 +1,35 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/14 16:05:12 by gtertysh #+# #+# # +# Updated: 2016/11/15 16:10:36 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +NAME = bsq +SRC = src/*.c +INC = headers/ +LIBSRC = lib_src/*.c +LIB = libft.a +FLAGS = -Wall -Werror -Wextra + +all: $(LIB) $(NAME) + +$(NAME): + gcc $(FLAGS) $(SRC) -I $(INC) -o $(NAME) -L . -lft + +$(LIB): + gcc -c $(FLAGS) $(LIBSRC) -I $(INC) + ar cr $(LIB) *.o + +clean: + rm -f *.o + +fclean: clean + rm -f $(NAME) $(LIB) + +re: fclean all diff --git a/my_bsq/headers/ft.h b/my_bsq/headers/ft.h new file mode 100644 index 0000000..9dcc726 --- /dev/null +++ b/my_bsq/headers/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:12:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/my_bsq/lib_src/ft_atoi.c b/my_bsq/lib_src/ft_atoi.c new file mode 100644 index 0000000..65189f7 --- /dev/null +++ b/my_bsq/lib_src/ft_atoi.c @@ -0,0 +1,37 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_atoi.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 10:27:11 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 16:20:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_atoi(char *str) +{ + int numb; + int is_negative; + + numb = 0; + is_negative = 0; + while (*str < 33) + str++; + if (*str == '-') + { + is_negative = 1; + str++; + } + if (*str == '+') + str++; + while (*str >= '0' && *str <= '9' && *str != '\0') + { + numb = numb * 10 + *str - '0'; + str++; + } + if (is_negative) + return (-numb); + return (numb); +} diff --git a/my_bsq/lib_src/ft_putchar.c b/my_bsq/lib_src/ft_putchar.c new file mode 100644 index 0000000..0c43d8c --- /dev/null +++ b/my_bsq/lib_src/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 10:53:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/02 10:55:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/my_bsq/lib_src/ft_putnbr.c b/my_bsq/lib_src/ft_putnbr.c new file mode 100644 index 0000000..828964c --- /dev/null +++ b/my_bsq/lib_src/ft_putnbr.c @@ -0,0 +1,58 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putnbr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:45:39 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 21:20:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putnbr_print(int nb, long div, int exeption) +{ + if (nb < 0) + { + nb = -nb; + ft_putchar('-'); + } + if (div == 1) + ft_putchar('0'); + else + { + while (div > 1) + { + div = div / 10; + ft_putchar(nb / div + '0'); + nb = nb % div; + } + } + if (exeption) + ft_putchar('8'); +} + +void ft_putnbr(int nb) +{ + int temp; + long div; + int exeption; + + div = 1; + exeption = 0; + temp = nb; + if (nb == -2147483648) + { + nb = nb / 10; + temp = temp / 10; + exeption = 1; + } + while (temp) + { + temp = temp / 10; + div = div * 10; + } + ft_putnbr_print(nb, div, exeption); +} diff --git a/my_bsq/lib_src/ft_putstr.c b/my_bsq/lib_src/ft_putstr.c new file mode 100644 index 0000000..550f1b9 --- /dev/null +++ b/my_bsq/lib_src/ft_putstr.c @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 09:40:45 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 13:05:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void ft_putstr(char *str) +{ + while (*str != '\0') + { + ft_putchar(*str); + str++; + } +} diff --git a/my_bsq/lib_src/ft_str_is_alpha.c b/my_bsq/lib_src/ft_str_is_alpha.c new file mode 100644 index 0000000..33d8070 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_alpha.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_alpha.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:19:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:31 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_alpha(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!((*str >= 'A' && *str <= 'Z') || (*str >= 'a' && *str <= 'z'))) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_lowercase.c b/my_bsq/lib_src/ft_str_is_lowercase.c new file mode 100644 index 0000000..ce23f58 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_lowercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_lowercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:45:43 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_lowercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'a' && *str <= 'z')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_numeric.c b/my_bsq/lib_src/ft_str_is_numeric.c new file mode 100644 index 0000000..8611a17 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_numeric.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_numeric.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:36:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:14:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_numeric(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= '0' && *str <= '9')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_printable.c b/my_bsq/lib_src/ft_str_is_printable.c new file mode 100644 index 0000000..56db2c3 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_printable.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_printable.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:56:24 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 17:00:42 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_printable(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 32 && *str <= 127)) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_str_is_uppercase.c b/my_bsq/lib_src/ft_str_is_uppercase.c new file mode 100644 index 0000000..67ed9f7 --- /dev/null +++ b/my_bsq/lib_src/ft_str_is_uppercase.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_str_is_uppercase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 16:51:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:15:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_str_is_uppercase(char *str) +{ + if (!*str) + return (1); + while (*str) + { + if (!(*str >= 'A' && *str <= 'Z')) + return (0); + str++; + } + return (1); +} diff --git a/my_bsq/lib_src/ft_strcapitalize.c b/my_bsq/lib_src/ft_strcapitalize.c new file mode 100644 index 0000000..83fbea2 --- /dev/null +++ b/my_bsq/lib_src/ft_strcapitalize.c @@ -0,0 +1,46 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcapitalize.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 13:46:20 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 16:18:12 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void to_lowercase(char *str) +{ + while (*str) + { + if (*str >= 'A' && *str <= 'B') + { + *str += 32; + } + str++; + } +} + +char *ft_strcapitalize(char *str) +{ + char *begin; + + begin = str; + to_lowercase(str); + while (*str) + { + if (*str >= 'a' && *str <= 'z') + { + if (*(str - 1) >= 'z') + *str -= 32; + if (*(str - 1) <= 'A') + *str -= 32; + if (*(str - 1) >= '0' && *(str - 1) <= '9') + *str += 32; + } + str++; + } + *str = '\0'; + return (begin); +} diff --git a/my_bsq/lib_src/ft_strcat.c b/my_bsq/lib_src/ft_strcat.c new file mode 100644 index 0000000..33d7631 --- /dev/null +++ b/my_bsq/lib_src/ft_strcat.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 17:06:09 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:44:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcat(char *dest, char *src) +{ + char *begin; + + begin = dest; + while (*dest) + { + dest++; + } + while (*src) + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (begin); +} diff --git a/my_bsq/lib_src/ft_strcmp.c b/my_bsq/lib_src/ft_strcmp.c new file mode 100644 index 0000000..d444994 --- /dev/null +++ b/my_bsq/lib_src/ft_strcmp.c @@ -0,0 +1,23 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 18:55:03 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:01:13 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strcmp(char *s1, char *s2) +{ + while (*s1 && *s2 && *s1 == *s2) + { + s1++; + s2++; + } + if (*s1 == '\0') + return (0); + return (*s1 - *s2); +} diff --git a/my_bsq/lib_src/ft_strcpy.c b/my_bsq/lib_src/ft_strcpy.c new file mode 100644 index 0000000..9151428 --- /dev/null +++ b/my_bsq/lib_src/ft_strcpy.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strcpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:46:21 by gtertysh #+# #+# */ +/* Updated: 2016/10/31 16:46:57 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strcpy(char *dest, char *src) +{ + char *start; + + start = dest; + while (*src != '\0') + { + *dest = *src; + dest++; + src++; + } + *dest = '\0'; + return (start); +} diff --git a/my_bsq/lib_src/ft_strlen.c b/my_bsq/lib_src/ft_strlen.c new file mode 100644 index 0000000..02c75d7 --- /dev/null +++ b/my_bsq/lib_src/ft_strlen.c @@ -0,0 +1,24 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlen.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 11:13:17 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 11:26:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strlen(char *str) +{ + int count; + + count = 0; + while (*str != '\0') + { + count++; + str++; + } + return (count); +} diff --git a/my_bsq/lib_src/ft_strlowcase.c b/my_bsq/lib_src/ft_strlowcase.c new file mode 100644 index 0000000..b7cc433 --- /dev/null +++ b/my_bsq/lib_src/ft_strlowcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strlowcase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:29:16 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:55 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strlowcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'A' && *counter <= 'Z') + { + *counter += 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/my_bsq/lib_src/ft_strncmp.c b/my_bsq/lib_src/ft_strncmp.c new file mode 100644 index 0000000..7813370 --- /dev/null +++ b/my_bsq/lib_src/ft_strncmp.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncmp.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:04:56 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:05:00 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_strncmp(char *s1, char *s2, unsigned int n) +{ + while (*s1 && *s1 == *s2 && n > 0) + { + s1++; + s2++; + n--; + } + if (n == 0) + return (0); + else + return (*s1 - *s2); + return (0); +} diff --git a/my_bsq/lib_src/ft_strncpy.c b/my_bsq/lib_src/ft_strncpy.c new file mode 100644 index 0000000..2f4ac3c --- /dev/null +++ b/my_bsq/lib_src/ft_strncpy.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strncpy.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 16:59:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strncpy(char *dest, char *src, unsigned int n) +{ + char *start; + unsigned int i; + + start = dest; + i = 0; + while (i < n && *src) + { + *dest = *src; + dest++; + src++; + i++; + } + *dest = '\0'; + return (start); +} diff --git a/my_bsq/lib_src/ft_strstr.c b/my_bsq/lib_src/ft_strstr.c new file mode 100644 index 0000000..4c5bb2e --- /dev/null +++ b/my_bsq/lib_src/ft_strstr.c @@ -0,0 +1,33 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_strstr.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/31 17:47:48 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 20:11:37 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strstr(char *str, char *to_find) +{ + char *start; + char *find; + + find = to_find; + while (*str != '\0') + { + start = str; + find = to_find; + while (*str != '\0' && *find != '\0' && *str == *find) + { + str++; + find++; + } + if (*find == '\0') + return (start); + str++; + } + return (0); +} diff --git a/my_bsq/lib_src/ft_strupcase.c b/my_bsq/lib_src/ft_strupcase.c new file mode 100644 index 0000000..51d8fec --- /dev/null +++ b/my_bsq/lib_src/ft_strupcase.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_struocase.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/01 12:11:35 by gtertysh #+# #+# */ +/* Updated: 2016/11/01 12:50:51 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char *ft_strupcase(char *str) +{ + char *counter; + + counter = str; + while (*counter) + { + if (*counter >= 'a' && *counter <= 'z') + { + *counter -= 32; + } + counter++; + } + *counter = '\0'; + return (str); +} diff --git a/my_bsq/lib_src/ft_swap.c b/my_bsq/lib_src/ft_swap.c new file mode 100644 index 0000000..f59c395 --- /dev/null +++ b/my_bsq/lib_src/ft_swap.c @@ -0,0 +1,20 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_swap.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/28 10:08:34 by gtertysh #+# #+# */ +/* Updated: 2016/10/28 10:14:17 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +void ft_swap(int *a, int *b) +{ + int temp; + + temp = *a; + *a = *b; + *b = temp; +} diff --git a/my_bsq/map_gen.pl b/my_bsq/map_gen.pl new file mode 100755 index 0000000..a72422f --- /dev/null +++ b/my_bsq/map_gen.pl @@ -0,0 +1,18 @@ +#!/usr/bin/perl +use warnings; +use strict; + +die "program x y density" unless (scalar(@ARGV) == 3); +my ($x, $y, $density) = @ARGV; +print "$y.ox\n"; +for (my $i = 0; $i < $y; $i++) { + for (my $j = 0; $j < $x; $j++) { + if (int(rand($y) * 2) < $density) { + print "o"; + } + else { + print "."; + } + } + print "\n"; +} diff --git a/my_bsq/src/main.c b/my_bsq/src/main.c new file mode 100644 index 0000000..56f56d1 --- /dev/null +++ b/my_bsq/src/main.c @@ -0,0 +1,85 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/14 16:17:17 by gtertysh #+# #+# */ +/* Updated: 2016/11/16 13:29:09 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include +#include +#include +#include + +# define BUF_S 131072 + +char *char_realloc(char *old, unsigned int size) +{ + char *new_p; + + new_p = malloc(size); + ft_strcpy(new_p, old); + free(old); + return (new_p); +} + +char *read_in(int type, char *path) +{ + int fd; + int readed; + char buf[BUF_S + 1]; + char *input; + int old_size; + + old_size = 0; + if (type == 3) + { + fd = open(path, O_RDONLY); + if (fd == -1) + return (0); + } + else + fd = 0; + input = malloc(sizeof(char)); + while ((readed = read(fd, buf, BUF_S))) + { + + buf[readed] = '\0'; + old_size = ft_strlen(input); + input = char_realloc(input, old_size + readed + 1); + ft_strcat(input, buf); + } + return (input); +} + +int main(int argc, char **argv) +{ + char *input_string; + int i; + + i = 1; + input_string = 0; + if (argc >= 2) + { + while (i < argc) + { + input_string = read_in(3, argv[i]); + //ft_putstr(input_string); + //free(input_string); + i++; + } + } + else + { + input_string = read_in(0, 0); + //ft_putstr(input_string); + free(input_string); + } + //while(1); + return (0); +} diff --git a/rushes/rush00/ex00/ft_putchar.c b/rushes/rush00/ex00/ft_putchar.c new file mode 100644 index 0000000..2414190 --- /dev/null +++ b/rushes/rush00/ex00/ft_putchar.c @@ -0,0 +1,19 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_putchar.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 14:20:03 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 14:20:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int ft_putchar(char c) +{ + write(1, &c, 1); + return (0); +} diff --git a/rushes/rush00/ex00/main.c b/rushes/rush00/ex00/main.c new file mode 100644 index 0000000..5bd2ed4 --- /dev/null +++ b/rushes/rush00/ex00/main.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 11:13:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:05:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +int ft_putchar(char c); +int ft_atoi(char *str); +void rush(int x, int y); + +int main(int argc, char **argv) +{ + int x; + int y; + + if (argc != 3) + return (0); + x = ft_atoi(argv[1]); + y = ft_atoi(argv[2]); + rush(x, y); + return (0); +} diff --git a/rushes/rush00/ex00/rush00.c b/rushes/rush00/ex00/rush00.c new file mode 100644 index 0000000..197fe1a --- /dev/null +++ b/rushes/rush00/ex00/rush00.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 17:45:41 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('o'); + else if (j == x && i == 1) + ft_putchar('o'); + else if (j == 1 && i == y) + ft_putchar('o'); + else if (j == x && i == y) + ft_putchar('o'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('-'); + else + ft_putchar('|'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush01.c b/rushes/rush00/ex00/rush01.c new file mode 100644 index 0000000..5de961b --- /dev/null +++ b/rushes/rush00/ex00/rush01.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 14:57:40 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('/'); + else if (j == x && i == 1) + ft_putchar('\\'); + else if (j == 1 && i == y) + ft_putchar('\\'); + else if (j == x && i == y) + ft_putchar('/'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('*'); + else + ft_putchar('*'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush02.c b/rushes/rush00/ex00/rush02.c new file mode 100644 index 0000000..0e8273d --- /dev/null +++ b/rushes/rush00/ex00/rush02.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 15:27:54 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('A'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush03.c b/rushes/rush00/ex00/rush03.c new file mode 100644 index 0000000..4fedea1 --- /dev/null +++ b/rushes/rush00/ex00/rush03.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 15:31:24 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('A'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush00/ex00/rush04.c b/rushes/rush00/ex00/rush04.c new file mode 100644 index 0000000..b5325c0 --- /dev/null +++ b/rushes/rush00/ex00/rush04.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/10/30 17:00:05 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int ft_putchar(char c); + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('A'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/Makefile b/rushes/rush02/ex00/Makefile new file mode 100644 index 0000000..d78325d --- /dev/null +++ b/rushes/rush02/ex00/Makefile @@ -0,0 +1,36 @@ +# **************************************************************************** # +# # +# ::: :::::::: # +# Makefile :+: :+: :+: # +# +:+ +:+ +:+ # +# By: gtertysh +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2016/11/12 13:37:10 by gtertysh #+# #+# # +# Updated: 2016/11/13 21:51:43 by gtertysh ### ########.fr # +# # +# **************************************************************************** # + +RUSH2 = rush-2 +RUSH0 = rush-0 +RUSH0SRC = src-rush-00/ +RUSH2SRC = src-rush-02/*.c +INC = headers/ +LIB = lib/ +BIN = bin/ +FLAGS = -Wall -Werror -Wextra + +all: $(RUSH2) $(RUSH0) + +$(RUSH2): + @gcc $(FLAGS) $(RUSH2SRC) -I $(INC) -o $(BIN)$(RUSH2) -L $(LIB) -lft + +$(RUSH0): + @for number in 0 1 2 3 4 ; do \ + gcc $(FLAGS) $(RUSH0SRC)main.c $(RUSH0SRC)rush0$$number.c \ + -I $(INC) -o $(BIN)$(RUSH0)$$number -L $(LIB) -lft ; \ + done + +fclean: + @rm -f $(BIN)* + +re: fclean all diff --git a/rushes/rush02/ex00/bin/rush-00 b/rushes/rush02/ex00/bin/rush-00 new file mode 100755 index 0000000000000000000000000000000000000000..cf081ad05147975e4c7d75b0a857faff18d06ba7 GIT binary patch literal 8600 zcmeHNUuauZ7(chIv()KL6kOHmvf;E^x2B@Fv6ohR_0BE2Kdt|8oTY1KqG=lPhqYs2 zg*1@6ENc;jJr1Ax;6opL5uxpz(76{YOi&Q4p!QyfkcS{q%Hr=kIXAs&>+n^$AAI+m z?>pc5zVH0bx#Zk)^6lS$+_{%ArIoSC7RHzgKHbJxj`>hy>=CdI=KNUyYubC-i8o2x zOiHu3r9^)6FywqtduOoOMD+JG>zI_08@mULlmu~}3XP|vfMTP+x%)5}=zqb0h)A~k z3Pl^66s3G{o=l~OlMU5Ie;)%7^0!S|*s|TBUHY@z>;8B+6pe=xFxu$vs`U4$bU-rU z-k?qSrDNwJu@N4LogIVGMt`46e>6u#Bscl1s~b<62NTTsK>uKWL(K^9rg^aE!!Zv8 zsqLHdSd=FxMu*3uJf2GYt3TTf`Il27f)ZXLo=k!BXz*_SJm^pM?b4oPr$1UJPI-OZ z9zFcV5pCeGz2=fwdZLlxo{@>@2xOwiz?8?p z`L6jdT&j=gV`y1|6tt@Vc`O4wh7H`3w5^D10efP z-B5S+F?&8Skw&_*q?LgXCb2{XW|gUzu}>qUm|B$cOHI}#yM3zBo^#Ishhzk<16fh0 zPpm6SG&|F~s4-J5q$`D?av@MMy?1Igl-cWw5hz*T*J`x|@@*bOK&+hXl44}aGBrap ztxsVgm)rWf5#y=bp)W>aQb8+Goo~Vgt`(6dv@b?Hz~mXz}p~ivE+ez3-x& z3FE=6-x0L_eM0XKk+a026Z>|0Gl}V2m5A!}ZL}Txbq`olqhc$loJF548=OXN-9^Af zz(v4Cz(v4Cz(v4Cz(v4Cz(v4Cz(v4C;D3dHcaP^dCG72^%R_M)&WCZ|jLYle2{ywL z9&aB%mx!c75Qr3x`}j6K8s?$#(3x~9guCt_nLjrgjKr8fkxqu$i)T}u9ij7xRyMZ- zH-U}`MF-jAnKXTre*3%0W5ooHI2GrGAQ@s*ZkWrlnZ zQK>3)a8o~@cv#4|Q^iFnombFlmWs-0d4AC?W&8gCy;7dUX${%GBxN5C%}9O)jFPH? tUdPiZ)42}a4TJiq?!%4uW(+vSEe1sudt6)q!v!$nDZ!AiZo*vz`3E58HN5}; literal 0 HcmV?d00001 diff --git a/rushes/rush02/ex00/bin/rush-01 b/rushes/rush02/ex00/bin/rush-01 new file mode 100755 index 0000000000000000000000000000000000000000..51b23041e762f9ab4dcfb89c1463dc0dbe5d3c80 GIT binary patch literal 8600 zcmeHNO>7%Q6rN2&iPFM4AkhGYZX*hXK;s|~Exjbrg)Ob2X%l{1O_RnY2Ioh%S4|F9 zBRQ75b=^b=q#S`$1RQeU!lg+mQlJ+C0tqA}id4w1WRMRLGAOF~-t4TiPC~^MX`l3V z=Dm6I-kWb`<=Gj3{rB%TZe>iVXKbR5F{Xk~H87TC8fuK)4K~1>AMJWxe_cQJ5@~Bm zsTDVs$WIQ2ocHLj_SBk){-IhOlQME+w}6q7AkI_Kv6K{0toJv!6@!8P7YvAqWUsGK zG_VO#$_MAkl-ZxGs@D5^2Y`^jEz-i1y$+4ipV#jCglSg8R1>(roef;?`Hl&=uh^I(w=0$KUyb#d2QVu zIrQRT{oo;Q&1vh#37Kd{CPRMwd9~ub2$O;4#%@H}Lb4=H6VS0R%0cJ|A8Mb4Ou6pc zh4%?1mLWR|_7h=1>|yF}^Xhxhzh?c)hTBnU;BDY`Gnr_Q$NJj`#^VE!iS7kc9v^)B z(e6hH9z4JKgMqV!&`LRa(P5fe8deO+IA)gD`uL#-Br;B;hw#Suf zx4gb;WWLZ&UYYht#tU2NRm&_}y(?A((MpPX@d-pgfCKufTEMP>Wzs9q-Y>K(2lTR9 zxC8Zh4G;TIHvy*sp+xWO4yZ+stgvb)t0gxr=SK+A^Lo1zWH&49t~;LyAIK%^i|YCl zb`!$xnsd(QZ-b?X{Ian8$)O$EO-3gW&g)`yZXDV^*)5{?56*26=7na9(0u1W!8UsU zdsE)%_k<(GFKM$5)i^97OB9jGW7!XX@nG03vzy`$vN+}PgdKr{`r54jKD6C zE9%s-HARtTXKE)krptMACEr`hM~ZgyjYLs-b=wzh7>cw9U5#Yk)_XeFwb8Z&?GQVY#eHZlu}Vd*93XZWcaJf>#vbo
ZQ6&Ih>0us}~-Ej~exUQcux_wCawj?|q)@T|Tcb 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 literal 0 HcmV?d00001 diff --git a/rushes/rush02/ex00/bin/rush-2 b/rushes/rush02/ex00/bin/rush-2 new file mode 100755 index 0000000000000000000000000000000000000000..7925b2f6596f70da32038e0736a913fe405f8289 GIT binary patch literal 13596 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 IITPK#0p_J?O8@`> literal 0 HcmV?d00001 diff --git a/rushes/rush02/ex00/headers/ft.h b/rushes/rush02/ex00/headers/ft.h new file mode 100644 index 0000000..9dcc726 --- /dev/null +++ b/rushes/rush02/ex00/headers/ft.h @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/02 11:27:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:12:47 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef FT_H +# define FT_H + +int ft_putchar(char c); +void ft_swap(int *a, int *b); +char *ft_strupcase(char *str); +char *ft_strstr(char *str, char *to_find); +char *ft_strncpy(char *dest, char *src, unsigned int n); +int ft_strncmp(char *s1, char *s2, unsigned int n); +char *ft_strlowcase(char *str); +int ft_strlen(char *str); +char *ft_strcpy(char *dest, char *src); +int ft_strcmp(char *s1, char *s2); +char *ft_strcat(char *dest, char *src); +char *ft_strcapitalize(char *str); +void to_lowercase(char *str); +int ft_str_is_uppercase(char *str); +int ft_str_is_printable(char *str); +int ft_str_is_numeric(char *str); +int ft_str_is_lowercase(char *str); +int ft_str_is_alpha(char *str); +void ft_putstr(char *str); +void ft_putnbr(int nb); +int ft_atoi(char *str); + +#endif diff --git a/rushes/rush02/ex00/headers/rush00.h b/rushes/rush02/ex00/headers/rush00.h new file mode 100644 index 0000000..20e76ae --- /dev/null +++ b/rushes/rush02/ex00/headers/rush00.h @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:15:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:16:32 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RUSH00_H +# define RUSH00_H + +void rush(int x, int y); + +#endif diff --git a/rushes/rush02/ex00/headers/rush02.h b/rushes/rush02/ex00/headers/rush02.h new file mode 100644 index 0000000..81d9d04 --- /dev/null +++ b/rushes/rush02/ex00/headers/rush02.h @@ -0,0 +1,32 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:16:44 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:44:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RUSH02_H +# define RUSH02_H + +# define BUF_S 8192 + +typedef char (*t_rush)(int *, int, int); + +char *buf_concat(char *old, char *buf, int readed); +char *input_read(void); +int *det_dimensions(char *str); +char *rush_creator(int *dim, t_rush ch); +int *find_rush(char *str, int *dim); +void print_result(int *dim, int *checked); +char ch_rush00(int *dim, int x, int y); +char ch_rush01(int *dim, int x, int y); +char ch_rush02(int *dim, int x, int y); +char ch_rush03(int *dim, int x, int y); +char ch_rush04(int *dim, int x, int y); + +#endif diff --git a/rushes/rush02/ex00/lib/libft.a b/rushes/rush02/ex00/lib/libft.a new file mode 100644 index 0000000000000000000000000000000000000000..e14cca65c42ade321ca6482583f598a3c860b9b8 GIT binary patch literal 17348 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 F;lFv +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 11:13:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:17:52 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "rush00.h" +#include "ft.h" + +int main(int argc, char **argv) +{ + int x; + int y; + + if (argc != 3) + return (0); + x = ft_atoi(argv[1]); + y = ft_atoi(argv[2]); + rush(x, y); + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush00.c b/rushes/rush02/ex00/src-rush-00/rush00.c new file mode 100644 index 0000000..6782f81 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush00.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush00.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/10/30 12:58:15 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:16:58 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('o'); + else if (j == x && i == 1) + ft_putchar('o'); + else if (j == 1 && i == y) + ft_putchar('o'); + else if (j == x && i == y) + ft_putchar('o'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('-'); + else + ft_putchar('|'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush01.c b/rushes/rush02/ex00/src-rush-00/rush01.c new file mode 100644 index 0000000..1202116 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush01.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush01.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:07 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:18 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('/'); + else if (j == x && i == 1) + ft_putchar('\\'); + else if (j == 1 && i == y) + ft_putchar('\\'); + else if (j == x && i == y) + ft_putchar('/'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('*'); + else + ft_putchar('*'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush02.c b/rushes/rush02/ex00/src-rush-00/rush02.c new file mode 100644 index 0000000..9e6012e --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush02.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush02.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:34 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('A'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush03.c b/rushes/rush02/ex00/src-rush-00/rush03.c new file mode 100644 index 0000000..61e651b --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush03.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush03.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:17:47 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:17:50 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('A'); + else if (j == x && i == y) + ft_putchar('C'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-00/rush04.c b/rushes/rush02/ex00/src-rush-00/rush04.c new file mode 100644 index 0000000..1d2b429 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-00/rush04.c @@ -0,0 +1,56 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush04.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 15:18:02 by gtertysh #+# #+# */ +/* Updated: 2016/11/12 15:18:04 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void rush_print(int x, int y, int i, int j) +{ + if (j > 1 && j < x && i > 1 && i < y) + ft_putchar(' '); + else if (j == 1 && i == 1) + ft_putchar('A'); + else if (j == x && i == 1) + ft_putchar('C'); + else if (j == 1 && i == y) + ft_putchar('C'); + else if (j == x && i == y) + ft_putchar('A'); + else if ((j > 1 && j < x) && (i == 1 || i == y)) + ft_putchar('B'); + else + ft_putchar('B'); +} + +int rush(int x, int y) +{ + int i; + int j; + + i = 1; + j = 1; + if (x < 0 || y < 0) + return (1); + if (x == 0 || y == 0) + return (0); + while (i <= y) + { + while (j <= x) + { + rush_print(x, y, i, j); + j++; + } + ft_putchar('\n'); + i++; + j = 1; + } + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-02/buf_concat.c b/rushes/rush02/ex00/src-rush-02/buf_concat.c new file mode 100644 index 0000000..cc9f4b0 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/buf_concat.c @@ -0,0 +1,28 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* buf_concat.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:19:33 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:24:02 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include + +char *buf_concat(char *old, char *buf, int readed) +{ + char *new_ptr; + int old_size; + + old_size = 0; + new_ptr = NULL; + old_size = ft_strlen(old); + new_ptr = malloc(sizeof(char) * (old_size + readed + 1)); + ft_strcat(new_ptr, old); + ft_strcat(new_ptr, buf); + return (new_ptr); +} diff --git a/rushes/rush02/ex00/src-rush-02/det_dimensions.c b/rushes/rush02/ex00/src-rush-02/det_dimensions.c new file mode 100644 index 0000000..6e24b33 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/det_dimensions.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* det_dimensions.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:29:53 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 21:30:39 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int *det_dimensions(char *str) +{ + int *xy; + int i; + + xy = malloc(sizeof(int) * 2); + xy[0] = 0; + xy[1] = 0; + i = 0; + while (str[i]) + { + while (str[i] != '\n') + { + xy[0]++; + i++; + } + break ; + } + i = 0; + while (str[i]) + { + if (str[i] == '\n') + xy[1]++; + i++; + } + return (xy); +} diff --git a/rushes/rush02/ex00/src-rush-02/find_rush.c b/rushes/rush02/ex00/src-rush-02/find_rush.c new file mode 100644 index 0000000..40249e5 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/find_rush.c @@ -0,0 +1,41 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* find_rush.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:33:01 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:50:10 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" +#include "rush02.h" +#include + +int *find_rush(char *str, int *dim) +{ + t_rush rush_func[5]; + int *checked; + int i; + + i = 0; + rush_func[0] = ch_rush00; + rush_func[1] = ch_rush01; + rush_func[2] = ch_rush02; + rush_func[3] = ch_rush03; + rush_func[4] = ch_rush04; + checked = malloc(sizeof(int) * 5); + while (i < 5) + checked[i++] = 1; + if (dim[0] <= 0 || dim[1] <= 0) + return (checked); + i = 0; + while (i < 5) + { + checked[i] = ft_strcmp(str, rush_creator(dim, rush_func[i])); + i++; + } + return (checked); +} diff --git a/rushes/rush02/ex00/src-rush-02/input_read.c b/rushes/rush02/ex00/src-rush-02/input_read.c new file mode 100644 index 0000000..0ccd179 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/input_read.c @@ -0,0 +1,30 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:10:29 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include +#include "rush02.h" + +char *input_read(void) +{ + char *input; + char buf[BUF_S + 1]; + int readed; + + input = malloc(sizeof(char) * (BUF_S + 1)); + while ((readed = read(0, buf, BUF_S))) + { + buf[readed] = '\0'; + input = buf_concat(input, buf, readed); + } + return (input); +} diff --git a/rushes/rush02/ex00/src-rush-02/main.c b/rushes/rush02/ex00/src-rush-02/main.c new file mode 100644 index 0000000..eca2a94 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/main.c @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 14:32:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "rush02.h" + +int main(void) +{ + char *in_str; + int *dimensions; + int *checked; + + in_str = input_read(); + dimensions = det_dimensions(in_str); + checked = find_rush(in_str, dimensions); + print_result(dimensions, checked); + return (0); +} diff --git a/rushes/rush02/ex00/src-rush-02/print_result.c b/rushes/rush02/ex00/src-rush-02/print_result.c new file mode 100644 index 0000000..79aa793 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/print_result.c @@ -0,0 +1,55 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* print_result.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:34:06 by gtertysh #+# #+# */ +/* Updated: 2016/11/14 15:02:20 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft.h" + +void print(int i, int *dim, int *mult, int *wtf) +{ + ft_putstr("[rush-0"); + ft_putnbr(i); + ft_putstr("] ["); + ft_putnbr(dim[0]); + ft_putstr("] ["); + ft_putnbr(dim[1]); + ft_putstr("]"); + *mult = 1; + *wtf = 0; +} + +void print_result(int *dim, int *checked) +{ + int i; + int mult; + int wtf; + + i = 0; + mult = 0; + wtf = 1; + if (dim[0] <= 0 || dim[1] <= 0) + { + ft_putstr("ALL GLORY TO THE HYPNOTOAD\n"); + return ; + } + while (i < 5) + { + if (checked[i] == 0) + { + if (mult != 0) + ft_putstr(" || "); + print(i, dim, &mult, &wtf); + } + i++; + } + if (wtf) + ft_putstr("ALL GLORY TO THE HYPNOTOAD"); + ft_putstr("\n"); +} diff --git a/rushes/rush02/ex00/src-rush-02/rush_creator.c b/rushes/rush02/ex00/src-rush-02/rush_creator.c new file mode 100644 index 0000000..6c07455 --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/rush_creator.c @@ -0,0 +1,43 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/12 13:45:26 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 22:17:35 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include "rush02.h" + +char *rush_creator(int *dim, t_rush ch) +{ + char *rush; + int x; + int y; + int i; + + rush = malloc(sizeof(char) * (((dim[0] + 1) * dim[1]) + 1)); + x = 0; + y = 0; + i = 0; + if (dim[0] <= 0 || dim[1] <= 0) + return (0); + while (y < dim[1]) + { + x = 0; + while (x < dim[0]) + { + rush[i] = ch(dim, x, y); + i++; + x++; + } + rush[i++] = '\n'; + y++; + } + rush[i] = '\0'; + return (rush); +} diff --git a/rushes/rush02/ex00/src-rush-02/rush_functions.c b/rushes/rush02/ex00/src-rush-02/rush_functions.c new file mode 100644 index 0000000..bdf16fb --- /dev/null +++ b/rushes/rush02/ex00/src-rush-02/rush_functions.c @@ -0,0 +1,101 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rush_functions.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: gtertysh +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2016/11/13 21:08:59 by gtertysh #+# #+# */ +/* Updated: 2016/11/13 22:08:19 by gtertysh ### ########.fr */ +/* */ +/* ************************************************************************** */ + +char ch_rush00(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('o'); + else if (x == dim[0] - 1 && y == 0) + return ('o'); + else if (x == 0 && y == dim[1] - 1) + return ('o'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('o'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('-'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('|'); + else + return (' '); +} + +char ch_rush01(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('/'); + else if (x == dim[0] - 1 && y == 0) + return ('\\'); + else if (x == 0 && y == dim[1] - 1) + return ('\\'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('/'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('*'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('*'); + else + return (' '); +} + +char ch_rush02(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('A'); + else if (x == 0 && y == dim[1] - 1) + return ('C'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('C'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +} + +char ch_rush03(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('C'); + else if (x == 0 && y == dim[1] - 1) + return ('A'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('C'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +} + +char ch_rush04(int *dim, int x, int y) +{ + if (x == 0 && y == 0) + return ('A'); + else if (x == dim[0] - 1 && y == 0) + return ('C'); + else if (x == 0 && y == dim[1] - 1) + return ('C'); + else if (x == dim[0] - 1 && y == dim[1] - 1) + return ('A'); + else if (x > 0 && x < dim[0] - 1 && (y == 0 || y == dim[1] - 1)) + return ('B'); + else if ((x == 0 || x == dim[0] - 1) && (y > 0 && y < dim[1] - 1)) + return ('B'); + else + return (' '); +}