├── 0x14-bit_manipulation ├── 101-password ├── _putchar.c ├── 1-print_binary.c ├── 100-get_endianness.c ├── 2-get_bit.c ├── 0-binary_to_uint.c ├── 3-set_bit.c ├── 4-clear_bit.c ├── main.h ├── 5-flip_bits.c └── README.md ├── 0x1E-search_algorithms ├── 107-O ├── 2-O ├── 3-O ├── 5-O ├── 6-O ├── 101-O ├── 108-O ├── 4-O ├── README.md └── 0-linear.c ├── 0x17-doubly_linked_lists ├── 102-result ├── 100-password ├── 4-free_dlistint.c ├── 6-sum_dlistint.c ├── 1-dlistint_len.c ├── 0-print_dlistint.c ├── 5-get_dnodeint.c ├── 2-add_dnodeint.c ├── README.md └── 3-add_dnodeint_end.c ├── README.md ├── 0x00-hello_world ├── README.md ├── 1-compiler ├── 2-assembler ├── 3-name ├── 0-preprocessor ├── 100-intel ├── q ├── c ├── a.out ├── quote ├── cisfun ├── main.o ├── size32 ├── size64 ├── main.c ├── 4-puts.c ├── 5-printf.c ├── 101-quote.c └── 6-size.c ├── 0x03-debugging ├── README.md ├── 0-main ├── 1-main ├── 2-main ├── 3-main_a ├── 3-main_b ├── 0-main.c ├── main.h ├── positive_or_negative.c ├── 1-main.c ├── 2-main.c ├── 3-main_a.c ├── 3-main_b.c └── 2-largest_number.c ├── 0x08-recursion ├── README.md ├── 4-pow ├── 5-sqrt ├── 6-prime ├── 101-wildcmp ├── 3-factorial ├── 100-palindrome ├── 0-puts_recursion ├── 2-strlen_recursion ├── 1-print_rev_recursion ├── 0-main.c ├── 1-main.c ├── 2-main.c ├── 1-print_rev_recursion.c ├── _putchar.c ├── 0-puts_recursion.c ├── 2-strlen_recursion.c ├── 3-factorial.c ├── main.h ├── 3-main.c ├── 4-pow_recursion.c ├── 100-main.c ├── 5-main.c ├── 4-main.c └── 6-main.c ├── 0x0A-argc_argv ├── README.md ├── add ├── args ├── mul ├── nargs ├── change ├── mynewnameis ├── 0-whatsmyname.c ├── 1-args.c ├── 2-args.c ├── 3-mul.c └── 4-add.c ├── 0x0C-more_malloc_free ├── README.md ├── a ├── 101-mul ├── 2-calloc ├── 100-realloc ├── 3-array_range ├── 1-string_nconcat ├── _putchar.c ├── main.h ├── 1-main.c ├── 0-malloc_checked.c ├── 2-calloc.c ├── 3-array_range.c └── 0-main.c ├── 0x0B-malloc_free ├── README.md ├── a ├── c ├── f ├── g ├── s ├── args ├── strtow ├── main.h ├── 4-free_grid.c ├── 100-main.c ├── 1-main.c ├── 2-main.c └── 0-create_array.c ├── 0x0D-preprocessor ├── README.md ├── 1-pi.h ├── a ├── b ├── c ├── d ├── e ├── 4-sum.h ├── 0-object_like_macro.h ├── 3-function_like_macro.h ├── 2-main.c ├── 4-main.c ├── 0-main.c ├── 1-main.c └── 3-main.c ├── 0x01-variables_if_else_while ├── README.md ├── 1-last_digit ├── 9-print_comb ├── 100-print_comb3 ├── 101-print_comb4 ├── 102-print_comb5 ├── 2-print_alphabet ├── 4-print_alphabt ├── 5-print_numbers ├── 6-print_numberz ├── 7-print_tebahpla ├── 8-print_base16 ├── 3-print_alphabets ├── template.c ├── 5-print_numbers.c ├── 6-print_numberz.c ├── 2-print_alphabet.c ├── 7-print_tebahpla.c ├── 4-print_alphabt.c ├── 8-print_base16.c ├── 0-positive_or_negative.c ├── 9-print_comb.c ├── 3-print_alphabets.c ├── 100-print_comb3.c ├── 101-print_comb4.c ├── 1-last_digit.c └── 102-print_comb5.c ├── 0x07-pointers_arrays_strings ├── 101-crackme_password ├── README.md ├── 0-memset ├── 1-memcpy ├── 2-strchr ├── 3-strspn ├── 5-strstr ├── crackme2 ├── 4-strpbrk ├── 100-set_string ├── 8-print_diagsums ├── 7-print_chessboard ├── 100-set_string.c ├── _putchar.c ├── 4-main.c ├── 5-main.c ├── 7-print_chessboard.c ├── 3-main.c ├── 2-main.c ├── 100-main.c ├── 0-memset.c ├── 1-memcpy.c ├── main.h ├── 2-strchr.c ├── 4-strpbrk.c ├── 8-print_diagsums.c ├── 8-main.c ├── 3-strspn.c └── 7-main.c ├── 0x0E-structures_typedef ├── README.md ├── b ├── c ├── e ├── f ├── 5-free_dog.c ├── 2-main.c ├── 1-main.c ├── 4-main.c ├── 5-main.c ├── 1-init_dog.c ├── 2-print_dog.c └── dog.h ├── 0x0F-function_pointers ├── README.md ├── a ├── b ├── c ├── calc ├── main ├── 0-print_name.c ├── function_pointers.h ├── 1-array_iterator.c ├── 3-calc.h ├── 2-int_index.c ├── 3-get_op_func.c ├── 100-main_opcodes.c └── 3-main.c ├── 0x10-variadic_functions ├── README.md ├── a ├── b ├── c ├── d ├── 2-main.c ├── 3-main.c ├── 1-main.c ├── 0-main.c ├── variadic_functions.h ├── 0-sum_them_all.c ├── 1-print_numbers.c └── 2-print_strings.c ├── 0x12-singly_linked_lists ├── README.md ├── a ├── b ├── c ├── d ├── e ├── 101-hello_holberton.asm ├── 4-free_list.c ├── 100-first.c ├── 1-list_len.c ├── 0-print_list.c ├── 4-main.c └── 3-add_node_end.c ├── 0x02-functions_nested_loops ├── README.md ├── 8-24 ├── 10-add ├── 11-98 ├── 5-sign ├── 6-abs ├── 0-putchar ├── 3-islower ├── 4-isalpha ├── 1-alphabet ├── 101-natural ├── 7-last_digit ├── 102-fibonacci ├── 103-fibonacci ├── 104-fibonacci ├── 2-alphabet_x10 ├── 9-times_table ├── 100-times_table ├── 8-main.c ├── 9-main.c ├── 1-main.c ├── 2-main.c ├── 6-abs.c ├── 10-main.c ├── 10-add.c ├── 1-alphabet.c ├── 11-main.c ├── _putchar.c ├── 3-islower.c ├── 0-putchar.c ├── 7-main.c ├── 4-isalpha.c ├── 100-main.c ├── main.h ├── 3-main.c ├── 103-fibonacci.c ├── 101-natural.c ├── 2-print_alphabet_x10.c ├── 6-main.c ├── 4-main.c ├── 5-sign.c ├── 102-fibonacci.c ├── 7-print_last_digit.c ├── 11-print_to_98.c ├── 9-times_table.c └── 5-main.c ├── 0x05-pointers_arrays_strings ├── README.md ├── 0-98 ├── 1-swap ├── 3-puts ├── 100-atoi ├── 2-strlen ├── 6-puts2 ├── 9-strcpy ├── 101-keygen ├── 4-print_rev ├── 7-puts_half ├── 5-rev_string ├── 8-print_array ├── 6-main.c ├── 7-main.c ├── 0-reset_to_98.c ├── 1-swap.c ├── 3-main.c ├── 2-strlen.c ├── 3-puts.c ├── 4-main.c ├── 5-main.c ├── _putchar.c ├── 0-main.c ├── 2-main.c ├── 8-main.c ├── 1-main.c ├── 9-main.c ├── main.h ├── 4-print_rev.c ├── 8-print_array.c ├── 6-puts2.c ├── 5-rev_string.c ├── 101-keygen.c ├── 7-puts_half.c └── 9-strcpy.c ├── 0x06-pointers_arrays_strings ├── README.md ├── 6-cap ├── 7-1337 ├── test ├── 0-strcat ├── 103-add ├── 3-strcmp ├── 1-strncat ├── 100-rot13 ├── 102-magic ├── 104-buffer ├── 2-strncpy ├── 4-rev_array ├── 5-string_toupper ├── 101-print_numbers ├── _putchar.c ├── 5-main.c ├── 3-main.c ├── 4-rev_array.c ├── 7-main.c ├── 5-string_toupper.c ├── 0-main.c ├── 3-strcmp.c ├── 7-leet.c ├── 101-main.c ├── 2-strncpy.c ├── 6-main.c ├── main.h ├── 104-main.c ├── 102-magic.c ├── 0-strcat.c ├── 1-strncat.c ├── 101-print_number.c ├── 1-main.c ├── 100-rot13.c └── 102-magic-test.c ├── 0x09-static_libraries ├── README.md ├── create_static_lib.sh ├── 3-puts.o ├── 6-abs.o ├── liball.a ├── libmy.a ├── 0-memset.o ├── 0-strcat.o ├── 1-memcpy.o ├── 100-atoi.o ├── 2-strchr.o ├── 2-strlen.o ├── 3-strcmp.o ├── 3-strspn.o ├── 5-strstr.o ├── 9-strcpy.o ├── _putchar.o ├── 0-isupper.o ├── 1-isdigit.o ├── 1-strncat.o ├── 2-strncpy.o ├── 3-islower.o ├── 4-isalpha.o ├── 4-strpbrk.o └── sources │ ├── 6-abs.c │ ├── 2-strlen.c │ ├── 3-puts.c │ ├── 0-isupper.c │ ├── 1-isdigit.c │ ├── _putchar.c │ ├── 3-islower.c │ ├── 4-isalpha.c │ ├── 0-memset.c │ ├── 1-memcpy.c │ ├── 3-strcmp.c │ ├── 2-strncpy.c │ ├── 9-strcpy.c │ ├── 2-strchr.c │ ├── 0-strcat.c │ ├── 1-strncat.c │ ├── 4-strpbrk.c │ └── 3-strspn.c ├── 0x04-more_functions_nested_loops ├── README.md ├── 2-mul ├── 6-lines ├── 0-isuper ├── 1-isdigit ├── 8-squares ├── 10-triangles ├── 7-diagonals ├── 9-fizz_buzz ├── 5-more_numbers ├── 100-prime_factor ├── 101-print_numbers ├── 3-print_numbers ├── 4-print_most_numbers ├── 5-main.c ├── 3-main.c ├── 4-main.c ├── 8-main.c ├── 2-mul.c ├── 6-main.c ├── 2-main.c ├── 10-main.c ├── 3-print_numbers.c ├── 7-main.c ├── 0-isupper.c ├── 1-isdigit.c ├── _putchar.c ├── 0-main.c ├── 1-main.c ├── 6-print_line.c ├── 4-print_most_numbers.c ├── main.h ├── 100-prime_factor.c ├── 5-more_numbers.c ├── 101-main.c ├── 8-print_square.c ├── 9-fizz_buzz.c ├── 7-print_diagonal.c ├── 101-print_number.c └── 10-print_triangle.c ├── 0x1C-makefiles ├── 0-Makefile ├── 1-Makefile ├── main.o ├── school ├── school.o ├── 2-Makefile ├── m.h ├── main.c ├── 3-Makefile ├── 4-Makefile ├── 100-Makefile ├── 5-main.py └── README.md ├── 0x18-dynamic_libraries ├── 1-create_dynamic_lib.sh ├── libdynamic.so ├── 100-operations.so ├── tmp │ ├── 100-operations.o │ ├── _putchar.c │ ├── 3-puts.c │ ├── 6-abs.c │ ├── 1-isdigit.c │ ├── 3-islower.c │ ├── 2-strlen.c │ ├── 0-isupper.c │ ├── 4-isalpha.c │ ├── 0-memset.c │ ├── 9-strcpy.c │ ├── 1-memcpy.c │ ├── 100-tests.py │ ├── 3-strcmp.c │ ├── 2-strncpy.c │ ├── 2-strchr.c │ ├── 3-strspn.c │ ├── 100-atoi.c │ ├── 0-strcat.c │ ├── 4-strpbrk.c │ └── 1-strncat.c ├── 101-make_me_win.sh └── README.md ├── 0x15-file_io ├── _putchar.c ├── README.md └── main.h ├── 0x13-more_singly_linked_lists ├── 4-free_listint.c ├── 8-sum_listint.c ├── 1-listint_len.c ├── 5-free_listint2.c ├── 0-print_listint.c ├── 6-pop_listint.c ├── 7-get_nodeint.c ├── 2-add_nodeint.c ├── 100-reverse_listint.c └── 3-add_nodeint_end.c └── 0x1A-hash_tables ├── 2-key_index.c ├── 1-djb2.c ├── README.md ├── 4-hash_table_get.c ├── 0-hash_table_create.c └── 6-hash_table_delete.c /0x14-bit_manipulation/101-password: -------------------------------------------------------------------------------- 1 | Hol -------------------------------------------------------------------------------- /0x1E-search_algorithms/107-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/2-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/3-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/5-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/6-O: -------------------------------------------------------------------------------- 1 | O(nm) 2 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/102-result: -------------------------------------------------------------------------------- 1 | 906609 -------------------------------------------------------------------------------- /0x1E-search_algorithms/101-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/108-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/4-O: -------------------------------------------------------------------------------- 1 | O(log(n)) 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # alx-low_level_programming 2 | -------------------------------------------------------------------------------- /0x00-hello_world/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | -------------------------------------------------------------------------------- /0x03-debugging/README.md: -------------------------------------------------------------------------------- 1 | # 0x03-debugging 2 | -------------------------------------------------------------------------------- /0x08-recursion/README.md: -------------------------------------------------------------------------------- 1 | # 0x08-recursion 2 | -------------------------------------------------------------------------------- /0x0A-argc_argv/README.md: -------------------------------------------------------------------------------- 1 | # 0x0A-argc_argv 2 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/README.md: -------------------------------------------------------------------------------- 1 | # README 2 | -------------------------------------------------------------------------------- /0x0B-malloc_free/README.md: -------------------------------------------------------------------------------- 1 | # 0x0B-malloc_free 2 | -------------------------------------------------------------------------------- /0x0D-preprocessor/README.md: -------------------------------------------------------------------------------- 1 | # 0x0D-preprocessor 2 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/100-password: -------------------------------------------------------------------------------- 1 | en C Pyfo neZ -------------------------------------------------------------------------------- /0x01-variables_if_else_while/README.md: -------------------------------------------------------------------------------- 1 | # Description 2 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/101-crackme_password: -------------------------------------------------------------------------------- 1 | abc123 -------------------------------------------------------------------------------- /0x00-hello_world/1-compiler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/2-assembler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S $CFILE 3 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/README.md: -------------------------------------------------------------------------------- 1 | # 0x0E-structures_typedef 2 | -------------------------------------------------------------------------------- /0x0F-function_pointers/README.md: -------------------------------------------------------------------------------- 1 | # 0x0F-function_pointers 2 | -------------------------------------------------------------------------------- /0x10-variadic_functions/README.md: -------------------------------------------------------------------------------- 1 | # 0x10-variadic_functions 2 | -------------------------------------------------------------------------------- /0x00-hello_world/3-name: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc $CFILE -o cisfun 3 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/README.md: -------------------------------------------------------------------------------- 1 | # 0x12-singly_linked_lists 2 | -------------------------------------------------------------------------------- /0x00-hello_world/0-preprocessor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc $CFILE -E -o c 3 | -------------------------------------------------------------------------------- /0x00-hello_world/100-intel: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S $CFILE -masm=intel 3 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # 0x02-functions_nested_loops 2 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | # 0x05-pointers_arrays_strings 2 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | # 0x06-pointers_arrays_strings 2 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | # 0x07-pointers_arrays_strings 2 | -------------------------------------------------------------------------------- /0x09-static_libraries/README.md: -------------------------------------------------------------------------------- 1 | # Static Libraries in C programming 2 | 3 | -------------------------------------------------------------------------------- /0x00-hello_world/q: -------------------------------------------------------------------------------- 1 | and that piece of art is useful - Dora Korpar, 2015-10-19 2 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # 0x04-more_functions_nested_loops 2 | -------------------------------------------------------------------------------- /0x0D-preprocessor/1-pi.h: -------------------------------------------------------------------------------- 1 | #ifndef PI 2 | #define PI 3.14159265359 3 | #endif 4 | -------------------------------------------------------------------------------- /0x1C-makefiles/0-Makefile: -------------------------------------------------------------------------------- 1 | all: main.c school.c 2 | gcc main.c school.c -o school 3 | -------------------------------------------------------------------------------- /0x1C-makefiles/1-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | 4 | all: 5 | $(CC) $(SRC) -o school 6 | -------------------------------------------------------------------------------- /0x09-static_libraries/create_static_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | gcc -c *.c 4 | 5 | ar -rc liball.a *.o 6 | 7 | -------------------------------------------------------------------------------- /0x00-hello_world/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/c -------------------------------------------------------------------------------- /0x08-recursion/4-pow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/4-pow -------------------------------------------------------------------------------- /0x0A-argc_argv/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/add -------------------------------------------------------------------------------- /0x0A-argc_argv/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/args -------------------------------------------------------------------------------- /0x0A-argc_argv/mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/mul -------------------------------------------------------------------------------- /0x0A-argc_argv/nargs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/nargs -------------------------------------------------------------------------------- /0x0B-malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/a -------------------------------------------------------------------------------- /0x0B-malloc_free/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/c -------------------------------------------------------------------------------- /0x0B-malloc_free/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/f -------------------------------------------------------------------------------- /0x0B-malloc_free/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/g -------------------------------------------------------------------------------- /0x0B-malloc_free/s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/s -------------------------------------------------------------------------------- /0x0D-preprocessor/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0D-preprocessor/a -------------------------------------------------------------------------------- /0x0D-preprocessor/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0D-preprocessor/b -------------------------------------------------------------------------------- /0x0D-preprocessor/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0D-preprocessor/c -------------------------------------------------------------------------------- /0x0D-preprocessor/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0D-preprocessor/d -------------------------------------------------------------------------------- /0x0D-preprocessor/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0D-preprocessor/e -------------------------------------------------------------------------------- /0x00-hello_world/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/a.out -------------------------------------------------------------------------------- /0x00-hello_world/quote: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/quote -------------------------------------------------------------------------------- /0x03-debugging/0-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x03-debugging/0-main -------------------------------------------------------------------------------- /0x03-debugging/1-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x03-debugging/1-main -------------------------------------------------------------------------------- /0x03-debugging/2-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x03-debugging/2-main -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/5-sqrt -------------------------------------------------------------------------------- /0x08-recursion/6-prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/6-prime -------------------------------------------------------------------------------- /0x0A-argc_argv/change: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/change -------------------------------------------------------------------------------- /0x0B-malloc_free/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/args -------------------------------------------------------------------------------- /0x1C-makefiles/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x1C-makefiles/main.o -------------------------------------------------------------------------------- /0x1C-makefiles/school: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x1C-makefiles/school -------------------------------------------------------------------------------- /0x00-hello_world/cisfun: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/cisfun -------------------------------------------------------------------------------- /0x00-hello_world/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/main.o -------------------------------------------------------------------------------- /0x00-hello_world/size32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/size32 -------------------------------------------------------------------------------- /0x00-hello_world/size64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x00-hello_world/size64 -------------------------------------------------------------------------------- /0x03-debugging/3-main_a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x03-debugging/3-main_a -------------------------------------------------------------------------------- /0x03-debugging/3-main_b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x03-debugging/3-main_b -------------------------------------------------------------------------------- /0x0B-malloc_free/strtow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0B-malloc_free/strtow -------------------------------------------------------------------------------- /0x0C-more_malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/a -------------------------------------------------------------------------------- /0x0D-preprocessor/4-sum.h: -------------------------------------------------------------------------------- 1 | #ifndef FOUR_SUM_H 2 | #define FOUR_SUM_H 3 | 4 | #define SUM(x, y) ((x) + (y)) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0E-structures_typedef/b -------------------------------------------------------------------------------- /0x0E-structures_typedef/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0E-structures_typedef/c -------------------------------------------------------------------------------- /0x0E-structures_typedef/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0E-structures_typedef/e -------------------------------------------------------------------------------- /0x0E-structures_typedef/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0E-structures_typedef/f -------------------------------------------------------------------------------- /0x0F-function_pointers/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0F-function_pointers/a -------------------------------------------------------------------------------- /0x0F-function_pointers/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0F-function_pointers/b -------------------------------------------------------------------------------- /0x0F-function_pointers/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0F-function_pointers/c -------------------------------------------------------------------------------- /0x10-variadic_functions/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x10-variadic_functions/a -------------------------------------------------------------------------------- /0x10-variadic_functions/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x10-variadic_functions/b -------------------------------------------------------------------------------- /0x10-variadic_functions/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x10-variadic_functions/c -------------------------------------------------------------------------------- /0x10-variadic_functions/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x10-variadic_functions/d -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-create_dynamic_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c -fPIC *.c 3 | gcc -shared -o liball.so *.o 4 | rm *.o 5 | -------------------------------------------------------------------------------- /0x1C-makefiles/school.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x1C-makefiles/school.o -------------------------------------------------------------------------------- /0x08-recursion/101-wildcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/101-wildcmp -------------------------------------------------------------------------------- /0x08-recursion/3-factorial: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/3-factorial -------------------------------------------------------------------------------- /0x0A-argc_argv/mynewnameis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0A-argc_argv/mynewnameis -------------------------------------------------------------------------------- /0x0F-function_pointers/calc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0F-function_pointers/calc -------------------------------------------------------------------------------- /0x0F-function_pointers/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0F-function_pointers/main -------------------------------------------------------------------------------- /0x12-singly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x12-singly_linked_lists/a -------------------------------------------------------------------------------- /0x12-singly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x12-singly_linked_lists/b -------------------------------------------------------------------------------- /0x12-singly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x12-singly_linked_lists/c -------------------------------------------------------------------------------- /0x12-singly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x12-singly_linked_lists/d -------------------------------------------------------------------------------- /0x12-singly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x12-singly_linked_lists/e -------------------------------------------------------------------------------- /0x1E-search_algorithms/README.md: -------------------------------------------------------------------------------- 1 | ```diff 2 | 3 | + Done with this project. 4 | - By Author: Afolabi John Oluwaseun 5 | 6 | ``` 7 | -------------------------------------------------------------------------------- /0x08-recursion/100-palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/100-palindrome -------------------------------------------------------------------------------- /0x09-static_libraries/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/3-puts.o -------------------------------------------------------------------------------- /0x09-static_libraries/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/6-abs.o -------------------------------------------------------------------------------- /0x09-static_libraries/liball.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/liball.a -------------------------------------------------------------------------------- /0x09-static_libraries/libmy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/libmy.a -------------------------------------------------------------------------------- /0x0C-more_malloc_free/101-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/101-mul -------------------------------------------------------------------------------- /0x0C-more_malloc_free/2-calloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/2-calloc -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/8-24 -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/0-puts_recursion -------------------------------------------------------------------------------- /0x09-static_libraries/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/0-memset.o -------------------------------------------------------------------------------- /0x09-static_libraries/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/1-memcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/2-strchr.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/3-strspn.o -------------------------------------------------------------------------------- /0x09-static_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/5-strstr.o -------------------------------------------------------------------------------- /0x09-static_libraries/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/_putchar.o -------------------------------------------------------------------------------- /0x0D-preprocessor/0-object_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_LIKE_MACRO 2 | #define OBJECT_LIKE_MACRO 3 | 4 | #define SIZE 1024 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/10-add -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/11-98 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/5-sign -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/6-abs -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/0-98 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/1-swap -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/3-puts -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/6-cap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/6-cap -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-1337: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/7-1337 -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/test: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/test -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/2-strlen_recursion -------------------------------------------------------------------------------- /0x09-static_libraries/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/0-isupper.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/1-isdigit.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/1-strncat.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/2-strncpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/3-islower.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x09-static_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x0C-more_malloc_free/100-realloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/100-realloc -------------------------------------------------------------------------------- /0x0C-more_malloc_free/3-array_range: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/3-array_range -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-putchar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/0-putchar -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/3-islower -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/4-isalpha -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/100-atoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/100-atoi -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/2-strlen -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/6-puts2 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/9-strcpy -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/0-strcat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/103-add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/103-add -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/3-strcmp -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/0-memset -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/1-memcpy -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/2-strchr -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-strspn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/3-strspn -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-strstr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/5-strstr -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/crackme2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/crackme2 -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x08-recursion/1-print_rev_recursion -------------------------------------------------------------------------------- /0x18-dynamic_libraries/libdynamic.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x18-dynamic_libraries/libdynamic.so -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/1-alphabet -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/101-natural -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/7-last_digit -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/2-mul -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-lines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/6-lines -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/101-keygen -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/4-print_rev -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/7-puts_half -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-strncat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/1-strncat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/100-rot13: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/100-rot13 -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/102-magic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/102-magic -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/104-buffer: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/104-buffer -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/2-strncpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/2-strncpy -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/4-rev_array -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-strpbrk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/4-strpbrk -------------------------------------------------------------------------------- /0x0C-more_malloc_free/1-string_nconcat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x0C-more_malloc_free/1-string_nconcat -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x18-dynamic_libraries/100-operations.so -------------------------------------------------------------------------------- /0x1C-makefiles/2-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | 6 | all: $(OBJ) 7 | $(CC) $(OBJ) -o $(NAME) 8 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/1-last_digit -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/9-print_comb -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/102-fibonacci -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/103-fibonacci -------------------------------------------------------------------------------- /0x02-functions_nested_loops/104-fibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/104-fibonacci -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-alphabet_x10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/2-alphabet_x10 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/9-times_table -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isuper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/0-isuper -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/1-isdigit -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-squares: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/8-squares -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/5-rev_string -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x05-pointers_arrays_strings/8-print_array -------------------------------------------------------------------------------- /0x00-hello_world/main.c: -------------------------------------------------------------------------------- 1 | /** 2 | * main - Entry point 3 | * 4 | * Return: Always 0 (Success) 5 | */ 6 | int main(void) 7 | { 8 | return (0); 9 | } 10 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/100-print_comb3 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/101-print_comb4 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/102-print_comb5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/102-print_comb5 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/2-print_alphabet -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/4-print_alphabt -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/5-print_numbers -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/6-print_numberz -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/7-print_tebahpla -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/8-print_base16 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/100-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x02-functions_nested_loops/100-times_table -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-triangles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/10-triangles -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-diagonals: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/7-diagonals -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/9-fizz_buzz -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/5-string_toupper -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/100-set_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/100-set_string -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/8-print_diagsums -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/100-operations.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x18-dynamic_libraries/tmp/100-operations.o -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x01-variables_if_else_while/3-print_alphabets -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/5-more_numbers -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x06-pointers_arrays_strings/101-print_numbers -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x07-pointers_arrays_strings/7-print_chessboard -------------------------------------------------------------------------------- /0x1C-makefiles/m.h: -------------------------------------------------------------------------------- 1 | #ifndef __M_H__ 2 | #define __M_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_holberton(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/100-prime_factor -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/101-print_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/3-print_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/isoteriksoftware/alx-low_level_programming/HEAD/0x04-more_functions_nested_loops/4-print_most_numbers -------------------------------------------------------------------------------- /0x0D-preprocessor/3-function_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef THREE_FUNCTION_LIKE_MACRO_H 2 | #define THREE_FUNCTION_LIKE_MACRO_H 3 | 4 | #define ABS(x) (x > 0 ? (x) : (x) * -1) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/template.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x1C-makefiles/main.c: -------------------------------------------------------------------------------- 1 | #include "m.h" 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 7 | */ 8 | int main(void) 9 | { 10 | print_holberton(); 11 | return (EXIT_SUCCESS); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | jack_bauer(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | times_table(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_alphabet(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | more_numbers(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-make_me_win.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget -P /tmp https://github.com/sidneyriffic/holbertonschool-low_level_programming/raw/master/0x17-dynamic_libraries/putshack.so 3 | export LD_PRELOAD=/tmp/putshack.so 4 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_alphabet_x10(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_numbers(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x0D-preprocessor/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Print the name of the file compiled from 5 | * Return: 0; 6 | */ 7 | int main(void) 8 | { 9 | printf("%s\n", __FILE__); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_most_numbers(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x08-recursion/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | _puts_recursion("Puts with recursion"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x08-recursion/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | _print_rev_recursion("\nColton Walker"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x15-file_io/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - pribts a character 5 | * @c: the chracter to print 6 | * 7 | * Return: 0 on success 8 | */ 9 | 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - pribts a character 5 | * @c: the chracter to print 6 | * 7 | * Return: 0 on success 8 | */ 9 | 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x10-variadic_functions/2-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_strings(", ", 2, "Jay", "Django"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/3-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_all("ceis", 'B', 3, "stSchool"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - pribts a character 5 | * @c: the chracter to print 6 | * 7 | * Return: 0 on success 8 | */ 9 | 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x00-hello_world/4-puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | puts("\"Programming is like building a multilingual puzzle"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_numbers(", ", 4, 0, 98, -1024, 402); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - pribts a character 5 | * @c: the chracter to print 6 | * 7 | * Return: 0 on success 8 | */ 9 | 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/100-set_string.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * set_string - sets the value of a pointer to a char. 5 | * @s: the pointer 6 | * @to: new value 7 | */ 8 | void set_string(char **s, char *to) 9 | { 10 | *s = to; 11 | } 12 | -------------------------------------------------------------------------------- /0x00-hello_world/5-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | printf("%s", "with proper grammar, but the outcome is a piece of art,\n"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "0123456789"; 13 | puts2(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "012345678"; 13 | puts_half(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_square(2); 11 | print_square(10); 12 | print_square(0); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x03-debugging/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - tests function that prints if integer is positive or negative 5 | * Return: 0 6 | */ 7 | 8 | int main(void) 9 | { 10 | int i; 11 | 12 | i = 0; 13 | positive_or_negative(i); 14 | 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * reset_to_98 - Takes a pointer to an int as parameter and updates 5 | * the value it points to to 98 6 | * @n: A pointer to an int 7 | */ 8 | void reset_to_98(int *n) 9 | { 10 | *n = 98; 11 | } 12 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * swap_int - Swaps the values of two integers 5 | * @a: First integer 6 | * @b: Second integer 7 | */ 8 | void swap_int(int *a, int *b) 9 | { 10 | int temp = *a; 11 | *a = *b; 12 | *b = temp; 13 | } 14 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _abs - Computes the absolute value of an integer 5 | * @i: The integer to compute with 6 | * 7 | * Return: The absolute value of i 8 | */ 9 | int _abs(int i) 10 | { 11 | return (i < 0 ? i * -1 : i); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * mul - Multiplies two integers 5 | * @a: First number 6 | * @b: Second number 7 | * 8 | * Return: The multiplication of a and b 9 | */ 10 | int mul(int a, int b) 11 | { 12 | return (a * b); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts - prints a given string 5 | * @s: pointer to the string 6 | */ 7 | 8 | void _puts(char *s) 9 | { 10 | int x = 0; 11 | 12 | while (s[x] != '\0') 13 | _putchar(s[x++]); 14 | _putchar('\n'); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = add(89, 9); 14 | printf("%d\n", n); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _abs - Computes the absolute value of an integer 5 | * @i: The integer to compute with 6 | * 7 | * Return: The absolute value of i 8 | */ 9 | int _abs(int i) 10 | { 11 | return (i < 0 ? i * -1 : i); 12 | } 13 | -------------------------------------------------------------------------------- /0x0F-function_pointers/0-print_name.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * print_name - prints a name. 5 | * @name: the name 6 | * @f: the function to print with 7 | */ 8 | void print_name(char *name, void (*f)(char *)) 9 | { 10 | if (name && f) 11 | f(name); 12 | } 13 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/1-print_binary.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_binary - prints an int in binary 5 | * @n: number to print 6 | */ 7 | void print_binary(unsigned long int n) 8 | { 9 | if (n > 1) 10 | print_binary(n >> 1); 11 | _putchar(n & 1 ? '1' : '0'); 12 | } 13 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-get_endianness.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * get_endianness - check the endian status 5 | * 6 | * Return: 1 if big 0 if little 7 | */ 8 | int get_endianness(void) 9 | { 10 | int x = 1; 11 | char *c = (char *)(&x); 12 | 13 | return (*c); 14 | } 15 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _abs - get the absolute value of an int 5 | * @n: The integer to check 6 | * Return: The absolute value of n 7 | */ 8 | 9 | int _abs(int n) 10 | { 11 | if (n < 0) 12 | return (-n); 13 | return (n); 14 | } 15 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * add - Returns the addition of two integers 5 | * @a: The first integer 6 | * @b: The second integer 7 | * 8 | * Return: The addition of a and b 9 | */ 10 | int add(int a, int b) 11 | { 12 | return (a + b); 13 | } 14 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_line(0); 11 | print_line(2); 12 | print_line(10); 13 | print_line(-4); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x03-debugging/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | 6 | void positive_or_negative(int i); 7 | int largest_number(int a, int b, int c); 8 | int convert_day(int month, int day); 9 | void print_remaining_days(int month, int day, int year); 10 | 11 | #endif /* MAIN_H */ 12 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | printf("%d\n", mul(98, 1024)); 12 | printf("%d\n", mul(-402, 4096)); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x08-recursion/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = _strlen_recursion("Corbin Coleman"); 14 | printf("%d\n", n); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x1C-makefiles/3-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | RM = rm -f 6 | 7 | all: $(OBJ) 8 | $(CC) $(OBJ) -o $(NAME) 9 | 10 | clean: 11 | $(RM) *~ $(NAME) 12 | 13 | oclean: 14 | $(RM) $(OBJ) 15 | 16 | fclean: clean oclean 17 | 18 | re: fclean all 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_triangle(2); 11 | print_triangle(10); 12 | print_triangle(1); 13 | print_triangle(0); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_numbers - Prints the numbers, from 0 to 9, followed by a new line 5 | */ 6 | void print_numbers(void) 7 | { 8 | char c; 9 | 10 | for (c = '0'; c <= '9'; c++) 11 | _putchar(c); 12 | _putchar('\n'); 13 | } 14 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_diagonal(0); 11 | print_diagonal(2); 12 | print_diagonal(10); 13 | print_diagonal(-4); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _print_rev_recursion - prints a string in reverse. 5 | * @s: the string 6 | */ 7 | void _print_rev_recursion(char *s) 8 | { 9 | if (*s == '\0') 10 | return; 11 | 12 | _print_rev_recursion(s + 1); 13 | _putchar(*s); 14 | } 15 | -------------------------------------------------------------------------------- /0x0D-preprocessor/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "4-sum.h" 3 | #include "4-sum.h" 4 | 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int s; 13 | 14 | s = SUM(98, 1024); 15 | printf("%d\n", s); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-free_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | 4 | /** 5 | * free_dog - free the dogs 6 | * @d: pointer to dog struct 7 | */ 8 | void free_dog(dog_t *d) 9 | { 10 | if (d != NULL) 11 | { 12 | free(d->name); 13 | free(d->owner); 14 | 15 | free(d); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i; 11 | 12 | for (i = 0; i < 10; i++) 13 | { 14 | printf("%d", i); 15 | } 16 | printf("\n"); 17 | 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i; 11 | 12 | for (i = 0; i < 10; i++) 13 | { 14 | putchar(i + '0'); 15 | } 16 | putchar('\n'); 17 | 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_alphabet - Prints the alphabet in lowercase, followed by a newline 5 | */ 6 | void print_alphabet(void) 7 | { 8 | char c = 'a'; 9 | 10 | while (c <= 'z') 11 | { 12 | _putchar(c); 13 | c++; 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; 13 | _puts(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0B-malloc_free/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | char *create_array(unsigned int size, char c); 3 | char *_strdup(char *str); 4 | char *str_concat(char *s1, char *s2); 5 | int **alloc_grid(int width, int height); 6 | void free_grid(int **grid, int height); 7 | char *argstostr(int ac, char **av); 8 | char **strtow(char *str); 9 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_to_98(0); 11 | print_to_98(98); 12 | print_to_98(111); 13 | print_to_98(81); 14 | print_to_98(-10); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen - Returns the length of a string 5 | * @s: The string 6 | * 7 | * Return: The length of the string 8 | */ 9 | int _strlen(char *s) 10 | { 11 | int len = 0; 12 | 13 | while (s[len]) 14 | len++; 15 | 16 | return (len); 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts - Prints a string, followed by a new line, to stdout 5 | * @str: The string 6 | */ 7 | void _puts(char *str) 8 | { 9 | int i = 0; 10 | 11 | while (str[i]) 12 | { 13 | _putchar(str[i]); 14 | i++; 15 | } 16 | _putchar('\n'); 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; 13 | print_rev(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-recursion/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen - Returns the length of a string 5 | * @s: The string 6 | * 7 | * Return: The length of the string 8 | */ 9 | int _strlen(char *s) 10 | { 11 | int len = 0; 12 | 13 | while (s[len]) 14 | len++; 15 | 16 | return (len); 17 | } 18 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts - Prints a string, followed by a new line, to stdout 5 | * @str: The string 6 | */ 7 | void _puts(char *str) 8 | { 9 | int i = 0; 10 | 11 | while (str[i]) 12 | { 13 | _putchar(str[i]); 14 | i++; 15 | } 16 | _putchar('\n'); 17 | } 18 | -------------------------------------------------------------------------------- /0x0A-argc_argv/0-whatsmyname.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints its name, followed by a new line. 5 | * @argc: argument count 6 | * @argv: arguments 7 | * 8 | * Return: 0 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | (void)argc; 13 | 14 | printf("%s\n", argv[0]); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0A-argc_argv/1-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints the number of arguments passed into it. 5 | * @argc: argument count 6 | * @argv: arguments 7 | * 8 | * Return: 0 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | (void)argv; 13 | 14 | printf("%d\n", argc - 1); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | section .data 2 | fmt db "%s", 10, 0 3 | msg db "Hello, Holberton", 0 4 | 5 | section .text 6 | extern printf 7 | global main 8 | 9 | main: 10 | push rbp 11 | mov rsi, msg 12 | mov rdi, fmt 13 | mov rax, 0 14 | call printf 15 | pop rbp 16 | mov rax, 0 17 | ret 18 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/4-free_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_listint - frees a list 5 | * @head: pointer to head 6 | */ 7 | void free_listint(listint_t *head) 8 | { 9 | listint_t *tmp; 10 | 11 | while (head) 12 | { 13 | tmp = head->next; 14 | free(head); 15 | head = tmp; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isdigit - checks if a character is a digit 5 | * @c: the character to check 6 | * Return: 1 if is lower 0 otherwise; 7 | */ 8 | 9 | int _isdigit(int c) 10 | { 11 | if (c < '0' || c > '9') 12 | return (0); 13 | else 14 | return (1); 15 | } 16 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _islower - checks if a character is lower case 5 | * @c: the character to check 6 | * Return: 1 if is lower 0 otherwise; 7 | */ 8 | 9 | int _islower(int c) 10 | { 11 | if (c < 'a' || c > 'z') 12 | return (0); 13 | else 14 | return (1); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isupper - Checks for uppercase character 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is uppercase. 0 otherwise 8 | */ 9 | int _isupper(int c) 10 | { 11 | if (c >= 'A' && c <= 'Z') 12 | return (1); 13 | 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isdigit - Checks for a digit (0 through 9) 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is a digit. 0 otherwise 8 | */ 9 | int _isdigit(int c) 10 | { 11 | if (c >= '0' && c <= '9') 12 | return (1); 13 | 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isupper - Checks for uppercase character 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is uppercase. 0 otherwise 8 | */ 9 | int _isupper(int c) 10 | { 11 | if (c >= 'A' && c <= 'Z') 12 | return (1); 13 | 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isdigit - Checks for a digit (0 through 9) 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is a digit. 0 otherwise 8 | */ 9 | int _isdigit(int c) 10 | { 11 | if (c >= '0' && c <= '9') 12 | return (1); 13 | 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0D-preprocessor/0-main.c: -------------------------------------------------------------------------------- 1 | #include "0-object_like_macro.h" 2 | #include "0-object_like_macro.h" 3 | #include 4 | 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int s; 13 | 14 | s = 98 + SIZE; 15 | printf("%d\n", s); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0F-function_pointers/function_pointers.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_POINTERS_H 2 | #define FUNCTION_POINTERS_H 3 | 4 | #include 5 | 6 | void print_name(char *name, void (*f)(char *)); 7 | void array_iterator(int *array, size_t size, void (*action)(int)); 8 | int int_index(int *array, int size, int (*cmp)(int)); 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-free_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_list - frees a list 5 | * @head: pointer to head 6 | */ 7 | void free_list(list_t *head) 8 | { 9 | list_t *tmp; 10 | 11 | while (head) 12 | { 13 | free(head->str); 14 | tmp = head->next; 15 | free(head); 16 | head = tmp; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen - calculate the length of a string 5 | * @s: pointer to the string 6 | * Return: The length of the string 7 | */ 8 | 9 | int _strlen(char *s) 10 | { 11 | int x = 0; 12 | 13 | while (s[x++] != '\0') 14 | continue; 15 | return (x - 1); 16 | } 17 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s[10] = "My School"; 12 | 13 | printf("%s\n", s); 14 | rev_string(s); 15 | printf("%s\n", s); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts_recursion - prints a string, followed by a new line. 5 | * @s: the string 6 | */ 7 | void _puts_recursion(char *s) 8 | { 9 | if (*s == '\0') 10 | { 11 | _putchar('\n'); 12 | return; 13 | } 14 | 15 | _putchar(*s); 16 | _puts_recursion(++s); 17 | } 18 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-first.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void start(void) __attribute__((constructor)); 5 | 6 | /** 7 | * start - executes before main 8 | */ 9 | 10 | void start(void) 11 | { 12 | printf("You're beat! and yet, you must allow,\n"); 13 | printf("I bore my house upon my back!\n"); 14 | } 15 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/4-free_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_dlistint - frees a list 5 | * 6 | * @head: list head 7 | */ 8 | 9 | void free_dlistint(dlistint_t *head) 10 | { 11 | dlistint_t *temp; 12 | 13 | while (head) 14 | { 15 | temp = head->next; 16 | free(head); 17 | head = temp; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isupper - checks if a character is an upper case letter 5 | * @c: the character to check 6 | * Return: 1 if is lower 0 otherwise; 7 | */ 8 | 9 | int _isupper(int c) 10 | { 11 | if (c < 'A' || c > 'Z') 12 | return (0); 13 | else 14 | return (1); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _islower - Checks for lowercase character 5 | * @c: The character to be checked 6 | * 7 | * Return: 1 if c is lowercase, otherwise 0 8 | */ 9 | int _islower(int c) 10 | { 11 | if (c >= 'a' && c <= 'z') 12 | return (1); 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = 402; 14 | printf("n=%d\n", n); 15 | reset_to_98(&n); 16 | printf("n=%d\n", n); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen_recursion - returns the length of a string. 5 | * @s: the string 6 | * 7 | * Return: the length of the string 8 | */ 9 | int _strlen_recursion(char *s) 10 | { 11 | if (*s == '\0') 12 | return (0); 13 | 14 | return (_strlen_recursion(++s) + 1); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _islower - Checks for lowercase character 5 | * @c: The character to be checked 6 | * 7 | * Return: 1 if c is lowercase, otherwise 0 8 | */ 9 | int _islower(int c) 10 | { 11 | if (c >= 'a' && c <= 'z') 12 | return (1); 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0D-preprocessor/1-main.c: -------------------------------------------------------------------------------- 1 | #include "1-pi.h" 2 | #include "1-pi.h" 3 | #include 4 | 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | float a; 13 | float r; 14 | 15 | r = 98; 16 | a = PI * r * r; 17 | printf("%.3f\n", a); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | char alphabet = 'a'; 11 | 12 | while (alphabet <= 'z') 13 | { 14 | putchar(alphabet); 15 | alphabet++; 16 | } 17 | putchar('\n'); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | char alphabet = 'z'; 11 | 12 | while (alphabet >= 'a') 13 | { 14 | putchar(alphabet); 15 | alphabet--; 16 | } 17 | putchar('\n'); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x08-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * factorial - returns the factorial of a given number. 5 | * @n: the number 6 | * 7 | * Return: the factorial of n 8 | */ 9 | int factorial(int n) 10 | { 11 | if (n < 0) 12 | return (-1); 13 | if (n == 0) 14 | return (1); 15 | 16 | return (n * factorial(n - 1)); 17 | } 18 | -------------------------------------------------------------------------------- /0x0A-argc_argv/2-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints all arguments it receives. 5 | * @argc: argument count 6 | * @argv: arguments 7 | * 8 | * Return: 0 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | int i; 13 | 14 | for (i = 0; i < argc; i++) 15 | printf("%s\n", argv[i]); 16 | 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0B-malloc_free/4-free_grid.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * free_grid - frees a 2 dimensional grid 6 | * @grid: the grid 7 | * @height: height of the grid 8 | */ 9 | void free_grid(int **grid, int height) 10 | { 11 | int i; 12 | 13 | for (i = 0; i < height; i++) 14 | free(grid[i]); 15 | free(grid); 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *str; 12 | int len; 13 | 14 | str = "My first strlen!"; 15 | len = _strlen(str); 16 | printf("%d\n", len); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void _puts_recursion(char *s); 3 | void _print_rev_recursion(char *s); 4 | int _strlen_recursion(char *s); 5 | int factorial(int n); 6 | int _pow_recursion(int x, int y); 7 | int _sqrt_recursion(int n); 8 | int is_prime_number(int n); 9 | int is_palindrome(char *s); 10 | int wildcmp(char *s1, char *s2); 11 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-putchar.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i = 0; 11 | char text[] = "_putchar"; 12 | 13 | while (text[i] != '\0') 14 | { 15 | _putchar(text[i]); 16 | i++; 17 | } 18 | _putchar('\n'); 19 | 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "world"; 13 | char *t; 14 | 15 | t = _strpbrk(s, f); 16 | printf("%s\n", t); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "llo"; 13 | char *t; 14 | 15 | t = _strstr(s, f); 16 | printf("%s\n", t); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_chessboard - prints the chessboard. 5 | * @a: the board 6 | */ 7 | void print_chessboard(char (*a)[8]) 8 | { 9 | int i, j; 10 | 11 | for (i = 0; i < 8; i++) 12 | { 13 | for (j = 0; j < 8; j++) 14 | _putchar(a[i][j]); 15 | _putchar('\n'); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x1C-makefiles/4-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | RM = rm -f 6 | CFLAGS = -Wall -Werror -Wextra -pedantic 7 | 8 | all: $(OBJ) 9 | $(CC) $(CLFAGS) $(OBJ) -o $(NAME) 10 | 11 | clean: 12 | $(RM) *~ $(NAME) 13 | 14 | oclean: 15 | $(RM) $(OBJ) 16 | 17 | fclean: clean oclean 18 | 19 | re: fclean all 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | print_last_digit(98); 13 | print_last_digit(0); 14 | r = print_last_digit(-1024); 15 | _putchar('0' + r); 16 | _putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "oleh"; 13 | unsigned int n; 14 | 15 | n = _strspn(s, f); 16 | printf("%u\n", n); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | struct dog my_dog; 12 | 13 | my_dog.name = "Poppy"; 14 | my_dog.age = 3.5; 15 | my_dog.owner = "Bob"; 16 | print_dog(&my_dog); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x03-debugging/positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * positive_or_negative - Prints 'i is zero' if i is 0, 5 | * 'i is positive' if i > 0 or 'i is negative' if i < 0 6 | * @i: The number to check 7 | * 8 | */ 9 | void positive_or_negative(int i) 10 | { 11 | printf("%d is %s\n", i, i == 0 ? "zero" : i < 0 ? "negative" : "positive"); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | 13 | c = 'A'; 14 | printf("%c: %d\n", c, _isupper(c)); 15 | c = 'a'; 16 | printf("%c: %d\n", c, _isupper(c)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | 13 | c = '0'; 14 | printf("%c: %d\n", c, _isdigit(c)); 15 | c = 'a'; 16 | printf("%c: %d\n", c, _isdigit(c)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char str[] = "Look up!\n"; 12 | char *ptr; 13 | 14 | ptr = string_toupper(str); 15 | printf("%s", ptr); 16 | printf("%s", str); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/main.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int _putchar(char c); 4 | void *malloc_checked(unsigned int b); 5 | char *string_nconcat(char *s1, char *s2, unsigned int n); 6 | int *array_range(int min, int max); 7 | void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size); 8 | void *_calloc(unsigned int nmemb, unsigned int size); 9 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/8-sum_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_listint - prints a singly linked list 5 | * @h: head of the list 6 | * Return: sum of list data 7 | */ 8 | int sum_listint(listint_t *h) 9 | { 10 | int retval = 0; 11 | 12 | while (h) 13 | { 14 | retval += h->n; 15 | h = h->next; 16 | } 17 | return (retval); 18 | } 19 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/6-sum_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_dlistint - sum the list 5 | * 6 | * @head: head of the list 7 | * Return: sum of nodes data 8 | */ 9 | int sum_dlistint(dlistint_t *head) 10 | { 11 | int sum = 0; 12 | 13 | while (head) 14 | { 15 | sum += head->n; 16 | head = head->next; 17 | } 18 | return (sum); 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isalpha - checks if a character is an alphabet 5 | * @c: the character to check 6 | * Return: 1 if its an alphabet 0 otherwise; 7 | */ 8 | 9 | int _isalpha(int c) 10 | { 11 | if ((c > 96 && c < 122) || 12 | (c > 64 && c <= 'Z')) 13 | return (1); 14 | else 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/1-listint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * listint_len - length of a singly linked list 5 | * @h: head of the list 6 | * Return: number of nodes 7 | */ 8 | size_t listint_len(const listint_t *h) 9 | { 10 | int retval = 0; 11 | 12 | while (h) 13 | { 14 | h = h->next; 15 | retval++; 16 | } 17 | return (retval); 18 | } 19 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-free_listint2.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_listint2 - frees a list 5 | * @head: pointer to head 6 | */ 7 | void free_listint2(listint_t **head) 8 | { 9 | listint_t *tmp; 10 | 11 | if (!head) 12 | return; 13 | while (*head) 14 | { 15 | tmp = (*head)->next; 16 | free(*head); 17 | *head = tmp; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *concat; 13 | 14 | concat = string_nconcat("Best ", "School !!!", 6); 15 | printf("%s\n", concat); 16 | free(concat); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | struct dog my_dog; 12 | 13 | init_dog(&my_dog, "Poppy", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | dog_t *my_dog; 12 | 13 | my_dog = new_dog("Poppy", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x00-hello_world/101-quote.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: 1 (Success) 9 | */ 10 | int main(void) 11 | { 12 | char *text = "and that piece of art is useful\" - Dora Korpar, 2015-10-19\n"; 13 | int length = strlen(text); 14 | 15 | write(2, text, length); 16 | return (1); 17 | } 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_line - Draws a straight line in the terminal 5 | * @n: Length of the line 6 | */ 7 | void print_line(int n) 8 | { 9 | int i; 10 | 11 | if (n <= 0) 12 | { 13 | _putchar('\n'); 14 | return; 15 | } 16 | 17 | for (i = 0; i < n; i++) 18 | _putchar('_'); 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code for 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int array[5]; 11 | 12 | array[0] = 98; 13 | array[1] = 402; 14 | array[2] = -198; 15 | array[3] = 298; 16 | array[4] = -1024; 17 | print_array(array, 5); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello"; 12 | char *f; 13 | 14 | f = _strchr(s, 'l'); 15 | 16 | if (f != NULL) 17 | { 18 | printf("%s\n", f); 19 | } 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/1-dlistint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * dlistint_len - get the length of a list 5 | * 6 | * @head: list head 7 | * Return: length of list 8 | */ 9 | size_t dlistint_len(const dlistint_t *head) 10 | { 11 | size_t count = 0; 12 | 13 | while (head) 14 | { 15 | head = head->next; 16 | count++; 17 | } 18 | return (count); 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/README.md: -------------------------------------------------------------------------------- 1 | # C - Dynamic libraries 2 | 3 | ## Description 4 | How to create Dynamic libraries in C. and also use them in python programs. 5 | 6 | ## Tasks 7 | * [libdynamic.so](libdynamic.so), [main.h](main.h) 8 | * [1-create_dynamic_lib.sh](1-create_dynamic_lib.sh) 9 | * [100-operations.so](100-operations.so) 10 | * [101-make_me_win.sh](101-make_me_win.sh) 11 | -------------------------------------------------------------------------------- /0x0D-preprocessor/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "3-function_like_macro.h" 3 | #include "3-function_like_macro.h" 4 | 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int i; 13 | int j; 14 | 15 | i = ABS(-98) * 10; 16 | j = ABS(98) * 10; 17 | printf("%d, %d\n", i, j); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x1C-makefiles/100-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | CFLAGS = -Wall -Werror -Wextra -pedantic 6 | 7 | .PHONY: all clean oclean fclean re 8 | 9 | all: m.h $(OBJ) 10 | $(CC) $(OBJ) -o $(NAME) 11 | 12 | clean: 13 | $(RM) *~ $(NAME) 14 | 15 | oclean: 16 | $(RM) $(OBJ) 17 | 18 | fclean: clean oclean 19 | 20 | re: fclean all 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isalpha - Checks for alphabetic character 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is a letter, lowercase or uppercase. 0 otherwise 8 | */ 9 | int _isalpha(int c) 10 | { 11 | if ((c >= 'A' && c <= 'Z') || 12 | (c >= 'a' && c <= 'z')) 13 | return (1); 14 | else 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x03-debugging/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - causes an infinite loop 5 | * Return: 0 6 | */ 7 | 8 | int main(void) 9 | { 10 | int i; 11 | 12 | printf("Infinite loop incoming :(\n"); 13 | i = 0; 14 | /* 15 | * while (i < 10) 16 | * { 17 | * putchar(i); 18 | * } 19 | */ 20 | 21 | printf("Infinite loop avoided! \\o/\n"); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_most_numbers - Prints the numbers, from 0 to 9 (2,4 exclusive), 5 | * followed by a new line 6 | */ 7 | void print_most_numbers(void) 8 | { 9 | char c; 10 | 11 | for (c = '0'; c <= '9'; c++) 12 | { 13 | if (c != '2' && c != '4') 14 | _putchar(c); 15 | } 16 | _putchar('\n'); 17 | } 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | int _isupper(int c); 3 | int _isdigit(int c); 4 | int mul(int a, int b); 5 | void print_numbers(void); 6 | void print_most_numbers(void); 7 | void more_numbers(void); 8 | void print_line(int n); 9 | void print_diagonal(int n); 10 | void print_square(int size); 11 | void print_triangle(int size); 12 | void print_number(int n); 13 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int a; 12 | int b; 13 | 14 | a = 98; 15 | b = 42; 16 | printf("a=%d, b=%d\n", a, b); 17 | swap_int(&a, &b); 18 | printf("a=%d, b=%d\n", a, b); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | char alphabet = 'a'; 11 | 12 | while (alphabet <= 'z') 13 | { 14 | if (alphabet != 'q' && alphabet != 'e') 15 | putchar(alphabet); 16 | alphabet++; 17 | } 18 | putchar('\n'); 19 | 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_times_table(3); 11 | _putchar('\n'); 12 | print_times_table(5); 13 | _putchar('\n'); 14 | print_times_table(98); 15 | _putchar('\n'); 16 | print_times_table(12); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void print_alphabet(void); 3 | void print_alphabet_x10(void); 4 | int _islower(int c); 5 | int _isalpha(int c); 6 | int print_sign(int n); 7 | int _abs(int); 8 | int print_last_digit(int); 9 | void jack_bauer(void); 10 | void times_table(void); 11 | int add(int, int); 12 | void print_to_98(int n); 13 | void print_times_table(int n); 14 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98]; 12 | char *ptr; 13 | 14 | ptr = _strcpy(s1, "First, solve the problem. Then, write the code\n"); 15 | printf("%s", s1); 16 | printf("%s", ptr); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void reset_to_98(int *n); 3 | void swap_int(int *a, int *b); 4 | int _strlen(char *s); 5 | void _puts(char *str); 6 | void print_rev(char *s); 7 | void rev_string(char *s); 8 | void puts2(char *str); 9 | void puts_half(char *str); 10 | void print_array(int *a, int n); 11 | char *_strcpy(char *dest, char *src); 12 | int _atoi(char *s); 13 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s0 = "Bob Dylan"; 12 | char *s1 = "Robert Allen"; 13 | 14 | printf("%s, %s\n", s0, s1); 15 | set_string(&s1, s0); 16 | printf("%s, %s\n", s0, s1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isalpha - Checks for alphabetic character 5 | * @c: The character to check 6 | * 7 | * Return: 1 if c is a letter, lowercase or uppercase. 0 otherwise 8 | */ 9 | int _isalpha(int c) 10 | { 11 | if ((c >= 'A' && c <= 'Z') || 12 | (c >= 'a' && c <= 'z')) 13 | return (1); 14 | else 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/0-malloc_checked.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * malloc_checked - allocates memory using malloc. 5 | * @b: the memory size 6 | * 7 | * Return: a pointer to the allocated memory 8 | */ 9 | void *malloc_checked(unsigned int b) 10 | { 11 | void *memory; 12 | 13 | memory = malloc(b); 14 | if (memory == NULL) 15 | exit(98); 16 | 17 | return (memory); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i; 11 | char c; 12 | 13 | for (i = 0; i < 10; i++) 14 | { 15 | putchar(i + '0'); 16 | } 17 | 18 | for (c = 'a'; c < 'g'; c++) 19 | { 20 | putchar(c); 21 | } 22 | putchar('\n'); 23 | 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | dog_t *my_dog; 12 | 13 | my_dog = new_dog("Poppy", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | free_dog(my_dog); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-print_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_listint - prints a singly linked list 5 | * @h: head of the list 6 | * Return: number of nodes 7 | */ 8 | size_t print_listint(const listint_t *h) 9 | { 10 | int retval = 0; 11 | 12 | while (h) 13 | { 14 | printf("%d\n", h->n); 15 | h = h->next; 16 | retval++; 17 | } 18 | return (retval); 19 | } 20 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: 0 (Success) 9 | */ 10 | int main(void) 11 | { 12 | int n; 13 | 14 | srand(time(0)); 15 | n = rand() - RAND_MAX / 2; 16 | printf("%d is %s\n", n, n == 0 ? "zero" : n < 0 ? "negative" : "positive"); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = _islower('H'); 13 | _putchar(r + '0'); 14 | r = _islower('o'); 15 | _putchar(r + '0'); 16 | r = _islower(108); 17 | _putchar(r + '0'); 18 | _putchar('\n'); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[] = "Hello"; 12 | char s2[] = "World!"; 13 | 14 | printf("%d\n", _strcmp(s1, s2)); 15 | printf("%d\n", _strcmp(s2, s1)); 16 | printf("%d\n", _strcmp(s1, s1)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * reverse_array - Reverses the content of an array of integers. 5 | * @a: The array 6 | * @n: Length of array 7 | */ 8 | void reverse_array(int *a, int n) 9 | { 10 | int i, j, temp; 11 | 12 | for (i = 0; i < n / 2; i++) 13 | { 14 | j = n - i - 1; 15 | temp = a[i]; 16 | a[i] = a[j]; 17 | a[j] = temp; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s[] = "Expect the best. Prepare for the worst. Capitalize on what comes.\n"; 12 | char *p; 13 | 14 | p = leet(s); 15 | printf("%s", p); 16 | printf("%s", s); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x10-variadic_functions/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "variadic_functions.h" 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int sum; 12 | 13 | sum = sum_them_all(2, 98, 1024); 14 | printf("%d\n", sum); 15 | sum = sum_them_all(4, 98, 1024, 402, -1024); 16 | printf("%d\n", sum); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i = 1, j = 2, total = 0; 11 | int k; 12 | 13 | while (j < 4000000) 14 | { 15 | if (j % 2 == 0) 16 | total += j; 17 | 18 | k = j; 19 | j += i; 20 | i = k; 21 | } 22 | printf("%d\n", total); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * list_len - returns the number of elements in a linked list_t list. 5 | * @h: the list 6 | * 7 | * Return: the number of elements in a linked list_t list. 8 | */ 9 | size_t list_len(const list_t *h) 10 | { 11 | size_t elements; 12 | 13 | for (elements = 0; h; h = h->next) 14 | elements++; 15 | 16 | return (elements); 17 | } 18 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/0-print_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_dlistint - prints a list 5 | * 6 | * @head: list head 7 | * Return: length of list 8 | */ 9 | 10 | size_t print_dlistint(const dlistint_t *head) 11 | { 12 | size_t count = 0; 13 | 14 | while (head) 15 | { 16 | printf("%d\n", head->n); 17 | count++; 18 | head = head->next; 19 | } 20 | return (count); 21 | } 22 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i = 0; 11 | 12 | while (i < 10) 13 | { 14 | putchar(i + '0'); 15 | if (i < 9) 16 | { 17 | putchar(44); /* comma */ 18 | putchar(32); /* space */ 19 | } 20 | i++; 21 | } 22 | putchar('\n'); 23 | 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i = 1; 11 | int total = 0; 12 | 13 | while (i < 1024) 14 | { 15 | if (i % 3 == 0) 16 | total += i; 17 | else if (i % 5 == 0) 18 | total += i; 19 | 20 | i++; 21 | } 22 | printf("%d\n", total); 23 | 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - Entry point 6 | * 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | int c; 12 | long num = 612852475143; 13 | 14 | for (c = (int) sqrt(num); c > 2; c++) 15 | { 16 | if (num % c == 0) 17 | { 18 | printf("%d\n", c); 19 | break; 20 | } 21 | } 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memset - set bytes of a buffer to a constant 5 | * @s: pointer to the buffer 6 | * @b: the constant to fill s 7 | * @n: number of bytes to fill 8 | * Return: pointer to s 9 | */ 10 | char *_memset(char *s, char b, unsigned int n) 11 | { 12 | unsigned int i; 13 | 14 | for (i = 0; i < n; i++) 15 | s[i] = b; 16 | return (s); 17 | } 18 | -------------------------------------------------------------------------------- /0x1C-makefiles/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 5-main 4 | """ 5 | island_perimeter = __import__('5-island_perimeter').island_perimeter 6 | 7 | if __name__ == "__main__": 8 | grid = [ 9 | [0, 0, 0, 0, 0, 0], 10 | [0, 1, 0, 0, 0, 0], 11 | [0, 1, 0, 0, 0, 0], 12 | [0, 1, 1, 1, 0, 0], 13 | [0, 0, 0, 0, 0, 0] 14 | ] 15 | print(island_perimeter(grid)) 16 | 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_rev - Prints a string, in reverse, followed by a new line 5 | * @s: The string 6 | */ 7 | void print_rev(char *s) 8 | { 9 | /* Figure out the length first */ 10 | int len = 0; 11 | 12 | while (s[len]) 13 | len++; 14 | 15 | /* Print backwards */ 16 | while (--len >= 0) 17 | _putchar(s[len]); 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_alphabet_x10 - Prints the alphabet in lowercase 10 times, 5 | * followed by a newline 6 | */ 7 | void print_alphabet_x10(void) 8 | { 9 | int i; 10 | char c; 11 | 12 | for (i = 0; i < 10; i++) 13 | { 14 | c = 'a'; 15 | while (c <= 'z') 16 | { 17 | _putchar(c); 18 | c++; 19 | } 20 | _putchar('\n'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * print_array - Prints n elements of an array of integers, 5 | * followed by a new line 6 | * @a: The array 7 | * @n: The number of elements of the array to be printed 8 | */ 9 | void print_array(int *a, int n) 10 | { 11 | int i; 12 | 13 | for (i = 0; i < n; i++) 14 | printf("%d%s", a[i], i != n - 1 ? ", " : ""); 15 | printf("\n"); 16 | } 17 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memset - fills memory with a constant byte. 5 | * @s: memory area 6 | * @b: constant byte 7 | * @n: number of bytes to fill 8 | * 9 | * Return: a pointer to the memory area s 10 | */ 11 | char *_memset(char *s, char b, unsigned int n) 12 | { 13 | unsigned int i; 14 | 15 | for (i = 0; i < n; i++) 16 | s[i] = b; 17 | 18 | return (s); 19 | } 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memset - fills memory with a constant byte. 5 | * @s: memory area 6 | * @b: constant byte 7 | * @n: number of bytes to fill 8 | * 9 | * Return: a pointer to the memory area s 10 | */ 11 | char *_memset(char *s, char b, unsigned int n) 12 | { 13 | unsigned int i; 14 | 15 | for (i = 0; i < n; i++) 16 | s[i] = b; 17 | 18 | return (s); 19 | } 20 | -------------------------------------------------------------------------------- /0x10-variadic_functions/variadic_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIADIC_FUNCTIONS_H 2 | #define VARIADIC_FUNCTIONS_H 3 | 4 | #include 5 | 6 | int _putchar(char c); 7 | int sum_them_all(const unsigned int n, ...); 8 | void print_numbers(const char *separator, const unsigned int n, ...); 9 | void print_strings(const char *separator, const unsigned int n, ...); 10 | void print_all(const char * const format, ...); 11 | 12 | #endif 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _abs(-1); 14 | printf("%d\n", r); 15 | r = _abs(0); 16 | printf("%d\n", r); 17 | r = _abs(1); 18 | printf("%d\n", r); 19 | r = _abs(-98); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x0B-malloc_free/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for ALX School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char *av[]) 11 | { 12 | char *s; 13 | 14 | s = argstostr(ac, av); 15 | if (s == NULL) 16 | { 17 | return (1); 18 | } 19 | printf("%s", s); 20 | free(s); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * puts2 - Prints every other character of a string, 5 | * starting with the first character, followed by a new line 6 | * @str: The string 7 | */ 8 | void puts2(char *str) 9 | { 10 | int len = 0; 11 | int i = 0; 12 | 13 | while (str[len]) 14 | len++; 15 | 16 | while (i < len) 17 | { 18 | _putchar(str[i]); 19 | i += 2; 20 | } 21 | _putchar('\n'); 22 | } 23 | -------------------------------------------------------------------------------- /0x08-recursion/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = factorial(1); 14 | printf("%d\n", r); 15 | r = factorial(5); 16 | printf("%d\n", r); 17 | r = factorial(10); 18 | printf("%d\n", r); 19 | r = factorial(-1024); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * more_numbers - Prints 10 times the numbers, from 0 to 14, 5 | * followed by a new line 6 | */ 7 | void more_numbers(void) 8 | { 9 | int i, j; 10 | 11 | for (i = 0; i < 10; i++) 12 | { 13 | for (j = 0; j <= 14; j++) 14 | { 15 | if (j > 9) 16 | _putchar(j / 10 + '0'); 17 | _putchar(j % 10 + '0'); 18 | } 19 | _putchar('\n'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * string_toupper - changes all lowercase letters of a string to uppercase. 5 | * @str: The string 6 | * 7 | * Return: The string 8 | */ 9 | char *string_toupper(char *str) 10 | { 11 | int i = 0; 12 | 13 | while (str[i] != '\0') 14 | { 15 | if (str[i] >= 'a' && str[i] <= 'z') 16 | str[i] -= ('a' - 'A'); 17 | i++; 18 | } 19 | 20 | return (str); 21 | } 22 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcpy - copies src to destination 5 | * @src: pointer to the source string 6 | * @dst: pointer to the destination string 7 | * Return: pointer to destination 8 | */ 9 | 10 | char *_strcpy(char *dst, char *src) 11 | { 12 | int x = 0; 13 | 14 | while (src[x] != '\0') 15 | { 16 | dst[x] = src[x]; 17 | x++; 18 | } 19 | dst[x] = '\0'; 20 | return (dst); 21 | } 22 | -------------------------------------------------------------------------------- /0x1A-hash_tables/2-key_index.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * key_index - calculates index of a key 5 | * @key: the key to evaluate 6 | * @size: size of the table 7 | * Return: index of key in table 8 | */ 9 | unsigned long int key_index(const unsigned char *key, 10 | unsigned long int size) 11 | { 12 | unsigned long int index, hash; 13 | 14 | hash = hash_djb2(key); 15 | index = hash % size; 16 | 17 | return (index); 18 | } 19 | -------------------------------------------------------------------------------- /0x03-debugging/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * main - prints the largest of 3 integers 6 | * Return: 0 7 | */ 8 | 9 | int main(void) 10 | { 11 | int a, b, c; 12 | int largest; 13 | 14 | a = 972; 15 | b = -98; 16 | c = 0; 17 | 18 | largest = largest_number(a, b, c); 19 | 20 | printf("%d is the largest number\n", largest); 21 | 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_number(98); 11 | _putchar('\n'); 12 | print_number(402); 13 | _putchar('\n'); 14 | print_number(1024); 15 | _putchar('\n'); 16 | print_number(0); 17 | _putchar('\n'); 18 | print_number(-98); 19 | _putchar('\n'); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = _isalpha('H'); 13 | _putchar(r + '0'); 14 | r = _isalpha('o'); 15 | _putchar(r + '0'); 16 | r = _isalpha(108); 17 | _putchar(r + '0'); 18 | r = _isalpha(';'); 19 | _putchar(r + '0'); 20 | _putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_square - Prints a square, followed by a new line 5 | * @size: The size of a square 6 | */ 7 | void print_square(int size) 8 | { 9 | int x, y; 10 | 11 | if (size < 1) 12 | { 13 | _putchar('\n'); 14 | return; 15 | } 16 | 17 | for (y = 0; y < size; y++) 18 | { 19 | for (x = 0; x < size; x++) 20 | _putchar('#'); 21 | _putchar('\n'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memcpy - copies n bytes from memory area src 5 | * to memory area dest 6 | * @dest: destination 7 | * @src: source 8 | * @n: number of bytes to copy 9 | * 10 | * Return: a pointer to dest 11 | */ 12 | char *_memcpy(char *dest, char *src, unsigned int n) 13 | { 14 | unsigned int i; 15 | 16 | for (i = 0; i < n; i++) 17 | dest[i] = src[i]; 18 | 19 | return (dest); 20 | } 21 | -------------------------------------------------------------------------------- /0x08-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _pow_recursion - returns the value of x raised to the power of y. 5 | * @x: the number 6 | * @y: the power 7 | * 8 | * Return: the value of x raised to the power of y 9 | */ 10 | int _pow_recursion(int x, int y) 11 | { 12 | if (y < 0) 13 | return (-1); 14 | if (y == 0) 15 | return (1); 16 | if (y == 1) 17 | return (x); 18 | 19 | return (x * _pow_recursion(x, --y)); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | char alphabet = 'a'; 11 | 12 | while (alphabet <= 'z') 13 | { 14 | putchar(alphabet); 15 | alphabet++; 16 | } 17 | 18 | alphabet = 'A'; 19 | while (alphabet <= 'Z') 20 | { 21 | putchar(alphabet); 22 | alphabet++; 23 | } 24 | putchar('\n'); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memcpy - copies n bytes from memory area src 5 | * to memory area dest 6 | * @dest: destination 7 | * @src: source 8 | * @n: number of bytes to copy 9 | * 10 | * Return: a pointer to dest 11 | */ 12 | char *_memcpy(char *dest, char *src, unsigned int n) 13 | { 14 | unsigned int i; 15 | 16 | for (i = 0; i < n; i++) 17 | dest[i] = src[i]; 18 | 19 | return (dest); 20 | } 21 | -------------------------------------------------------------------------------- /0x0A-argc_argv/3-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - multiplies two numbers. 6 | * @argc: argument count 7 | * @argv: arguments 8 | * 9 | * Return: 0 10 | */ 11 | int main(int argc, char **argv) 12 | { 13 | int x, y; 14 | 15 | if (argc < 3) 16 | { 17 | printf("Error\n"); 18 | return (1); 19 | } 20 | 21 | x = atoi(argv[1]); 22 | y = atoi(argv[2]); 23 | printf("%d\n", x * y); 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | 4 | /** 5 | * init_dog - initialize a variable of type `struct dog` 6 | * @d: struct dog 7 | * @name: string for name 8 | * @age: integer for age 9 | * @owner: string for owners name 10 | */ 11 | void init_dog(struct dog *d, char *name, float age, char *owner) 12 | { 13 | if (d != NULL) 14 | { 15 | d->name = name; 16 | d->age = age; 17 | d->owner = owner; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-get_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * get_bit - get the bit at a given index 5 | * @n: number to check 6 | * @index: index to check 7 | * Return: bit value or -1; 8 | */ 9 | int get_bit(unsigned long int n, unsigned int index) 10 | { 11 | unsigned long int i = 1, len = 0; 12 | 13 | while (len++ < index) 14 | { 15 | if (len >= MAX_COUNT) 16 | return (-1); 17 | i = i << 1; 18 | } 19 | return (n & i ? 1 : 0); 20 | } 21 | -------------------------------------------------------------------------------- /0x15-file_io/README.md: -------------------------------------------------------------------------------- 1 | # File IO 2 | 3 | ## Description 4 | This Directory contain simple tasks to get us acquainted with handling files. 5 | Creating, reading, writing amd closing files. 6 | 7 | ## Functions and System Calls 8 | * read 9 | * write 10 | * open 11 | * close 12 | 13 | ## Tasks 14 | * [0-read_textfile.c](0-read_textfile.c) 15 | * [1-create_file.c](1-create_file.c) 16 | * [2-append_text_to_file.c](2-append_text_to_file.c) 17 | * [3-cp.c](3-cp.c) 18 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memcpy - copies n bytes from one buffer to another 5 | * @src: pointer to the source buffer 6 | * @dest: pointer to the destination buffer 7 | * @n: number of bytes to copy 8 | * Return: pointer to dst 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | unsigned int i; 13 | 14 | for (i = 0; i < n; i++) 15 | dest[i] = src[i]; 16 | return (dest); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | char *_memset(char *s, char b, unsigned int n); 3 | char *_memcpy(char *dest, char *src, unsigned int n); 4 | char *_strchr(char *s, char c); 5 | unsigned int _strspn(char *s, char *accept); 6 | char *_strpbrk(char *s, char *accept); 7 | char *_strstr(char *haystack, char *needle); 8 | void print_chessboard(char (*a)[8]); 9 | void print_diagsums(int *a, int size); 10 | void set_string(char **s, char *to); 11 | -------------------------------------------------------------------------------- /0x0B-malloc_free/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for ALX School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *s; 13 | 14 | s = _strdup(""); 15 | if (s == NULL) 16 | { 17 | printf("failed to allocate memory\n"); 18 | return (1); 19 | } 20 | printf("%s\n", s); 21 | free(s); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x0B-malloc_free/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for ALX School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *s; 13 | 14 | s = str_concat("Betty ", "Holberton"); 15 | if (s == NULL) 16 | { 17 | printf("failed\n"); 18 | return (1); 19 | } 20 | printf("%s\n", s); 21 | free(s); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x15-file_io/main.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int _putchar(char c); 12 | ssize_t read_textfile(const char *filename, size_t letters); 13 | int append_text_to_file(const char *filename, char *text_content); 14 | int create_file(const char *filename, char *text_content); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/5-get_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_dnodeint_at_index - retrieve node 5 | * 6 | * @head: head of the list 7 | * @index: position of the node to get 8 | * Return: Node at index or null 9 | */ 10 | dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index) 11 | { 12 | unsigned int i = 0; 13 | 14 | while (head && i < index) 15 | { 16 | head = head->next; 17 | i++; 18 | } 19 | return (head); 20 | } 21 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-djb2.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_djb2 - implementation of the djb2 algorithm 5 | * @str: string used to generate hash value 6 | * 7 | * Return: hash value 8 | */ 9 | unsigned long int hash_djb2(const unsigned char *str) 10 | { 11 | unsigned long int hash; 12 | int c; 13 | 14 | hash = 5381; 15 | while ((c = *str++)) 16 | { 17 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 18 | } 19 | return (hash); 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98] = "Hello "; 12 | char s2[] = "World!\n"; 13 | char *ptr; 14 | 15 | printf("%s\n", s1); 16 | printf("%s", s2); 17 | ptr = _strcat(s1, s2); 18 | printf("%s", s1); 19 | printf("%s", s2); 20 | printf("%s", ptr); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/6-pop_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * pop_listint - removes the head of a list 5 | * @head: pointer to head 6 | * 7 | * Return: data of the head 0 otherwise 8 | */ 9 | int pop_listint(listint_t **head) 10 | { 11 | listint_t *tmp; 12 | int retval; 13 | 14 | if (!head || !(*head)) 15 | return (0); 16 | tmp = (*head)->next; 17 | retval = (*head)->n; 18 | free(*head); 19 | *head = tmp; 20 | return (retval); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - Compares two strings. 5 | * @s1: First string 6 | * @s2: Second string 7 | * 8 | * Return: 0 if similar, positive number if s1 > s2, otherwise negative number 9 | */ 10 | int _strcmp(char *s1, char *s2) 11 | { 12 | int i; 13 | 14 | for (i = 0; s1[i] != '\0' || s2[i] != '\0'; i++) 15 | { 16 | if (s1[i] != s2[i]) 17 | return (s1[i] - s2[i]); 18 | } 19 | 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-leet.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * leet - encodes a string into 1337. 5 | * @s: The string 6 | * 7 | * Return: The string 8 | */ 9 | char *leet(char *s) 10 | { 11 | int i, j; 12 | char subs[] = "aAeEoOtTlL"; 13 | char le[] = "43071"; 14 | 15 | i = 0; 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | for (j = 0; subs[j] != '\0'; j++) 19 | if (s[i] == subs[j]) 20 | s[i] = le[j / 2]; 21 | } 22 | 23 | return (s); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - Compares two strings. 5 | * @s1: First string 6 | * @s2: Second string 7 | * 8 | * Return: 0 if similar, positive number if s1 > s2, otherwise negative number 9 | */ 10 | int _strcmp(char *s1, char *s2) 11 | { 12 | int i; 13 | 14 | for (i = 0; s1[i] != '\0' || s2[i] != '\0'; i++) 15 | { 16 | if (s1[i] != s2[i]) 17 | return (s1[i] - s2[i]); 18 | } 19 | 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x0F-function_pointers/1-array_iterator.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * array_iterator - execute a function pointer on each element of an array 5 | * @array: array of integers 6 | * @size: size of array 7 | * @action: function pointer 8 | */ 9 | void array_iterator(int *array, size_t size, void (*action)(int)) 10 | { 11 | size_t i; 12 | 13 | if (!array || !action) 14 | return; 15 | 16 | for (i = 0; i < size; i++) 17 | action(array[i]); 18 | } 19 | -------------------------------------------------------------------------------- /0x1A-hash_tables/README.md: -------------------------------------------------------------------------------- 1 | # 0x1A. C - Hash tables 2 | 3 | ## Description 4 | Here we are exposed to the concept of implementing hash maps in C 5 | 6 | ## Tasks 7 | * [0-hash_table_create.c](0-hash_table_create.c) 8 | * [1-djb2.c](1-djb2.c) 9 | * [2-key_index.c](2-key_index.c) 10 | * [3-hash_table_set.c](3-hash_table_set.c) 11 | * [4-hash_table_get.c](4-hash_table_get.c) 12 | * [5-hash_table_print.c](5-hash_table_print.c) 13 | * [6-hash_table_delete.c](6-hash_table_delete.c) 14 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | print_number(98); 12 | _putchar('\n'); 13 | print_number(402); 14 | _putchar('\n'); 15 | print_number(1024); 16 | _putchar('\n'); 17 | print_number(INT_MIN); 18 | _putchar('\n'); 19 | print_number(-98); 20 | _putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncpy - Copies a string. 5 | * @dest: Destination string 6 | * @src: Source string 7 | * @n: Number of bytes to copy 8 | * 9 | * Return: Pointer to dest 10 | */ 11 | char *_strncpy(char *dest, char *src, int n) 12 | { 13 | int i; 14 | 15 | for (i = 0; src[i] != '\0' && i < n; i++) 16 | dest[i] = src[i]; 17 | 18 | for (; n > i; i++) 19 | dest[i] = '\0'; 20 | 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncpy - Copies a string. 5 | * @dest: Destination string 6 | * @src: Source string 7 | * @n: Number of bytes to copy 8 | * 9 | * Return: Pointer to dest 10 | */ 11 | char *_strncpy(char *dest, char *src, int n) 12 | { 13 | int i; 14 | 15 | for (i = 0; src[i] != '\0' && i < n; i++) 16 | dest[i] = src[i]; 17 | 18 | for (; n > i; i++) 19 | dest[i] = '\0'; 20 | 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-calc.h: -------------------------------------------------------------------------------- 1 | #ifndef CALC_H 2 | #define CALC_H 3 | 4 | /** 5 | * struct op - Struct op 6 | * 7 | * @op: The operator 8 | * @f: The function associated 9 | */ 10 | typedef struct op 11 | { 12 | char *op; 13 | int (*f)(int a, int b); 14 | } op_t; 15 | int (*get_op_func(char *s))(int, int); 16 | int op_add(int a, int b); 17 | int op_sub(int a, int b); 18 | int op_mul(int a, int b); 19 | int op_div(int a, int b); 20 | int op_mod(int a, int b); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/7-get_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_nodeint_at_index - gets a node from a singly linked list 5 | * @head: pointer to head of the list 6 | * @index: data to store 7 | * Return: pointer to new elemnt 8 | */ 9 | listint_t *get_nodeint_at_index(listint_t *head, unsigned int index) 10 | { 11 | unsigned int i = 0; 12 | 13 | while (head && i < index) 14 | { 15 | i++; 16 | head = head->next; 17 | } 18 | return (head); 19 | } 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * rev_string - Reverses a string 5 | * @s: The string 6 | */ 7 | void rev_string(char *s) 8 | { 9 | int len = 0; 10 | int i, j; 11 | char temp; 12 | 13 | /* Get the length */ 14 | while (s[len]) 15 | len++; 16 | 17 | /* Swap each character */ 18 | i = len; 19 | while (--i >= len / 2) 20 | { 21 | j = len - i - 1; 22 | temp = s[j]; 23 | s[j] = s[i]; 24 | s[i] = temp; 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char str[] = "Expect the best. Prepare for the worst. Capitalize on what comes.\nhello world! hello-world 0123456hello world\thello world.hello world\n"; 12 | char *ptr; 13 | 14 | ptr = cap_string(str); 15 | printf("%s", ptr); 16 | printf("%s", str); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = is_palindrome("level"); 14 | printf("%d\n", r); 15 | r = is_palindrome("redder"); 16 | printf("%d\n", r); 17 | r = is_palindrome("test"); 18 | printf("%d\n", r); 19 | r = is_palindrome("step on no pets"); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/100-tests.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | import random 3 | import ctypes 4 | 5 | cops = ctypes.CDLL('./100-operations.so') 6 | a = random.randint(-111, 111) 7 | b = random.randint(-111, 111) 8 | print("{} + {} = {}".format(a, b, cops.add(a, b))) 9 | print("{} - {} = {}".format(a, b, cops.sub(a, b))) 10 | print("{} x {} = {}".format(a, b, cops.mul(a, b))) 11 | print("{} / {} = {}".format(a, b, cops.div(a, b))) 12 | print("{} % {} = {}".format(a, b, cops.mod(a, b))) 13 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/2-add_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_nodeint - adds a node to a singly linked list 5 | * @head: pointer to head of the list 6 | * @n: data to store 7 | * Return: pointer to new elemnt 8 | */ 9 | listint_t *add_nodeint(listint_t **head, const int n) 10 | { 11 | listint_t *new; 12 | 13 | new = malloc(sizeof(*new)); 14 | if (new) 15 | { 16 | new->n = n; 17 | new->next = *head; 18 | *head = new; 19 | } 20 | 21 | return (new); 22 | } 23 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/0-binary_to_uint.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * binary_to_uint - converts a binary to int 5 | * @s: pointer to binary chars 6 | * Return: int value or zero 7 | */ 8 | unsigned int binary_to_uint(const char *s) 9 | { 10 | unsigned int res = 0, i = 0; 11 | 12 | if (!s) 13 | return (0); 14 | for (; s[i]; i++) 15 | { 16 | if (s[i] < '0' || s[i] > '1') 17 | return (0); 18 | res = res << 1; 19 | res |= (s[i] - '0'); 20 | } 21 | 22 | return (res); 23 | } 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: 0 9 | */ 10 | int main(void) 11 | { 12 | int myrand; 13 | int count; 14 | int total; 15 | 16 | srand(time(NULL)); 17 | for (count = 0, total = 2772; total > 122; count++) 18 | { 19 | myrand = (rand() % 125) + 1; 20 | printf("%c", myrand); 21 | total -= myrand; 22 | } 23 | printf("%c", total); 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * puts_half - Prints half of a string, followed by a new line 5 | * @str: The string 6 | */ 7 | void puts_half(char *str) 8 | { 9 | int len = 0; 10 | int n; 11 | int isEven; 12 | 13 | while (str[len]) 14 | len++; 15 | 16 | isEven = len % 2 == 0; 17 | n = (isEven ? len : len - 1) / 2; 18 | n += isEven ? 0 : 1; 19 | while (n < len) 20 | { 21 | _putchar(str[n]); 22 | n++; 23 | } 24 | _putchar('\n'); 25 | } 26 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-set_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * set_bit - set the bit at a given index 5 | * @n: number to check 6 | * @index: index to check 7 | * Return: bit value or -1; 8 | */ 9 | int set_bit(unsigned long int *n, unsigned int index) 10 | { 11 | unsigned long int i = 1, len = 0; 12 | 13 | if (!n) 14 | return (-1); 15 | while (len++ < index) 16 | { 17 | if (len >= MAX_COUNT) 18 | return (-1); 19 | i = i << 1; 20 | } 21 | *n |= i; 22 | return (1); 23 | } 24 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-print_dog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dog.h" 4 | 5 | /** 6 | * print_dog - Prints a struct dog 7 | * @d: pointer to struct dog 8 | */ 9 | 10 | void print_dog(struct dog *d) 11 | { 12 | if (d != NULL) 13 | { 14 | printf("Name: "); 15 | d->name == NULL ? printf("(nil)\n") : printf("%s\n", d->name); 16 | printf("Age: %f\n", d->age); 17 | printf("Owner: "); 18 | d->owner == NULL ? printf("(nil)\n") : printf("%s\n", d->owner); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_sign - Prints the sign of a number 5 | * @n: The number to check 6 | * 7 | * Return: 1 if n is greater than zero, 8 | * 0 if n is zero, -1 if n is less than zero 9 | */ 10 | int print_sign(int n) 11 | { 12 | if (n == 0) 13 | { 14 | _putchar('0'); 15 | return (0); 16 | } 17 | else if (n > 0) 18 | { 19 | _putchar('+'); 20 | return (1); 21 | } 22 | else 23 | { 24 | _putchar('-'); 25 | return (-1); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | char *_strcat(char *dest, char *src); 3 | char *_strncat(char *dest, char *src, int n); 4 | char *_strncpy(char *dest, char *src, int n); 5 | int _strcmp(char *s1, char *s2); 6 | void reverse_array(int *a, int n); 7 | char *string_toupper(char *); 8 | char *cap_string(char *); 9 | char *leet(char *); 10 | char *rot13(char *); 11 | void print_number(int n); 12 | char *infinite_add(char *n1, char *n2, char *r, int size_r); 13 | void print_buffer(char *b, int size); 14 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/dog.h: -------------------------------------------------------------------------------- 1 | #ifndef DOG_H 2 | #define DOG_H 3 | 4 | /** 5 | * struct dog - structure definition of a dog 6 | * @name: character string 7 | * @age: integer 8 | * @owner: character string 9 | */ 10 | typedef struct dog 11 | { 12 | char *name; 13 | float age; 14 | char *owner; 15 | } dog_t; 16 | 17 | void init_dog(struct dog *d, char *name, float age, char *owner); 18 | void print_dog(struct dog *d); 19 | dog_t *new_dog(char *name, float age, char *owner); 20 | void free_dog(dog_t *d); 21 | #endif 22 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - compares src with dst 5 | * @s1: pointer to the first string 6 | * @s2: pointer to the second string 7 | * Return: -ve if dst < src 8 | * +ve if dst > src 9 | * 0 if src == dst 10 | */ 11 | 12 | int _strcmp(char *s1, char *s2) 13 | { 14 | int x = 0, diff = 0; 15 | 16 | while (diff == 0) 17 | { 18 | diff = s1[x] - s2[x]; 19 | if (s1[x] == '\0' || s2[x] == '\0') 20 | break; 21 | x++; 22 | } 23 | return (diff); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry block 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int count = 2; 11 | long int i = 1, j = 2; 12 | long int k; 13 | 14 | printf("%lu, ", i); 15 | while (count <= 50) 16 | { 17 | if (count == 50) 18 | { 19 | printf("%lu\n", j); 20 | } 21 | else 22 | { 23 | printf("%lu, ", j); 24 | } 25 | 26 | k = j; 27 | j += i; 28 | i = k; 29 | count++; 30 | } 31 | 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcpy - Copies the string pointed to by src, 5 | * including the terminating null byte (\0), 6 | * to the buffer pointed to by dest 7 | * @dest: The destination 8 | * @src: The source 9 | * 10 | * Return: The pointer to dest 11 | */ 12 | char *_strcpy(char *dest, char *src) 13 | { 14 | int len = 0; 15 | 16 | while (src[len]) 17 | { 18 | dest[len] = src[len]; 19 | len++; 20 | } 21 | dest[len] = '\0'; 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcpy - Copies the string pointed to by src, 5 | * including the terminating null byte (\0), 6 | * to the buffer pointed to by dest 7 | * @dest: The destination 8 | * @src: The source 9 | * 10 | * Return: The pointer to dest 11 | */ 12 | char *_strcpy(char *dest, char *src) 13 | { 14 | int len = 0; 15 | 16 | while (src[len]) 17 | { 18 | dest[len] = src[len]; 19 | len++; 20 | } 21 | dest[len] = '\0'; 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/2-calloc.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _calloc - allocates memory for an array, using malloc. 5 | * @nmemb: elements count 6 | * @size: size 7 | * 8 | * Return: a pointer to the allocated memory. 9 | */ 10 | void *_calloc(unsigned int nmemb, unsigned int size) 11 | { 12 | void *ptr; 13 | unsigned int i = 0; 14 | 15 | if (!nmemb || !size) 16 | return (NULL); 17 | ptr = malloc(nmemb * size); 18 | while (i < nmemb * size && ptr) 19 | ((char *)ptr)[i++] = 0; 20 | return (ptr); 21 | } 22 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-clear_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * clear_bit - clear the bit at a given index 5 | * @n: number to check 6 | * @index: index to clear 7 | * Return: bit value or -1; 8 | */ 9 | int clear_bit(unsigned long int *n, unsigned int index) 10 | { 11 | unsigned long int i = 1, len = 0; 12 | 13 | if (!n) 14 | return (-1); 15 | while (len++ < index) 16 | { 17 | if (len >= MAX_COUNT) 18 | return (-1); 19 | i = i << 1; 20 | } 21 | if (*n & i) 22 | *n ^= i; 23 | return (1); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-print_last_digit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_last_digit - Prints the last digit of a number 5 | * @n: The number to check 6 | * 7 | * Return: The last digit of n 8 | */ 9 | int print_last_digit(int n) 10 | { 11 | int lastDigit; 12 | 13 | if (n < 0) 14 | { 15 | lastDigit = -1 * (n % 10); 16 | _putchar(lastDigit + '0'); 17 | return (lastDigit); 18 | } 19 | else 20 | { 21 | lastDigit = n % 10; 22 | _putchar(lastDigit + '0'); 23 | return (lastDigit); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 7 | */ 8 | int main(void) 9 | { 10 | int i; 11 | 12 | for (i = 1; i <= 100; i++) 13 | { 14 | if ((i % 3 == 0) && (i % 5 == 0)) 15 | printf("FizzBuzz"); 16 | else if (i % 3 == 0) 17 | printf("Fizz"); 18 | else if (i % 5 == 0) 19 | printf("Buzz"); 20 | else 21 | printf("%d", i); 22 | 23 | if (i != 100) 24 | printf(" "); 25 | } 26 | printf("\n"); 27 | 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncpy - copies n bytes from src to destination 5 | * @src: pointer to the source string 6 | * @dst: pointer to the destination string 7 | * @n: number of bytes to copy 8 | * Return: pointer to destination 9 | */ 10 | 11 | char *_strncpy(char *dst, char *src, int n) 12 | { 13 | int x = 0; 14 | 15 | while (src[x] != '\0' && x < n) 16 | { 17 | dst[x] = src[x]; 18 | x++; 19 | } 20 | while (x < n) 21 | dst[x++] = '\0'; 22 | return (dst); 23 | } 24 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/3-array_range.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * array_range - creates an array of integers. 5 | * @min: lower bound 6 | * @max: upper bound 7 | * 8 | * Return: the pointer to the newly created array 9 | */ 10 | int *array_range(int min, int max) 11 | { 12 | int *p, i; 13 | 14 | if (min > max) 15 | return (NULL); 16 | 17 | p = malloc((max - min + 1) * sizeof(*p)); 18 | if (p == NULL) 19 | return (NULL); 20 | 21 | for (i = 0; min <= max; i++, min++) 22 | p[i] = min; 23 | 24 | return (p); 25 | } 26 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/100-reverse_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * reverse_listint - reverses a linked list 5 | * @h: head of the list 6 | * 7 | * Return: pointer to the reversed 8 | */ 9 | listint_t *reverse_listint(listint_t **h) 10 | { 11 | listint_t *tmp2, *tmp1; 12 | 13 | if (!h || !(*h)) 14 | return (NULL); 15 | tmp1 = (*h)->next; 16 | (*h)->next = NULL; 17 | while (tmp1) 18 | { 19 | tmp2 = *h; 20 | *h = tmp1; 21 | tmp1 = (*h)->next; 22 | (*h)->next = tmp2; 23 | } 24 | return (*h); 25 | } 26 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/104-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char buffer[] = "This is a string!\0And this is the rest of the #buffer :)\1\2\3\4\5\6\7#cisfun\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\x20\x21\x34\x56#pointersarefun #infernumisfun\n"; 12 | 13 | printf("%s\n", buffer); 14 | printf("---------------------------------\n"); 15 | print_buffer(buffer, sizeof(buffer)); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strchr - finds a character in a string 6 | * @s: pointer to the string 7 | * @c: the character to find 8 | * Return: pointer to c in s or NULL 9 | */ 10 | char *_strchr(char *s, char c) 11 | { 12 | unsigned int i; 13 | char *found = NULL; 14 | 15 | for (i = 0; s[i] != '\0'; i++) 16 | { 17 | if (s[i] == c) 18 | { 19 | found = &s[i]; 20 | break; 21 | } 22 | } 23 | if (c == '\0') 24 | found = &s[i]; 25 | return (found); 26 | } 27 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/0-print_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_list - prints all the elements of a list_t list. 5 | * @h: the list 6 | * 7 | * Return: the number of nodes 8 | */ 9 | size_t print_list(const list_t *h) 10 | { 11 | size_t nodes = 0; 12 | 13 | while (h) 14 | { 15 | if (h->str == NULL) 16 | { 17 | printf("[0] (nil)\n"); 18 | h = h->next; 19 | nodes++; 20 | continue; 21 | } 22 | 23 | printf("[%d] %s\n", h->len, h->str); 24 | h = h->next; 25 | nodes++; 26 | } 27 | 28 | return (nodes); 29 | } 30 | -------------------------------------------------------------------------------- /0x10-variadic_functions/0-sum_them_all.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * sum_them_all - returns the sum of all its parameters. 5 | * @n: count of extra parameters 6 | * 7 | * Return: sum of all parameters 8 | */ 9 | int sum_them_all(const unsigned int n, ...) 10 | { 11 | unsigned int i; 12 | int sum; 13 | va_list params; 14 | 15 | if (n == 0) 16 | return (0); 17 | 18 | sum = 0; 19 | va_start(params, n); 20 | 21 | for (i = 0; i < n; i++) 22 | sum += va_arg(params, int); 23 | va_end(params); 24 | 25 | return (sum); 26 | } 27 | -------------------------------------------------------------------------------- /0x1C-makefiles/README.md: -------------------------------------------------------------------------------- 1 | # 0x1C Makefile 2 | 3 | ## Description 4 | Getting to know the makefile 5 | 6 | ## Tasks 7 | * [0-Makefile](0-Makefile) 8 | * [100-Makefile](100-Makefile) 9 | * [1-Makefile](1-Makefile) 10 | * [2-Makefile](2-Makefile) 11 | * [3-Makefile](3-Makefile) 12 | * [4-Makefile](4-Makefile) 13 | * [5-island_perimeter.py](5-island_perimeter.py) 14 | * [5-main.py](5-main.py) 15 | * [main.c](main.c) 16 | * [main.o](main.o) 17 | * [m.h](m.h) 18 | * [README.md](README.md) 19 | * [school](school) 20 | * [school.c](school.c) 21 | * [school.o](school.o) 22 | -------------------------------------------------------------------------------- /0x00-hello_world/6-size.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | printf("%s%lu%s\n", "Size of a char: ", sizeof(char), " byte(s)"); 11 | printf("%s%lu%s\n", "Size of an int: ", sizeof(int), " byte(s)"); 12 | printf("%s%lu%s\n", "Size of a long int: ", sizeof(long), " byte(s)"); 13 | printf("%s%lu%s\n", "Size of a long long int: ", 14 | sizeof(long long), " byte(s)"); 15 | printf("%s%lu%s\n", "Size of a float: ", sizeof(float), " byte(s)"); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x03-debugging/3-main_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * main - takes a date and prints how many days are left in the year, taking 6 | * leap years into account 7 | * Return: 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | int month; 13 | int day; 14 | int year; 15 | 16 | month = 4; 17 | day = 01; 18 | year = 1997; 19 | 20 | printf("Date: %02d/%02d/%04d\n", month, day, year); 21 | 22 | day = convert_day(month, day); 23 | 24 | print_remaining_days(month, day, year); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x03-debugging/3-main_b.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * main - takes a date and prints how many days are left in the year, taking 6 | * leap years into account 7 | * Return: 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | int month; 13 | int day; 14 | int year; 15 | 16 | month = 2; 17 | day = 29; 18 | year = 2000; 19 | 20 | printf("Date: %02d/%02d/%04d\n", month, day, year); 21 | 22 | day = convert_day(month, day); 23 | 24 | print_remaining_days(month, day, year); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/102-magic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int n; 6 | int a[5]; 7 | int *p; 8 | 9 | a[2] = 1024; 10 | p = &n; 11 | /* 12 | * write your line of code here... 13 | * Remember: 14 | * - you are not allowed to use a 15 | * - you are not allowed to modify p 16 | * - only one statement 17 | * - you are not allowed to code anything else than this line of code 18 | */ 19 | *(p + 5) = 98; 20 | /* ...so that this prints 98\n */ 21 | printf("a[2] = %d\n", a[2]); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strchr - locates a character in a string. 6 | * @s: the string 7 | * @c: the character 8 | * 9 | * Return: a pointer to the first occurrence of the 10 | * character c in the string s, 11 | * or NULL if the character is not found 12 | */ 13 | char *_strchr(char *s, char c) 14 | { 15 | while (*s != '\0') 16 | { 17 | if (*s == c) 18 | return (s); 19 | else if (*(s + 1) == c) 20 | return (s + 1); 21 | s++; 22 | } 23 | 24 | return (s + 1); 25 | } 26 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strchr - locates a character in a string. 6 | * @s: the string 7 | * @c: the character 8 | * 9 | * Return: a pointer to the first occurrence of the 10 | * character c in the string s, 11 | * or NULL if the character is not found 12 | */ 13 | char *_strchr(char *s, char c) 14 | { 15 | while (*s != '\0') 16 | { 17 | if (*s == c) 18 | return (s); 19 | else if (*(s + 1) == c) 20 | return (s + 1); 21 | s++; 22 | } 23 | 24 | return (s + 1); 25 | } 26 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | 6 | /** 7 | * main - check the code 8 | * 9 | * Return: Always 0. 10 | */ 11 | int main(void) 12 | { 13 | list_t *head; 14 | 15 | head = NULL; 16 | add_node_end(&head, "Bob"); 17 | add_node_end(&head, "&"); 18 | add_node_end(&head, "Kris"); 19 | add_node_end(&head, "love"); 20 | add_node_end(&head, "asm"); 21 | print_list(head); 22 | free_list(head); 23 | head = NULL; 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strspn - finds number of characters 6 | * matching in the first part of s that are valid 7 | * @s: pointer to the string 8 | * @accept: the string with valid characters 9 | * Return: number of valid matches 10 | */ 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int i, count = 0; 14 | 15 | for (i = 0; s[i] != '\0'; i++) 16 | { 17 | if (strchr(accept, s[i])) 18 | count++; 19 | else 20 | break; 21 | } 22 | return (count); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_diagonal - Draws a diagonal line in the terminal 5 | * @n: Length of the line 6 | */ 7 | void print_diagonal(int n) 8 | { 9 | int i, c; 10 | 11 | if (n <= 0) 12 | { 13 | _putchar('\n'); 14 | return; 15 | } 16 | 17 | c = 0; 18 | while (n > 0) 19 | { 20 | i = c; 21 | while (i > 0) 22 | { 23 | _putchar(' '); 24 | i--; 25 | } 26 | _putchar('\\'); 27 | _putchar('\n'); 28 | c++; 29 | n--; 30 | } 31 | 32 | if (c < 1) 33 | _putchar('\n'); 34 | } 35 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcat - Concatenates two strings 5 | * @dest: Destination string 6 | * @src: Source string 7 | * 8 | * Return: A pointer to the resulting string dest 9 | */ 10 | char *_strcat(char *dest, char *src) 11 | { 12 | int destLen = 0; 13 | int srcLen = 0; 14 | 15 | while (dest[destLen] != '\0') 16 | destLen++; 17 | 18 | while (src[srcLen]) 19 | { 20 | dest[destLen] = src[srcLen]; 21 | srcLen++; 22 | destLen++; 23 | } 24 | dest[destLen] = '\0'; 25 | 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcat - Concatenates two strings 5 | * @dest: Destination string 6 | * @src: Source string 7 | * 8 | * Return: A pointer to the resulting string dest 9 | */ 10 | char *_strcat(char *dest, char *src) 11 | { 12 | int destLen = 0; 13 | int srcLen = 0; 14 | 15 | while (dest[destLen] != '\0') 16 | destLen++; 17 | 18 | while (src[srcLen]) 19 | { 20 | dest[destLen] = src[srcLen]; 21 | srcLen++; 22 | destLen++; 23 | } 24 | dest[destLen] = '\0'; 25 | 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-print_to_98.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * print_to_98 - Prints all natural numbers from n to 98 5 | * @n: The number to check 6 | */ 7 | void print_to_98(int n) 8 | { 9 | if (n > 98) 10 | { 11 | while (n >= 98) 12 | { 13 | printf("%d", n); 14 | if (n != 98) 15 | { 16 | printf(", "); 17 | } 18 | n--; 19 | } 20 | } 21 | else 22 | { 23 | while (n <= 98) 24 | { 25 | printf("%d", n); 26 | if (n != 98) 27 | { 28 | printf(", "); 29 | } 30 | n++; 31 | } 32 | } 33 | printf("\n"); 34 | } 35 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/100-atoi.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _atoi - converts string to integer 5 | * @s: the pinter to the string 6 | * Return: the integer value of s 7 | */ 8 | int _atoi(char *s) 9 | { 10 | unsigned int res = 0; 11 | int sign = 1, i; 12 | 13 | for (i = 0; s[i] != '\0'; i++) 14 | { 15 | if (s[i] == '-') 16 | sign *= -1; 17 | else if ('0' <= s[i] && s[i] <= '9') 18 | break; 19 | } 20 | while ('0' <= s[i] && s[i] <= '9') 21 | { 22 | res = (res * 10) + (s[i] - '0'); 23 | i++; 24 | } 25 | return ((int)(res * sign)); 26 | } 27 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncat - Concatenates two strings. 5 | * @dest: Destination string 6 | * @src: Source string 7 | * @n: Number of bytes to use from src 8 | * 9 | * Return: A pointer to the resulting string dest 10 | */ 11 | char *_strncat(char *dest, char *src, int n) 12 | { 13 | int destLen, i; 14 | 15 | for (destLen = 0; dest[destLen] != '\0'; destLen++) 16 | ; 17 | 18 | for (i = 0; src[i] != '\0' && n > 0; i++, n--, destLen++) 19 | { 20 | dest[destLen] = src[i]; 21 | } 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncat - Concatenates two strings. 5 | * @dest: Destination string 6 | * @src: Source string 7 | * @n: Number of bytes to use from src 8 | * 9 | * Return: A pointer to the resulting string dest 10 | */ 11 | char *_strncat(char *dest, char *src, int n) 12 | { 13 | int destLen, i; 14 | 15 | for (destLen = 0; dest[destLen] != '\0'; destLen++) 16 | ; 17 | 18 | for (i = 0; src[i] != '\0' && n > 0; i++, n--, destLen++) 19 | { 20 | dest[destLen] = src[i]; 21 | } 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcat - concatenates src to destination 5 | * @src: pointer to the source string 6 | * @dst: pointer to the destination string 7 | * Return: pointer to destination 8 | */ 9 | 10 | char *_strcat(char *dst, char *src) 11 | { 12 | int x = 0, y = 0; 13 | 14 | /* Get the length of destination */ 15 | while (dst[y++] != '\0') 16 | continue; 17 | y--; 18 | /* concatenate */ 19 | while (src[x] != '\0') 20 | { 21 | dst[y++] = src[x]; 22 | x++; 23 | } 24 | dst[y] = '\0'; 25 | return (dst); 26 | } 27 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | void print_uint(unsigned int n); 4 | 5 | /** 6 | * print_number - Prints an integer 7 | * @n: The integer to print 8 | */ 9 | void print_number(int n) 10 | { 11 | if (n < 0) 12 | { 13 | _putchar('-'); 14 | n = -n; 15 | } 16 | 17 | print_uint((unsigned int) n); 18 | } 19 | 20 | /** 21 | * print_uint - Prints an unsigned integer 22 | * @n: The unsigned int to print 23 | */ 24 | void print_uint(unsigned int n) 25 | { 26 | if (n / 10 != 0) 27 | print_uint(n / 10); 28 | _putchar(n % 10 + '0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x08-recursion/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _sqrt_recursion(1); 14 | printf("%d\n", r); 15 | r = _sqrt_recursion(1024); 16 | printf("%d\n", r); 17 | r = _sqrt_recursion(16); 18 | printf("%d\n", r); 19 | r = _sqrt_recursion(17); 20 | printf("%d\n", r); 21 | r = _sqrt_recursion(25); 22 | printf("%d\n", r); 23 | r = _sqrt_recursion(-1); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/2-add_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_dnodeint - adds a node at the beginning of a list 5 | * @head: head of the list 6 | * @n: data to add 7 | * Return: pointer to new node 8 | */ 9 | 10 | dlistint_t *add_dnodeint(dlistint_t **head, const int n) 11 | { 12 | dlistint_t *new; 13 | 14 | if (!head) 15 | return (0); 16 | new = malloc(sizeof(dlistint_t)); 17 | if (!new) 18 | return (0); 19 | new->n = n; 20 | if (*head) 21 | { 22 | (*head)->prev = new; 23 | new->next = *head; 24 | } 25 | *head = new; 26 | return (new); 27 | } 28 | -------------------------------------------------------------------------------- /0x03-debugging/2-largest_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * largest_number - returns the largest of 3 numbers 5 | * @a: first integer 6 | * @b: second integer 7 | * @c: third integer 8 | * Return: largest number 9 | */ 10 | 11 | int largest_number(int a, int b, int c) 12 | { 13 | int largest; 14 | 15 | if (a > b) 16 | { 17 | if (a > c) 18 | { 19 | largest = a; 20 | } 21 | else 22 | { 23 | largest = c; 24 | } 25 | } 26 | else if (b > c) 27 | { 28 | largest = b; 29 | } 30 | else 31 | { 32 | largest = c; 33 | } 34 | 35 | return (largest); 36 | } 37 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | void print_uint(unsigned int n); 4 | 5 | /** 6 | * print_number - Prints an integer 7 | * @n: The integer to print 8 | */ 9 | void print_number(int n) 10 | { 11 | if (n < 0) 12 | { 13 | _putchar('-'); 14 | n = -n; 15 | } 16 | 17 | print_uint((unsigned int) n); 18 | } 19 | 20 | /** 21 | * print_uint - Prints an unsigned integer 22 | * @n: The unsigned int to print 23 | */ 24 | void print_uint(unsigned int n) 25 | { 26 | if (n / 10 != 0) 27 | print_uint(n / 10); 28 | _putchar(n % 10 + '0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98] = "Hello "; 12 | char s2[] = "World!\n"; 13 | char *ptr; 14 | 15 | printf("%s\n", s1); 16 | printf("%s", s2); 17 | ptr = _strncat(s1, s2, 1); 18 | printf("%s\n", s1); 19 | printf("%s", s2); 20 | printf("%s\n", ptr); 21 | ptr = _strncat(s1, s2, 1024); 22 | printf("%s", s1); 23 | printf("%s", s2); 24 | printf("%s", ptr); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x08-recursion/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _pow_recursion(1, 10); 14 | printf("%d\n", r); 15 | r = _pow_recursion(1024, 0); 16 | printf("%d\n", r); 17 | r = _pow_recursion(2, 16); 18 | printf("%d\n", r); 19 | r = _pow_recursion(5, 2); 20 | printf("%d\n", r); 21 | r = _pow_recursion(5, -2); 22 | printf("%d\n", r); 23 | r = _pow_recursion(-5, 3); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x0F-function_pointers/2-int_index.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * int_index - Function that searches for an integer 5 | * @array: array of integers 6 | * @size: size of array 7 | * @cmp: function pointer 8 | * Return: index of first element that matches with `cmp`, or -1 if none found 9 | */ 10 | int int_index(int *array, int size, int (*cmp)(int)) 11 | { 12 | int i; 13 | 14 | if (size < 1 || array == NULL || cmp == NULL) 15 | return (-1); 16 | 17 | for (i = 0; i < size; i++) 18 | { 19 | if (cmp(array[i])) 20 | return (i); 21 | } 22 | 23 | return (-1); 24 | } 25 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/main.h: -------------------------------------------------------------------------------- 1 | #ifndef LIST_H 2 | #define LIST_H 3 | #include 4 | #include 5 | #include 6 | #define MAX_COUNT (sizeof(unsigned long int) * 8) 7 | 8 | int _putchar(char c); 9 | unsigned int binary_to_uint(const char *b); 10 | void print_binary(unsigned long int n); 11 | int get_bit(unsigned long int n, unsigned int index); 12 | int set_bit(unsigned long int *n, unsigned int index); 13 | int clear_bit(unsigned long int *n, unsigned int index); 14 | unsigned int flip_bits(unsigned long int n, unsigned long int m); 15 | int get_endianness(void); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-print_triangle.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_triangle - Prints a triangle, followed by a new line 5 | * @size: The size of the triangle 6 | */ 7 | void print_triangle(int size) 8 | { 9 | int c, i, j; 10 | 11 | c = 0; 12 | i = size - 1; 13 | while (c < size) 14 | { 15 | i = size - 1 - c; 16 | j = c + 1; 17 | while (i > 0) 18 | { 19 | _putchar(' '); 20 | i--; 21 | } 22 | while (j > 0) 23 | { 24 | _putchar('#'); 25 | j--; 26 | } 27 | _putchar('\n'); 28 | c++; 29 | } 30 | 31 | if (size <= 0) 32 | _putchar('\n'); 33 | } 34 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - Entry point 4 | * 5 | * Return: 0 (Success) 6 | */ 7 | int main(void) 8 | { 9 | int i = '0'; 10 | int j = '0'; 11 | 12 | while (i <= '9') 13 | { 14 | while (j <= '9') 15 | { 16 | if (!(i > j || i == j)) 17 | { 18 | putchar(i); 19 | putchar(j); 20 | if (i == '8' && j == '9') 21 | { 22 | putchar('\n'); 23 | } 24 | else 25 | { 26 | putchar(','); 27 | putchar(' '); 28 | } 29 | } 30 | j++; 31 | } 32 | j = '0'; 33 | i++; 34 | } 35 | 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/README.md: -------------------------------------------------------------------------------- 1 | # 0x17. C - Doubly linked lists 2 | 3 | ## Description 4 | Further data structures in C. 5 | Doubly linked lists - traversible forward and backward. 6 | 7 | ## Tasks 8 | * [0-print_dlistint.c](0-print_dlistint.c) 9 | * [1-dlistint_len.c](1-dlistint_len.c) 10 | * [2-add_dnodeint.c](2-add_dnodeint.c) 11 | * [3-add_dnodeint_end.c](3-add_dnodeint_end.c) 12 | * [4-free_dlistint.c](4-free_dlistint.c) 13 | * [5-get_dnodeint.c](5-get_dnodeint.c) 14 | * [6-sum_dlistint.c](6-sum_dlistint.c) 15 | * [7-insert_dnodeint.c](7-insert_dnodeint.c) 16 | * [8-delete_dnodeint.c](8-delete_dnodeint.c) 17 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i, j, k, l; 11 | 12 | for (i = 0; i < 1000; i++) 13 | { 14 | j = i / 100; /* hundreds */ 15 | k = (i / 10) % 10; /* tens */ 16 | l = i % 10; /* singles */ 17 | 18 | if (j < k && k < l) 19 | { 20 | putchar(j + '0'); 21 | putchar(k + '0'); 22 | putchar(l + '0'); 23 | 24 | if (i < 700) 25 | { 26 | putchar(44); 27 | putchar(32); 28 | } 29 | } 30 | } 31 | putchar('\n'); 32 | 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strpbrk - searches a string for any of a set of bytes. 6 | * @s: the string 7 | * @accept: a set of bytes 8 | * 9 | * Return: a pointer to the byte in s that matches one of the bytes 10 | * in accept, or NULL if no such byte is found 11 | */ 12 | char *_strpbrk(char *s, char *accept) 13 | { 14 | int i, j; 15 | 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (s[i] == accept[j]) 21 | return (&s[i]); 22 | } 23 | } 24 | 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strpbrk - searches a string for any of a set of bytes. 6 | * @s: the string 7 | * @accept: a set of bytes 8 | * 9 | * Return: a pointer to the byte in s that matches one of the bytes 10 | * in accept, or NULL if no such byte is found 11 | */ 12 | char *_strpbrk(char *s, char *accept) 13 | { 14 | int i, j; 15 | 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (s[i] == accept[j]) 21 | return (&s[i]); 22 | } 23 | } 24 | 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-flip_bits.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * flip_bits - returns no of bits to flip for two numbers to match 5 | * @n: first number 6 | * @m: second number 7 | * Return: number of bits to flip; 8 | */ 9 | unsigned int flip_bits(unsigned long int n, unsigned long int m) 10 | { 11 | unsigned long int tmp, i = 1, count = 0; 12 | 13 | /* find the different bits */ 14 | tmp = n ^ m; 15 | /* count ones in tmp */ 16 | while (tmp >= i) 17 | { 18 | if (i & tmp) 19 | count++; 20 | if (count >= MAX_COUNT) 21 | return (count); 22 | i = i << 1; 23 | } 24 | return (count); 25 | } 26 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * _strpbrk - locates the first occurrence in the string s 7 | * of any of the bytes in the string accept 8 | * @s: pointer to the string 9 | * @accept: the string with valid characters 10 | * Return: pointer to the matching byte 11 | */ 12 | char *_strpbrk(char *s, char *accept) 13 | { 14 | int i; 15 | char *found = NULL; 16 | 17 | for (i = 0; s[i] != '\0'; i++) 18 | { 19 | if (strchr(accept, s[i])) 20 | { 21 | found = &s[i]; 22 | break; 23 | } 24 | } 25 | return (found); 26 | } 27 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | 4 | /** 5 | * print_numbers - prints numbers, followed by a new line. 6 | * @separator: the string to be printed between numbers 7 | * @n: count of parameters 8 | */ 9 | void print_numbers(const char *separator, const unsigned int n, ...) 10 | { 11 | unsigned int i; 12 | va_list list; 13 | 14 | va_start(list, n); 15 | for (i = 0; i < n; i++) 16 | { 17 | printf("%d", va_arg(list, int)); 18 | if (i != (n - 1) && separator != NULL) 19 | printf("%s", separator); 20 | } 21 | printf("\n"); 22 | 23 | va_end(list); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: 0 (Success) 9 | */ 10 | int main(void) 11 | { 12 | int n; 13 | int lastDigit; 14 | char *resultEnd; 15 | 16 | srand(time(0)); 17 | n = rand() - RAND_MAX / 2; 18 | lastDigit = n % 10; 19 | 20 | if (lastDigit == 0) 21 | resultEnd = "0"; 22 | else if (lastDigit > 5) 23 | resultEnd = "greater than 5"; 24 | else 25 | resultEnd = "less than 6 and not 0"; 26 | 27 | printf("Last digit of %d is %d and is %s\n", n, lastDigit, resultEnd); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x0A-argc_argv/4-add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - adds positive numbers. 6 | * @argc: argument count 7 | * @argv: arguments 8 | * 9 | * Return: 0 10 | */ 11 | int main(int argc, char **argv) 12 | { 13 | int i, n, sum = 0; 14 | char *flag; 15 | 16 | if (argc < 2) 17 | { 18 | printf("0\n"); 19 | return (0); 20 | } 21 | 22 | for (i = 1; argv[i]; i++) 23 | { 24 | n = strtol(argv[i], &flag, 10); 25 | if (*flag) 26 | { 27 | printf("Error\n"); 28 | return (1); 29 | } 30 | else 31 | { 32 | sum += n; 33 | } 34 | } 35 | printf("%d\n", sum); 36 | 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/102-print_comb5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | int i, j; 11 | 12 | for (i = 0; i <= 99; i++) 13 | { 14 | for (j = 0; j <= 99; j++) 15 | { 16 | if (i < j && i != j) 17 | { 18 | putchar((i / 10) + '0'); 19 | putchar((i % 10) + '0'); 20 | putchar(' '); 21 | putchar((j / 10) + '0'); 22 | putchar((j % 10) + '0'); 23 | if (i != 98 || j != 99) 24 | { 25 | putchar(','); 26 | putchar(' '); 27 | } 28 | } 29 | } 30 | } 31 | putchar('\n'); 32 | 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/0-linear.c: -------------------------------------------------------------------------------- 1 | #include "search_algos.h" 2 | 3 | /** 4 | * linear_search - searches for a value in an array of 5 | * integers using the Linear search algorithm 6 | * 7 | * @array: input array 8 | * @size: size of the array 9 | * @value: value to search in 10 | * Return: Always EXIT_SUCCESS 11 | */ 12 | int linear_search(int *array, size_t size, int value) 13 | { 14 | int i; 15 | 16 | if (array == NULL) 17 | return (-1); 18 | 19 | for (i = 0; i < (int)size; i++) 20 | { 21 | printf("Value checked array[%u] = [%d]\n", i, array[i]); 22 | if (value == array[i]) 23 | return (i); 24 | } 25 | return (-1); 26 | } 27 | -------------------------------------------------------------------------------- /0x0B-malloc_free/0-create_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * create_array - creates an array of chars, 6 | * and initializes it with a specific char. 7 | * @size: the size of the array 8 | * @c: initial value 9 | * 10 | * Return: a pointer to the array, or NULL if it fails 11 | */ 12 | char *create_array(unsigned int size, char c) 13 | { 14 | char *array; 15 | unsigned int i; 16 | 17 | if (size == 0) 18 | return (NULL); 19 | 20 | array = (char *)malloc(sizeof(char) * size); 21 | if (array == NULL) 22 | return (NULL); 23 | 24 | for (i = 0; i < size; i++) 25 | array[i] = c; 26 | 27 | return (array); 28 | } 29 | -------------------------------------------------------------------------------- /0x1A-hash_tables/4-hash_table_get.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_table_get - retrieve value using key in a hash table 5 | * @ht: the hash table 6 | * @key: key to retrieve 7 | * Return: value of key in ht or null 8 | */ 9 | char *hash_table_get(const hash_table_t *ht, const char *key) 10 | { 11 | unsigned long int i; 12 | hash_node_t *tmp; 13 | 14 | if (!ht || !key) 15 | return (NULL); 16 | i = key_index((unsigned char *)key, ht->size); 17 | tmp = ht->array[i]; 18 | if (tmp) 19 | { 20 | while (strcmp(tmp->key, key) != 0) 21 | tmp = tmp->next; 22 | if (tmp) 23 | return (tmp->value); 24 | } 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-get_op_func.c: -------------------------------------------------------------------------------- 1 | #include "3-calc.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * get_op_func - select the correct operation function asked by user 7 | * @s: operator argument 8 | * Return: function pointer corresponding to operator given 9 | */ 10 | int (*get_op_func(char *s))(int, int) 11 | { 12 | op_t ops[] = { 13 | {"+", op_add}, 14 | {"-", op_sub}, 15 | {"*", op_mul}, 16 | {"/", op_div}, 17 | {"%", op_mod}, 18 | {NULL, NULL} 19 | }; 20 | int i; 21 | 22 | i = 0; 23 | while (i < 5) 24 | { 25 | if (ops[i].op[0] == s[0]) 26 | return (ops[i].f); 27 | i++; 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/100-rot13.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * rot13 - encodes a string using rot13. 5 | * @s: The string 6 | * 7 | * Return: The string 8 | */ 9 | char *rot13(char *s) 10 | { 11 | int i, j; 12 | char r[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"; 13 | char alpha[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 14 | char boolean; 15 | 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | boolean = 0; 19 | for (j = 0; alpha[j] != '\0' && boolean == 0; j++) 20 | { 21 | if (s[i] == alpha[j]) 22 | { 23 | s[i] = r[j]; 24 | boolean = 1; 25 | } 26 | } 27 | } 28 | 29 | return (s); 30 | } 31 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/3-add_nodeint_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_nodeint_end - adds a node to a singly linked list 5 | * @head: pointer to head of the list 6 | * @n: data to store 7 | * Return: pointer to new elemnt 8 | */ 9 | listint_t *add_nodeint_end(listint_t **head, const int n) 10 | { 11 | listint_t *new; 12 | listint_t *tmp = *head; 13 | 14 | new = malloc(sizeof(*new)); 15 | if (new) 16 | { 17 | new->n = n; 18 | new->next = NULL; 19 | if (!(*head)) 20 | { 21 | *head = new; 22 | return (new); 23 | } 24 | while (tmp->next) 25 | tmp = tmp->next; 26 | tmp->next = new; 27 | } 28 | 29 | return (new); 30 | } 31 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/3-add_dnodeint_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_dnodeint_end - adds node at the end 5 | * 6 | * @head: pointer to the head 7 | * @n: data to add 8 | * Return: pointer to new node 9 | */ 10 | 11 | dlistint_t *add_dnodeint_end(dlistint_t **head, const int n) 12 | { 13 | dlistint_t *new, *h; 14 | 15 | if (!head) 16 | return (0); 17 | new = malloc(sizeof(dlistint_t)); 18 | if (!new) 19 | return (0); 20 | new->n = n; 21 | if (!(*head)) 22 | { 23 | *head = new; 24 | return (new); 25 | } 26 | h = *head; 27 | while (h->next) 28 | h = h->next; 29 | new->prev = h; 30 | h->next = new; 31 | return (new); 32 | } 33 | -------------------------------------------------------------------------------- /0x1A-hash_tables/0-hash_table_create.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_table_create - creates a hash table 5 | * @size: size of the table 6 | * Return: pointer to the table 7 | */ 8 | 9 | hash_table_t *hash_table_create(unsigned long int size) 10 | { 11 | hash_table_t *res = malloc(sizeof(*res)); 12 | hash_node_t **arr; 13 | unsigned long int i = 0; 14 | 15 | if (!res) 16 | return (0); 17 | arr = malloc(size * sizeof(*arr)); 18 | if (!arr) 19 | { 20 | free(res); 21 | return (0); 22 | } 23 | while (i < size) 24 | { 25 | arr[i] = NULL; 26 | i++; 27 | } 28 | res->size = size; 29 | res->array = arr; 30 | return (res); 31 | } 32 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * print_diagsums - prints the sum of the two diagonals of a 6 | * square matrix of integers. 7 | * @a: the array 8 | * @size: the size of the array 9 | */ 10 | void print_diagsums(int *a, int size) 11 | { 12 | int i, row; 13 | int firstDiagonalSum = 0; 14 | int secondDiagonalSum = 0; 15 | int total = size * size; 16 | 17 | for (i = 0; i < total; i += size) 18 | { 19 | row = i / size; 20 | firstDiagonalSum += a[i + row]; 21 | secondDiagonalSum += a[i + size - row - 1]; 22 | } 23 | 24 | printf("%d, %d\n", firstDiagonalSum, secondDiagonalSum); 25 | } 26 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tmp/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strncat - concatenates src to destination 5 | * taking at most n characters 6 | * @src: pointer to the source string 7 | * @dst: pointer to the destination string 8 | * @n: number of bytes to copy 9 | * Return: pointer to destination 10 | */ 11 | 12 | char *_strncat(char *dst, char *src, int n) 13 | { 14 | int x = 0, y = 0; 15 | 16 | /* Get the length of destination */ 17 | while (dst[y++] != '\0') 18 | continue; 19 | y--; 20 | /* concatenate */ 21 | while (src[x] != '\0' && x < n) 22 | { 23 | dst[y++] = src[x]; 24 | x++; 25 | } 26 | dst[y] = '\0'; 27 | return (dst); 28 | } 29 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int c3[3][3] = { 12 | {0, 1, 5}, 13 | {10, 11, 12}, 14 | {1000, 101, 102}, 15 | }; 16 | int c5[5][5] = { 17 | {0, 1, 5, 12124, 1234}, 18 | {10, 11, 12, 123521, 12512}, 19 | {1000, 101, 102, 12545, 214543435}, 20 | {100, 1012451, 11102, 12545, 214543435}, 21 | {10, 12401, 10452, 11542545, 1214543435}, 22 | }; 23 | print_diagsums((int *)c3, 3); 24 | print_diagsums((int *)c5, 5); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/README.md: -------------------------------------------------------------------------------- 1 | # Bitwise Operations 2 | 3 | ## Description 4 | 5 | Under this Directory Tasks will help explore various uses of the following operators 6 | * & : Bitwise And Operator 7 | * | : Bitwise Or Operator 8 | * ~ : Bitwise NOT Operator 9 | * ^ : Bitwise ExOr Operator 10 | * >> : Bitwise Right Shift Operator 11 | * << : Bitwise Left Shift Operator 12 | 13 | ## Tasks 14 | 15 | * [0-binary_to_uint.c](0-binary_to_uint.c) 16 | * [1-print_binary.c](1-print_binary.c) 17 | * [2-get_bit.c](2-get_bit.c) 18 | * [3-set_bit.c](3-set_bit.c) 19 | * [4-clear_bit.c](4-clear_bit.c) 20 | * [5-flip_bits.c](5-flip_bits.c) 21 | * [100-get_endianness.c](100-get_endianness.c) 22 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strspn - gets the length of a prefix substring. 5 | * @s: the string 6 | * @accept: prefix 7 | * 8 | * Return: the number of bytes in the initial segment of s 9 | * which consist only of bytes from accept 10 | */ 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int length = 0; 14 | int i, j; 15 | 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (s[i] == accept[j]) 21 | { 22 | length++; 23 | break; 24 | } 25 | } 26 | 27 | if (accept[j] == '\0') 28 | break; 29 | } 30 | 31 | return (length); 32 | } 33 | -------------------------------------------------------------------------------- /0x09-static_libraries/sources/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strspn - gets the length of a prefix substring. 5 | * @s: the string 6 | * @accept: prefix 7 | * 8 | * Return: the number of bytes in the initial segment of s 9 | * which consist only of bytes from accept 10 | */ 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int length = 0; 14 | int i, j; 15 | 16 | for (i = 0; s[i] != '\0'; i++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (s[i] == accept[j]) 21 | { 22 | length++; 23 | break; 24 | } 25 | } 26 | 27 | if (accept[j] == '\0') 28 | break; 29 | } 30 | 31 | return (length); 32 | } 33 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/3-add_node_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_node_end - adds a node to a singly linked list 5 | * @head: pointer to head of the list 6 | * @str: data to store 7 | * Return: pointer to new elemnt 8 | */ 9 | list_t *add_node_end(list_t **head, const char *str) 10 | { 11 | list_t *new; 12 | list_t *tmp = *head; 13 | 14 | new = malloc(sizeof(*new)); 15 | if (new) 16 | { 17 | new->str = strdup(str); 18 | new->len = strlen(str); 19 | new->next = NULL; 20 | if (!(*head)) 21 | { 22 | *head = new; 23 | return (new); 24 | } 25 | while (tmp->next) 26 | tmp = tmp->next; 27 | tmp->next = new; 28 | } 29 | 30 | return (new); 31 | } 32 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-times_table.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * times_table - Prints the 9 times table, starting with 0 5 | */ 6 | void times_table(void) 7 | { 8 | int i, j, n; 9 | 10 | for (i = 0; i <= 9; i++) 11 | { 12 | for (j = 0; j <= 9; j++) 13 | { 14 | n = i * j; 15 | 16 | if (n > 9) 17 | { 18 | _putchar(n / 10 + '0'); 19 | _putchar(n % 10 + '0'); 20 | } 21 | else if (j != 0) 22 | { 23 | _putchar(' '); 24 | _putchar(n + '0'); 25 | } 26 | else 27 | { 28 | _putchar(n + '0'); 29 | } 30 | 31 | if (j != 9) 32 | { 33 | _putchar(','); 34 | _putchar(' '); 35 | } 36 | } 37 | _putchar('\n'); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/102-magic-test.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int n; 6 | int a[5]; 7 | int *p; 8 | 9 | a[2] = 1024; 10 | p = &n; 11 | /* 12 | * write your line of code here... 13 | * Remember: 14 | * - you are not allowed to use a 15 | * - you are not allowed to modify p 16 | * - only one statement 17 | * - you are not allowed to code anything else than this line of code 18 | */ 19 | // *(p + 5) = 98; 20 | 21 | printf("%p\n", &a[2]); 22 | printf("%p\n", p); 23 | for (int i = 0; i < 5; i++) 24 | printf("%p\n", p + (i + 1)); 25 | /* ...so that this prints 98\n */ 26 | printf("a[2] = %d\n", a[2]); 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x0F-function_pointers/100-main_opcodes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main- Entry point 6 | *@argc: the number of parameters. 7 | *@argv: the parameeters in the case the number ob bytes. 8 | * Return: 0 in succes 9 | */ 10 | int main(int argc, char *argv[]) 11 | { 12 | int i, n; 13 | 14 | 15 | if (argc != 2) 16 | { 17 | printf("Error\n"); 18 | return (1); 19 | } 20 | n = atoi(argv[1]); 21 | if (n < 0) 22 | { 23 | printf("Error\n"); 24 | exit(2); 25 | } 26 | 27 | for (i = 0; i < n; i++) 28 | { 29 | printf("%02hhx", *((char *)main + i)); 30 | if (i < n - 1) 31 | printf(" "); 32 | else 33 | printf("\n"); 34 | } 35 | 36 | return (0); 37 | } 38 | -------------------------------------------------------------------------------- /0x08-recursion/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = is_prime_number(1); 14 | printf("%d\n", r); 15 | r = is_prime_number(1024); 16 | printf("%d\n", r); 17 | r = is_prime_number(16); 18 | printf("%d\n", r); 19 | r = is_prime_number(17); 20 | printf("%d\n", r); 21 | r = is_prime_number(25); 22 | printf("%d\n", r); 23 | r = is_prime_number(-1); 24 | printf("%d\n", r); 25 | r = is_prime_number(113); 26 | printf("%d\n", r); 27 | r = is_prime_number(7919); 28 | printf("%d\n", r); 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - check the code. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = print_sign(98); 13 | _putchar(','); 14 | _putchar(' '); 15 | _putchar(r + '0'); 16 | _putchar('\n'); 17 | r = print_sign(0); 18 | _putchar(','); 19 | _putchar(' '); 20 | _putchar(r + '0'); 21 | _putchar('\n'); 22 | r = print_sign(0xff); 23 | _putchar(','); 24 | _putchar(' '); 25 | _putchar(r + '0'); 26 | _putchar('\n'); 27 | r = print_sign(-1); 28 | _putchar(','); 29 | _putchar(' '); 30 | _putchar(r + '0'); 31 | _putchar('\n'); 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char board[8][8] = { 12 | {'r', 'k', 'b', 'q', 'k', 'b', 'k', 'r'}, 13 | {'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'}, 14 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 15 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 16 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 17 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 18 | {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'}, 19 | {'R', 'K', 'B', 'Q', 'K', 'B', 'K', 'R'}, 20 | }; 21 | print_chessboard(board); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-main.c: -------------------------------------------------------------------------------- 1 | #include "3-calc.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - main function 7 | * @argc: argument count 8 | * @argv: string of arguments in array 9 | * Return: 0 10 | */ 11 | int main(int argc, char *argv[]) 12 | { 13 | int a, b; 14 | int (*o)(int, int); 15 | 16 | if (argc != 4) 17 | { 18 | printf("Error\n"); 19 | exit(98); 20 | } 21 | if (argv[2][1] != '\0') 22 | { 23 | printf("Error\n"); 24 | exit(99); 25 | } 26 | 27 | o = get_op_func(argv[2]); 28 | if (o == NULL) 29 | { 30 | printf("Error\n"); 31 | exit(99); 32 | } 33 | 34 | a = atoi(argv[1]); 35 | b = atoi(argv[3]); 36 | 37 | printf("%d\n", o(a, b)); 38 | 39 | return (0); 40 | } 41 | -------------------------------------------------------------------------------- /0x1A-hash_tables/6-hash_table_delete.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | void free_node(hash_node_t *); 4 | 5 | /** 6 | * hash_table_delete - delete a hash table 7 | * @ht: the hash table 8 | */ 9 | void hash_table_delete(hash_table_t *ht) 10 | { 11 | unsigned long int i = 0; 12 | 13 | if (!ht) 14 | return; 15 | while (i < ht->size) 16 | { 17 | free_node(ht->array[i]); 18 | i++; 19 | } 20 | free(ht->array); 21 | free(ht); 22 | } 23 | 24 | /** 25 | * free_node - frees a node 26 | * @n: node pointer 27 | */ 28 | void free_node(hash_node_t *n) 29 | { 30 | hash_node_t *tmp; 31 | 32 | while (n) 33 | { 34 | tmp = n->next; 35 | free(n->value); 36 | free(n->key); 37 | free(n); 38 | n = tmp; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * main - check the code 8 | * 9 | * Return: Always 0. 10 | */ 11 | int main(void) 12 | { 13 | char *c; 14 | int *i; 15 | float *f; 16 | double *d; 17 | 18 | c = malloc_checked(sizeof(char) * 1024); 19 | printf("%p\n", (void *)c); 20 | i = malloc_checked(sizeof(int) * 402); 21 | printf("%p\n", (void *)i); 22 | f = malloc_checked(sizeof(float) * 100000000); 23 | printf("%p\n", (void *)f); 24 | d = malloc_checked(INT_MAX); 25 | printf("%p\n", (void *)d); 26 | free(c); 27 | free(i); 28 | free(f); 29 | free(d); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x10-variadic_functions/2-print_strings.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | 4 | /** 5 | * print_strings - prints strings, followed by a new line. 6 | * @separator: the string to be printed between the strings 7 | * @n: count of parameters 8 | */ 9 | void print_strings(const char *separator, const unsigned int n, ...) 10 | { 11 | unsigned int i; 12 | va_list list; 13 | char *hold; 14 | 15 | va_start(list, n); 16 | for (i = 0; i < n; i++) 17 | { 18 | hold = va_arg(list, char*); 19 | if (hold == NULL) 20 | printf("(nil)"); 21 | else 22 | printf("%s", hold); 23 | if (i != (n - 1) && separator != NULL) 24 | printf("%s", separator); 25 | } 26 | printf("\n"); 27 | 28 | va_end(list); 29 | } 30 | --------------------------------------------------------------------------------