├── 0x00-hello_world ├── 0-preprocessor └── README.md ├── 0x01-variables_if_else_while ├── 0-positive_or_negative.c ├── 1-last_digit.c ├── 100-print_comb3.c ├── 101-print_comb4.c ├── 102-print_comb5.c ├── 2-print_alphabet.c ├── 3-print_alphabets.c ├── 4-print_alphabt.c ├── 5-print_numbers.c ├── 6-print_numberz.c ├── 7-print_tebahpla.c ├── 8-print_base16.c ├── 9-print_comb.c └── README.md ├── 0x02-functions_nested_loops ├── 0-putchar ├── 0-putchar.c ├── 1-alphabet ├── 1-alphabet.c ├── 1-main.c ├── 10-add ├── 10-add.c ├── 10-main.c ├── 100-main.c ├── 100-times_table ├── 100-times_table.c ├── 101-natural.c ├── 102-fibonacci.c ├── 103-fibonacci.c ├── 104-fibonacci.c ├── 11-98 ├── 11-main.c ├── 11-print_to_98.c ├── 2-alphabet_x10 ├── 2-main.c ├── 2-print_alphabet_x10.c ├── 3-islower ├── 3-islower.c ├── 3-main.c ├── 4-isalpha ├── 4-isalpha.c ├── 4-main.c ├── 5-main.c ├── 5-sign ├── 5-sign.c ├── 6-abs ├── 6-abs.c ├── 6-main.c ├── 7-last_digit ├── 7-main.c ├── 7-print_last_digit.c ├── 8-24 ├── 8-24_hours.c ├── 8-main.c ├── 9-main.c ├── 9-times_table ├── 9-times_table.c ├── README.md ├── _putchar.c └── main.h ├── 0x03-debugging ├── 0-main.c ├── 1-main ├── 1-main.c ├── 2-largest_number.c ├── 2-main ├── 2-main.c ├── 3-convert_day.c ├── 3-main_a.c ├── 3-main_b.c ├── 3-print_remaining_days.c ├── README.md └── main.h ├── 0x04-more_functions_nested_loops ├── .0-isupper.c.swp ├── 0-isuper ├── 0-isupper.c ├── 0-main.c ├── 1-isdigit ├── 1-isdigit.c ├── 1-main.c ├── 10-main.c ├── 10-print_triangle.c ├── 10-triangles ├── 100-prime_factor ├── 100-prime_factor.c ├── 101-main.c ├── 101-print_number.c ├── 101-print_numbers ├── 2-main.c ├── 2-mul ├── 2-mul.c ├── 3-main.c ├── 3-print_numbers ├── 3-print_numbers.c ├── 4-main.c ├── 4-print_most_numbers ├── 4-print_most_numbers.c ├── 5-main.c ├── 5-more_numbers ├── 5-more_numbers.c ├── 6-lines ├── 6-main.c ├── 6-print_line.c ├── 7-diagonals ├── 7-main.c ├── 7-print_diagonal.c ├── 8-main.c ├── 8-print_square.c ├── 8-squares ├── 9-fizz_buzz ├── 9-fizz_buzz.c ├── README.md ├── _putchar.c └── main.h ├── 0x05-pointers_arrays_strings ├── 0-98 ├── 0-main.c ├── 0-reset_to_98.c ├── 1-main.c ├── 1-swap ├── 1-swap.c ├── 100-atoi ├── 100-atoi.c ├── 100-main.c ├── 101-keygen ├── 101-keygen.c ├── 2-main.c ├── 2-strlen ├── 2-strlen.c ├── 3-main.c ├── 3-puts ├── 3-puts.c ├── 4-main.c ├── 4-print_rev ├── 4-print_rev.c ├── 5-main.c ├── 5-rev_string ├── 5-rev_string.c ├── 6-main.c ├── 6-puts2 ├── 6-puts2.c ├── 7-main.c ├── 7-puts_half ├── 7-puts_half.c ├── 8-main.c ├── 8-print_array ├── 8-print_array.c ├── 9-main.c ├── 9-strcpy ├── 9-strcpy.c ├── README.md ├── _putchar.c └── main.h ├── 0x06-pointers_arrays_strings ├── 0-main.c ├── 0-strcat ├── 0-strcat.c ├── 1-main.c ├── 1-strncat ├── 1-strncat.c ├── 2-main.c ├── 2-strncpy ├── 2-strncpy.c ├── 3-main.c ├── 3-strcmp ├── 3-strcmp.c ├── 4-main.c ├── 4-rev_array ├── 4-rev_array.c ├── 5-main.c ├── 5-string_toupper ├── 5-string_toupper.c ├── 6-cap ├── 6-cap_string.c ├── 6-main.c ├── 7-1337 ├── 7-leet.c ├── 7-main.c ├── README.md ├── _putchar.c └── main.h ├── 0x07-pointers_arrays_strings ├── 0-main.c ├── 0-memset ├── 0-memset.c ├── 1-main.c ├── 1-memcpy ├── 1-memcpy.c ├── 100-main.c ├── 100-set_string ├── 100-set_string.c ├── 101-crackme_password ├── 2-main.c ├── 2-strchr ├── 2-strchr.c ├── 3-main.c ├── 3-strspn ├── 3-strspn.c ├── 4-main.c ├── 4-strpbrk ├── 4-strpbrk.c ├── 5-main.c ├── 5-strstr ├── 5-strstr.c ├── 7-main.c ├── 7-print_chessboard ├── 7-print_chessboard.c ├── 8-main.c ├── 8-print_diagsums ├── 8-print_diagsums.c ├── README.md ├── _putchar.c ├── crackme2 └── main.h ├── 0x08-recursion ├── 0-main.c ├── 0-puts_recursion ├── 0-puts_recursion.c ├── 1-main.c ├── 1-print_rev_recursion ├── 1-print_rev_recursion.c ├── 100-is_palindrome.c ├── 100-main.c ├── 100-palindrome ├── 101-main.c ├── 101-wildcmp ├── 101-wildcmp.c ├── 2-main.c ├── 2-strlen_recursion ├── 2-strlen_recursion.c ├── 3-factorial ├── 3-factorial.c ├── 3-main.c ├── 4-main.c ├── 4-pow ├── 4-pow_recursion.c ├── 5-main.c ├── 5-sqrt ├── 5-sqrt_recursion.c ├── 6-is_prime_number.c ├── 6-main.c ├── 6-prime ├── README.md ├── _putchar.c └── main.h ├── 0x09-static_libraries ├── 0-isupper.c ├── 0-isupper.o ├── 0-memset.c ├── 0-memset.o ├── 0-strcat.c ├── 0-strcat.o ├── 1-isdigit.c ├── 1-isdigit.o ├── 1-memcpy.c ├── 1-memcpy.o ├── 1-strncat.c ├── 1-strncat.o ├── 100-atoi.c ├── 100-atoi.o ├── 2-strchr.c ├── 2-strchr.o ├── 2-strlen.c ├── 2-strlen.o ├── 2-strncpy.c ├── 2-strncpy.o ├── 3-islower.c ├── 3-islower.o ├── 3-puts.c ├── 3-puts.o ├── 3-strcmp.c ├── 3-strcmp.o ├── 3-strspn.c ├── 3-strspn.o ├── 4-isalpha.c ├── 4-isalpha.o ├── 4-strpbrk.c ├── 4-strpbrk.o ├── 5-strstr.c ├── 5-strstr.o ├── 6-abs.c ├── 6-abs.o ├── 9-strcpy.c ├── 9-strcpy.o ├── README.md ├── _putchar.c ├── _putchar.o ├── create_static_lib.sh ├── liball.a ├── libmy.a └── main.h ├── 0x0A-argc_argv ├── 0-whatsmyname.c ├── 1-args.c ├── 100-change.c ├── 2-args.c ├── 3-mul.c ├── 4-add.c ├── README.md ├── add ├── args ├── change ├── mul ├── mynewnameis └── nargs ├── 0x0B-malloc_free ├── 0-create_array.c ├── 0-main.c ├── 1-main.c ├── 1-strdup.c ├── 100-argstostr.c ├── 100-main.c ├── 101-main.c ├── 101-strtow.c ├── 2-main.c ├── 2-str_concat.c ├── 3-alloc_grid.c ├── 3-main.c ├── 4-free_grid.c ├── 4-main.c ├── README.md ├── a ├── args ├── c ├── f ├── g ├── main.h ├── s └── strtow ├── 0x0C-more_malloc_free ├── 0-main.c ├── 0-malloc_checked.c ├── 1-main.c ├── 1-string_nconcat ├── 1-string_nconcat.c ├── 100-main.c ├── 100-realloc ├── 100-realloc.c ├── 101-mul ├── 101-mul.c ├── 2-calloc ├── 2-calloc.c ├── 2-main.c ├── 3-array_range ├── 3-array_range.c ├── 3-main.c ├── README.md ├── _putchar.c ├── a └── main.h ├── 0x0D-preprocessor ├── 0-main.c ├── 0-object_like_macro.h ├── 02-main.c ├── 1-main.c ├── 1-pi.h ├── 2-main.c ├── 3-function_like_macro.h ├── 3-main.c ├── 4-main.c ├── 4-sum.h ├── README.md ├── a ├── b ├── c ├── cc ├── d └── e ├── 0x0E-structures_typedef ├── 0-main.c ├── 1-init_dog.c ├── 1-main.c ├── 2-main.c ├── 2-print_dog.c ├── 3-main.c ├── 4-main.c ├── 4-new_dog.c ├── 5-free_dog.c ├── 5-main.c ├── README.md ├── a ├── b ├── c ├── d ├── dog.h ├── e └── f ├── 0x0F-function_pointers ├── 0-main.c ├── 0-print_name.c ├── 1-array_iterator.c ├── 1-main.c ├── 100-main_opcodes.c ├── 2-int_index.c ├── 2-main.c ├── 3-calc.h ├── 3-get_op_func.c ├── 3-main.c ├── 3-op_functions.c ├── README.md ├── a ├── b ├── c ├── calc ├── function_pointers.h └── main ├── 0x10-variadic_functions ├── 0-main.c ├── 0-sum_them_all.c ├── 1-main.c ├── 1-print_numbers.c ├── 2-main.c ├── 2-print_strings.c ├── 3-main.c ├── 3-print_all.c ├── README.md ├── a ├── b ├── c ├── d └── variadic_functions.h ├── 0x12-singly_linked_lists ├── 0-main.c ├── 0-print_list.c ├── 1-list_len.c ├── 1-main.c ├── 100-first.c ├── 100-main.c ├── 101-hello_holberton.asm ├── 101-hello_holberton.o ├── 2-add_node.c ├── 2-main.c ├── 3-add_node_end.c ├── 3-main.c ├── 4-free_list.c ├── 4-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e ├── first ├── hello └── lists.h ├── 0x13-more_singly_linked_lists ├── 0-main.c ├── 0-print_listint.c ├── 1-listint_len.c ├── 1-main.c ├── 10-delete_nodeint.c ├── 10-main.c ├── 100-main.c ├── 100-reverse_listint.c ├── 101-main.c ├── 101-print_listint_safe.c ├── 102-free_listint_safe.c ├── 102-main.c ├── 103-find_loop.c ├── 103-main.c ├── 2-add_nodeint.c ├── 2-main.c ├── 3-add_nodeint_end.c ├── 3-main.c ├── 4-free_listint.c ├── 4-main.c ├── 5-free_listint2.c ├── 5-main.c ├── 6-main.c ├── 6-pop_listint.c ├── 7-get_nodeint.c ├── 7-main.c ├── 8-main.c ├── 8-sum_listint.c ├── 9-insert_nodeint.c ├── 9-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e ├── f ├── g ├── h ├── i ├── j ├── k ├── l ├── lists.h ├── m ├── n ├── next └── o ├── 0x14-bit_manipulation ├── 0-binary_to_uint.c ├── 0-main.c ├── 1-main.c ├── 1-print_binary.c ├── 100-get_endianness.c ├── 100-main.c ├── 101-password ├── 2-get_bit.c ├── 2-main.c ├── 3-main.c ├── 3-set_bit.c ├── 4-clear_bit.c ├── 4-main.c ├── 5-flip_bits.c ├── 5-main.c ├── README.md ├── _putchar.c ├── a ├── b ├── c ├── crackme3 ├── d ├── e ├── f ├── h ├── main.h └── run.xt ├── 0x15-file_io ├── 0-main.c ├── 0-read_textfile.c ├── 1-create_file.c ├── 1-main.c ├── 100-elf_header.c ├── 2-append_text_to_file.c ├── 2-main.c ├── 3-cp.c ├── Incitatous ├── README.md ├── Requiescat ├── a ├── b ├── c ├── cp ├── elf_b.h ├── hello ├── incitatous └── main.h ├── 0x17-doubly_linked_lists ├── 0-main.c ├── 0-print_dlistint.c ├── 1-dlistint_len.c ├── 1-main.c ├── 100-password ├── 102-result ├── 103-keygen.c ├── 2-add_dnodeint.c ├── 2-main.c ├── 3-add_dnodeint_end.c ├── 3-main.c ├── 4-free_dlistint.c ├── 4-main.c ├── 5-get_dnodeint.c ├── 5-main.c ├── 6-main.c ├── 6-sum_dlistint.c ├── 7-insert_dnodeint.c ├── 7-main.c ├── 8-delete_dnodeint.c ├── 8-main.c ├── README.md ├── a ├── b ├── c ├── crackme4 ├── crackme4.py ├── crackme4.pyc ├── crackme5 ├── d ├── e ├── h ├── i ├── j ├── k ├── keygen5 ├── largest_palindrome_102.py └── lists.h ├── 0x18-dynamic_libraries ├── 0-isupper.c ├── 0-isupper.o ├── 0-main.c ├── 0-main.o ├── 0-memset.c ├── 0-memset.o ├── 0-strcat.c ├── 0-strcat.o ├── 1-alphabet.c ├── 1-alphabet.o ├── 1-create_dynamic_lib.sh ├── 1-isdigit.c ├── 1-isdigit.o ├── 1-memcpy.c ├── 1-memcpy.o ├── 1-strncat.c ├── 1-strncat.o ├── 100-atoi.c ├── 100-atoi.o ├── 100-operations.c ├── 100-operations.o ├── 100-operations.so ├── 100-tests.py ├── 101-gm_overhaul.c ├── 101-gm_overhaul.o ├── 101-make_me_win.sh ├── 101-md5_gm ├── 2-strchr.c ├── 2-strchr.o ├── 2-strlen.c ├── 2-strlen.o ├── 2-strncpy.c ├── 2-strncpy.o ├── 3-islower.c ├── 3-islower.o ├── 3-puts.c ├── 3-puts.o ├── 3-strcmp.c ├── 3-strcmp.o ├── 3-strspn.c ├── 3-strspn.o ├── 4-isalpha.c ├── 4-isalpha.o ├── 4-strpbrk.c ├── 4-strpbrk.o ├── 5-strstr.c ├── 5-strstr.o ├── 6-abs.c ├── 6-abs.o ├── 9-strcpy.c ├── 9-strcpy.o ├── README.md ├── _putchar.c ├── _putchar.o ├── a.out ├── dog.h ├── gm ├── init.c ├── init.o ├── len ├── lib101-gm_overhaul.so ├── liball.so ├── libdynamic.so └── main.h ├── 0x1A-hash_tables ├── 0-hash_table_create.c ├── 0-main.c ├── 1-djb2.c ├── 1-main.c ├── 100-main.c ├── 100-sorted_hash_table.c ├── 2-key_index.c ├── 2-main.c ├── 3-hash_table_set.c ├── 3-main.c ├── 4-hash_table_get.c ├── 4-main.c ├── 5-hash_table_print.c ├── 5-main.c ├── 6-hash_table_delete.c ├── 6-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e ├── f ├── g ├── hash_tables.h └── sht ├── 0x1C-makefiles ├── 0-Makefile ├── 1-Makefile ├── 100-Makefile ├── 2-Makefile ├── 3-Makefile ├── 4-Makefile ├── 5-island_perimeter.py └── README.md ├── 0x1E-search_algorithms ├── 0-linear.c ├── 1-binary.c ├── 1-binary_recursive.c ├── 100-jump.c ├── 101-O ├── 102-interpolation.c ├── 103-exponential.c ├── 104-advanced_binary.c ├── 105-jump_list.c ├── 106-linear_skip.c ├── 107-O ├── 108-O ├── 2-O ├── 3-O ├── 4-O ├── 5-O ├── 6-O ├── README.md └── search_algos.h └── README.md /0x00-hello_world/0-preprocessor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -E $CFILE > c 3 | -------------------------------------------------------------------------------- /0x00-hello_world/README.md: -------------------------------------------------------------------------------- 1 | README.md 0x00-hello_world 2 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entyr point 5 | * Description: prints two digits combination 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int c, i; 11 | 12 | for (c = '0'; c <= '9'; c++) 13 | { 14 | for (i = '0'; i <= '9'; i++) 15 | { 16 | if (c < i) 17 | { 18 | putchar(c); 19 | putchar(i); 20 | 21 | if (c != '8' || (c == '8' && i != '9')) 22 | { 23 | putchar(','); 24 | putchar(' '); 25 | } 26 | } 27 | } 28 | } 29 | putchar('\n'); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Prints 3 combination of numbers 5 | * 6 | * Return: Always (Success) 7 | */ 8 | int main(void) 9 | { 10 | int c, i, k; 11 | 12 | for (c = '0'; c <= '9'; c++) 13 | { 14 | for (i = '0'; i <= '9'; i++) 15 | { 16 | for (k = '0'; k <= '9'; k++) 17 | { 18 | if (c < i && i < k) 19 | { 20 | putchar(c); 21 | putchar(i); 22 | putchar(k); 23 | 24 | if (c != '7') 25 | { 26 | putchar(','); 27 | putchar(' '); 28 | } 29 | } 30 | } 31 | } 32 | } 33 | putchar('\n'); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints the alphabet in lowercase\n 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int ch; 11 | 12 | for (ch = 'a'; ch <= 'z'; ch++) 13 | { 14 | putchar(ch); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints alphabet in lowercase then uppercase 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int ch; 11 | 12 | for (ch = 'a'; ch <= 'z'; ch++) 13 | { 14 | putchar(ch); 15 | } 16 | for (ch = 'A'; ch <= 'Z'; ch++) 17 | { 18 | putchar(ch); 19 | } 20 | putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints lowercase alphabets 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int ch; 11 | 12 | for (ch = 'a'; ch <= 'z'; ch++) 13 | { 14 | if (ch != 'e' && ch != 'q') 15 | { 16 | putchar(ch); 17 | } 18 | else 19 | { 20 | } 21 | } 22 | putchar('\n'); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main -Entry point 5 | * Description: prints allsingle digit numbers of 6 | * base 10 from 0 7 | * Return: Always 0 (success) 8 | */ 9 | int main(void) 10 | { 11 | int a; 12 | 13 | for (a = 0; a < 10; a++) 14 | { 15 | printf("%d", a); 16 | } 17 | putchar('\n'); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints char below 10 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int a; 11 | 12 | for (a = 0; a < 10; a++) 13 | { 14 | putchar(a + '0'); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints lowercase alphabets in reverse 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int a; 11 | 12 | for (a = 'z'; a >= 'a'; a--) 13 | { 14 | putchar(a); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: Print base 16 numbers 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | char c; 11 | char d = '0'; 12 | 13 | while (d <= '9') 14 | { 15 | putchar(d); 16 | d++; 17 | } 18 | for (c = 'a'; c <= 'f'; c++) 19 | { 20 | putchar(c); 21 | } 22 | putchar('\n'); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Entry point 5 | * Description: prints numbers 6 | * Return: Always 0 (success) 7 | */ 8 | int main(void) 9 | { 10 | int i; 11 | 12 | for (i = '0'; i <= '9' ; i++) 13 | { 14 | putchar(i); 15 | 16 | if (i != '9') 17 | { 18 | putchar(','); 19 | putchar(' '); 20 | } 21 | } 22 | 23 | putchar('\n'); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-putchar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/0-putchar -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-putchar.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * main - Entry point 4 | * Description: prints _putchar 5 | * Return: 0 6 | */ 7 | 8 | 9 | int main(void) 10 | { 11 | /* call instruction putchar from main.h */ 12 | _putchar('_'); 13 | _putchar('p'); 14 | _putchar('u'); 15 | _putchar('t'); 16 | _putchar('c'); 17 | _putchar('h'); 18 | _putchar('a'); 19 | _putchar('r'); 20 | _putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/1-alphabet -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_alphabet - Entry point 4 | * Description: print all alphabet in lowercase 5 | * print_alphabet - prints the english alphabet from a-z. 6 | * Return: Always 0 (success) 7 | */ 8 | 9 | void print_alphabet(void) 10 | { 11 | char letter; 12 | 13 | for (letter = 'a'; letter <= 'z'; letter++) 14 | { 15 | /* Description : print_alphabet call putchar from main*/ 16 | _putchar(letter); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | print_alphabet(); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/10-add -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * add - adds two integers and returns the result 5 | * @a: int to be added to b 6 | * @b: int to be added to a 7 | * Return: sum of a and b 8 | */ 9 | 10 | int add(int a, int b) 11 | { 12 | int c; 13 | 14 | c = a + b; 15 | 16 | return (c); 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/100-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/100-times_table -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - computes and prints the sum of all the multiples of 4 | * 3 or 5 below 1024. 5 | * Return: Nothing. 6 | */ 7 | 8 | int main(void) 9 | { 10 | int i, res; 11 | 12 | for (i = 0; i < 1024; i++) 13 | if (i % 3 == 0 || i % 5 == 0) 14 | res += i; 15 | printf("%d\n", res); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print the first 50 fibonacci numbers. 4 | * Return: Nothing. 5 | */ 6 | int main(void) 7 | { 8 | unsigned long count, i, j, k; 9 | 10 | i = 0; 11 | j = 1; 12 | for (count = 0; count < 50; count++) 13 | { 14 | k = i + j; 15 | i = j; 16 | j = k; 17 | printf("%lu", k); 18 | if (count == 49) 19 | putchar('\n'); 20 | else 21 | { 22 | printf(", "); 23 | } 24 | } 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - sum even fibonacci numbers under 4 million. 4 | * Return: Nothing. 5 | */ 6 | int main(void) 7 | { 8 | unsigned long count, i, j, k, sums; 9 | 10 | i = sums = 0; 11 | j = 1; 12 | for (count = 0; count < 50; count++) 13 | { 14 | k = i + j; 15 | i = j; 16 | j = k; 17 | if (k % 2 == 0 && k < 4000000) 18 | { 19 | sums += k; 20 | } 21 | } 22 | printf("%lu\n", sums); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/11-98 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-alphabet_x10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/2-alphabet_x10 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_alphabet_x10 - prints 10 times the alphabet, in lowercase, 4 | * followed by a new line 5 | */ 6 | 7 | void print_alphabet_x10(void) 8 | { 9 | char ch; 10 | 11 | int i; 12 | 13 | i = 0; 14 | 15 | while (i < 10) 16 | { 17 | ch = 'a'; 18 | while (ch <= 'z') 19 | { 20 | _putchar(ch); 21 | ch++; 22 | } 23 | _putchar('\n'); 24 | i++; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/3-islower -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _islower - check if char is lowercase 4 | * @c: is the char to be checked 5 | * Return: 1 if char is lowercase, otherwise 0. 6 | */ 7 | int _islower(int c) 8 | { 9 | if (c >= 'a' && c <= 'z') 10 | { 11 | return (1); 12 | } 13 | else 14 | { 15 | return (0); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/4-isalpha -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isalpha - checks for alphabetic character 5 | * @c: the character to be checked 6 | * Description: 'the program's description' 7 | * Return: 1 if c is a letter, 0 otherwise 8 | */ 9 | 10 | 11 | int _isalpha(int c) 12 | { 13 | return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); 14 | } 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/5-sign -------------------------------------------------------------------------------- /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 int to check 6 | * Return: 1 and prints + if n is greater than zero 7 | */ 8 | 9 | int print_sign(int n) 10 | { 11 | if (n > 0) 12 | { 13 | _putchar('+'); 14 | return (1); 15 | } 16 | else if (n == 0) 17 | { 18 | _putchar(48); 19 | return (0); 20 | } 21 | else if (n < 0) 22 | { 23 | _putchar('-'); 24 | } 25 | return (-1); 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/6-abs -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _abs - computes the absolute value of an integer 5 | * @n: the int to check 6 | * Return: the absolute value of int 7 | */ 8 | 9 | int _abs(int n) 10 | { 11 | if (n >= 0) 12 | { 13 | return (n); 14 | } 15 | return (-n); 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/7-last_digit -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 int to extract the last digit from 6 | * Return: value of the last digit 7 | */ 8 | 9 | int print_last_digit(int n) 10 | { 11 | int a; 12 | 13 | if (n < 0) 14 | { 15 | n = -n; 16 | } 17 | a = n % 10; 18 | if (a < 0) 19 | { 20 | a = -a; 21 | } 22 | _putchar(a + '0'); 23 | return (a); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/8-24 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24_hours.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * jack_bauer - prints every minute of the day of Jack Bauer 5 | * starting from 00:00 to 23:59 6 | */ 7 | 8 | void jack_bauer(void) 9 | { 10 | int i; 11 | 12 | int j; 13 | 14 | i = 0; 15 | 16 | while (i < 24) 17 | { 18 | j = 0; 19 | while (j < 60) 20 | { 21 | _putchar((i / 10) + '0'); 22 | _putchar((i % 10) + '0'); 23 | _putchar(':'); 24 | _putchar((j / 10) + '0'); 25 | _putchar((j % 10) + '0'); 26 | _putchar('\n'); 27 | j++; 28 | } 29 | i++; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /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/9-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x02-functions_nested_loops/9-times_table -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | #ifndef main_h 2 | #define main_h 3 | 4 | 5 | int _putchar(char); 6 | void print_alphabet(void); 7 | void print_alphabet_x10(void); 8 | int _islower(int c); 9 | int _isalpha(int c); 10 | int print_sign(int n); 11 | int _abs(int); 12 | int print_last_digit(int); 13 | void jack_bauer(void); 14 | void times_table(void); 15 | int add(int, int); 16 | void print_to_98(int n); 17 | void print_times_table(int n); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x03-debugging/1-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x03-debugging/1-main -------------------------------------------------------------------------------- /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 | 14 | i = 0; 15 | /* 16 | * while (i < 10) 17 | * { 18 | * putchar(i); 19 | * } 20 | */ 21 | printf("Infinite loop avoided! \\o/\n"); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /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 | {int largest; 13 | 14 | if (a > b && a > c) 15 | { 16 | largest = a; 17 | } 18 | else if (b > c) 19 | { 20 | largest = b; 21 | } 22 | else 23 | { 24 | largest = c; 25 | } 26 | 27 | return (largest); 28 | } 29 | -------------------------------------------------------------------------------- /0x03-debugging/2-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x03-debugging/2-main -------------------------------------------------------------------------------- /0x03-debugging/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * main - prints the largest of 3 integers 5 | * Return: 0 6 | */ 7 | 8 | int main(void) 9 | { 10 | int a, b, c; 11 | 12 | int largest; 13 | 14 | a = 972; 15 | b = -98; 16 | c = 0; 17 | largest = largest_number(a, b, c); 18 | printf("%d is the largest number\n", largest); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /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 = 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/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 | void print_remaining_days(int month, int day, int year); 9 | int convert_day(int month, int day); 10 | 11 | #endif /* MAIN_H */ 12 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/.0-isupper.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/.0-isupper.c.swp -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isuper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/0-isuper -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isupper - check uppercase 5 | * @c: character to be checked 6 | * Return: 1 if upper, 0 otherwise 7 | */ 8 | 9 | int _isupper(int c) 10 | { 11 | if (c >= 'A' && c <= 'Z') 12 | { 13 | return (1); 14 | } 15 | else 16 | { 17 | return (0); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /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-isdigit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/1-isdigit -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _isdigit - check digit 5 | * @c: parameter to be checked 6 | * Return: 1 if digit, 0 otherwise 7 | */ 8 | 9 | int _isdigit(int c) 10 | { 11 | if (c >= '0' && c <= '9') 12 | { 13 | return (1); 14 | } 15 | else 16 | { 17 | return (0); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /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 | 10 | int main(void) 11 | { 12 | char c; 13 | 14 | c = '0'; 15 | printf("%c: %d\n", c, _isdigit(c)); 16 | c = 'a'; 17 | printf("%c: %d\n", c, _isdigit(c)); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /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/10-print_triangle.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_triangle - prints a triangle 5 | * @size: parameter 6 | */ 7 | 8 | void print_triangle(int size) 9 | { 10 | int i, j, k; 11 | 12 | if (size <= 0) 13 | { 14 | _putchar('\n'); 15 | } 16 | else 17 | { 18 | for (i = 1; i <= size; i++) 19 | { 20 | for (k = size - i; k >= 1; k--) 21 | { 22 | _putchar(' '); 23 | } 24 | for (j = 1; j <= i; j++) 25 | { 26 | _putchar('#'); 27 | } 28 | _putchar('\n'); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-triangles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/10-triangles -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/100-prime_factor -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - Prints out the larget prime factor of 612852475143 4 | * Return:return 0 with success. 5 | */ 6 | int main(void) 7 | { 8 | long i; 9 | long num = 612852475143; 10 | 11 | for (i = 2; i < num; i++) 12 | { 13 | if (num % i == 0) 14 | num /= i; 15 | } 16 | printf("%li\n", num); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_number - prints an integer 5 | * @n: integer to be printed 6 | */ 7 | void print_number(int n) 8 | { 9 | unsigned int n1; 10 | 11 | if (n < 0) 12 | { 13 | n1 = -n; 14 | _putchar('-'); 15 | } else 16 | { 17 | n1 = n; 18 | } 19 | 20 | if (n1 / 10) 21 | { 22 | print_number(n1 / 10); 23 | } 24 | 25 | _putchar((n1 % 10) + '0'); 26 | } 27 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/101-print_numbers -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/2-mul -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * mul - multiply two number 5 | * @a: num 6 | * @b: num 7 | * Return: nothing 8 | */ 9 | 10 | int mul(int a, int b) 11 | { 12 | return (a * b); 13 | } 14 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/3-print_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_numbers - print number 0 to 9 5 | */ 6 | 7 | void print_numbers(void) 8 | { 9 | char i; 10 | 11 | for (i = '0'; i <= '9'; i++) 12 | { 13 | _putchar(i); 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/4-print_most_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_most_numbers - print number 5 | * Return: void 6 | */ 7 | 8 | void print_most_numbers(void) 9 | { 10 | char i; 11 | 12 | for (i = '0'; i <= '9'; i++) 13 | { 14 | if (!(i == '2' || i == '4')) 15 | { 16 | _putchar(i); 17 | } 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/5-more_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * more_numbers - prints the range 0-14 ten times. 4 | * Return: nothing. 5 | */ 6 | void more_numbers(void) 7 | { 8 | int i, j; 9 | 10 | i = j = 0; 11 | while (i < 10) 12 | { 13 | while (j <= 14) 14 | { 15 | if (j >= 10) 16 | _putchar(j / 10 + '0'); 17 | _putchar(j % 10 + '0'); 18 | ++j; 19 | } 20 | _putchar('\n'); 21 | j = 0; 22 | i++; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-lines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/6-lines -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_line - draws a straight line (n) characters long. 4 | * @n: the number of underscores to print. 5 | */ 6 | void print_line(int n) 7 | { 8 | int i; 9 | 10 | if (n > 0) 11 | for (i = 0; i < n; i++) 12 | _putchar('_'); 13 | _putchar('\n'); 14 | } 15 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-diagonals: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/7-diagonals -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_diagonal - draws a diagonal line across (n) terminal lines. 4 | * @n: the number of lines to print 5 | */ 6 | void print_diagonal(int n) 7 | { 8 | int i, j; 9 | 10 | if (n > 0) 11 | { 12 | for (j = 1; j <= n; j++) 13 | { 14 | for (i = 1; i <= j; i++) 15 | { 16 | if (i != 1) 17 | _putchar(' '); 18 | if (i == j) 19 | { 20 | _putchar('\\'); 21 | _putchar('\n'); 22 | } 23 | } 24 | } 25 | } 26 | else 27 | _putchar('\n'); 28 | } 29 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_square - draws a square using multiple terminal lines and #'s. 4 | * @n: the number of # to print in each line. 5 | */ 6 | void print_square(int n) 7 | { 8 | int i, j; 9 | 10 | if (n > 0) 11 | { 12 | for (i = 0; i < n; i++) 13 | { 14 | for (j = 0; j < n; j++) 15 | _putchar('#'); 16 | _putchar('\n'); 17 | } 18 | } 19 | else 20 | _putchar('\n'); 21 | } 22 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-squares: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/8-squares -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x04-more_functions_nested_loops/9-fizz_buzz -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | int _putchar(char c); 5 | int _isupper(int c); 6 | int _isdigit(int c); 7 | int mul(int a, int b); 8 | void print_numbers(void); 9 | void print_most_numbers(void); 10 | void more_numbers(void); 11 | void print_line(int n); 12 | void print_diagonal(int n); 13 | void print_square(int size); 14 | void print_triangle(int size); 15 | void print_number(int n); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/0-98 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int n; 11 | 12 | n = 402; 13 | 14 | printf("n=%d\n", n); 15 | reset_to_98(&n); 16 | printf("n=%d\n", n); 17 | 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * reset_to_98 - rest the parameter to 98 5 | * @n: parameter reseter 6 | * Return: nothing 7 | */ 8 | 9 | void reset_to_98(int *n) 10 | { 11 | *n = 98; 12 | } 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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/1-swap -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * swap_int - swap the values of two integers 5 | * @a: pointer parameters 6 | * @b: pointer parameters 7 | * Return: nothing 8 | */ 9 | 10 | void swap_int(int *a, int *b) 11 | { 12 | int s; 13 | 14 | s = *a; 15 | *a = *b; 16 | *b = s; 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/100-atoi: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/100-atoi -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/100-atoi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _atoi - changes a string to an int 3 | * @s: the string to be changed 4 | * 5 | * Return: the converted int 6 | */ 7 | int _atoi(char *s) 8 | { 9 | int i = 1; 10 | unsigned int num = 0; 11 | do { 12 | if (*s == '-') 13 | i *= -1; 14 | else if (*s >= '0' && *s <= '9') 15 | num = num * 10 + (*s - '0'); 16 | else if (num > 0) 17 | break; 18 | } while (*s++); 19 | return (num *i); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/101-keygen -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /** 5 | * main - entry point generates a random password 6 | * 7 | * Return: the generated password 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | int x; 13 | 14 | srand(time(0)); 15 | while (x <= 2645) 16 | { 17 | c = rand() % 128; 18 | x += c; 19 | putchar(c); 20 | } 21 | putchar(2772 - x); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/2-strlen -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen - string length counter 5 | * @s: parameter 6 | * Return: length of the string 7 | */ 8 | 9 | int _strlen(char *s) 10 | { 11 | int count = 0; 12 | 13 | for ( ; *s != '\0'; s++) 14 | { 15 | count++; 16 | } 17 | return (count); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/3-puts -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed by a new line, to 5 | * stdout. 6 | * 7 | * @str: This is my input string 8 | * 9 | */ 10 | 11 | void _puts(char *str) 12 | { 13 | int index; 14 | 15 | for (index = 0; str[index] != '\0'; index++) 16 | { 17 | _putchar(str[index]); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/4-print_rev -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_rev - This function prints a reverse string 5 | * 6 | * @s: This is the input string 7 | */ 8 | void print_rev(char *s) 9 | { 10 | int index; 11 | 12 | for (index = 0; s[index] != '\0'; index++) 13 | ; 14 | for (index = index - 1; s[index] != '\0'; index--) 15 | { 16 | _putchar(s[index]); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /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/5-rev_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/5-rev_string -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * rev_string - a function that reverses a string 5 | * @s: parameter 6 | * Return: nothing 7 | */ 8 | 9 | void rev_string(char *s) 10 | { 11 | int a = 0, c, b; 12 | char d; 13 | 14 | while (s[a] != '\0') 15 | { 16 | a++; 17 | } 18 | for (c = a - 1, b = 0; c >= 0 && b < c; c--, b++) 19 | { 20 | d = s[b]; 21 | s[b] = s[c]; 22 | s[c] = d; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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/6-puts2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/6-puts2 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * puts2 - Write a function that prints every other character of a string 5 | * starting with the first character, followed by a new line. 6 | * @s: This pointer point to a char or string 7 | */ 8 | 9 | void puts2(char *s) 10 | { 11 | int a; 12 | 13 | for (a = 0; s[a] != '\0'; a++) 14 | { 15 | if (a % 2 == 0) 16 | { 17 | _putchar(s[a]); 18 | } 19 | } 20 | _putchar('\n'); 21 | } 22 | -------------------------------------------------------------------------------- /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 = "0123456789"; 13 | puts_half(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/7-puts_half -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *puts_half - function that prints half of a string, followed by a new line. 4 | * 5 | *@str: This is the input string 6 | */ 7 | void puts_half(char *str) 8 | { 9 | int index, half; 10 | 11 | index = 0; 12 | while (str[index] != '\0') 13 | index++; 14 | 15 | half = index / 2; 16 | 17 | if (index % 2 == 1) 18 | half++; 19 | 20 | while (half < index) 21 | { 22 | _putchar(str[half]); 23 | half++; 24 | } 25 | _putchar('\n'); 26 | } 27 | -------------------------------------------------------------------------------- /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 | 18 | print_array(array, 5); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/8-print_array -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_array - print n element of array 4 | *@a: array 5 | *@n: number of elements 6 | *Return: nothing 7 | */ 8 | void print_array(int *a, int n) 9 | { 10 | int inc; 11 | for (inc = 0; inc < n ; inc++) 12 | { 13 | if (inc != n - 1) 14 | printf("%d, ", a[inc]); 15 | else 16 | printf("%d", a[inc]); 17 | 18 | } 19 | printf("\n"); 20 | } 21 | -------------------------------------------------------------------------------- /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/9-strcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x05-pointers_arrays_strings/9-strcpy -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcpy - copies a string point by src 5 | * @dest: parameter 6 | * @src: parameter 7 | * Return: desr 8 | */ 9 | 10 | char *_strcpy(char *dest, char *src) 11 | { 12 | int i = 0; 13 | 14 | while (src[i] != '\0') 15 | { 16 | dest[i] = src[i]; 17 | i++; 18 | } 19 | dest[i] = '\0'; 20 | return (dest); 21 | } 22 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/0-strcat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_strcat - Write a function that concatenates two strings. 5 | * 6 | *@dest: This is the output dest 7 | *@src: This is the input source 8 | * 9 | * Return: This return to dest, that concatenates two strings 10 | */ 11 | 12 | char *_strcat(char *dest, char *src) 13 | { 14 | int i, j; 15 | 16 | for (i = 0; dest[i] != '\0'; i++) 17 | ; 18 | for (j = 0; src[j] != '\0'; j++) 19 | { 20 | dest[i] = src[j]; 21 | i++; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char s1[98] = "Hello "; 11 | char s2[] = "World!\n"; 12 | char *ptr; 13 | 14 | printf("%s\n", s1); 15 | printf("%s", s2); 16 | ptr = _strncat(s1, s2, 1); 17 | printf("%s\n", s1); 18 | printf("%s", s2); 19 | printf("%s\n", ptr); 20 | ptr = _strncat(s1, s2, 1024); 21 | printf("%s", s1); 22 | printf("%s", s2); 23 | printf("%s", ptr); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-strncat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/1-strncat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/2-strncpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/2-strncpy -------------------------------------------------------------------------------- /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/3-strcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/3-strcmp -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strcmp - compares two strings. 4 | *@s1: pointer to first string. 5 | *@s2: pointer to second string. 6 | * 7 | *Return: value less than 0 if string is less than the other. 8 | *value greater than 0 if string is greater than the other. 9 | *0 if strings are equal. 10 | */ 11 | int _strcmp(char *s1, char *s2) 12 | { 13 | int counter, cmpVal; 14 | 15 | counter = 0; 16 | while (s1[counter] == s2[counter] && s1[counter] != '\0') 17 | { 18 | counter++; 19 | } 20 | 21 | cmpVal = s1[counter] - s2[counter]; 22 | return (cmpVal); 23 | } 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/4-rev_array -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *reverse_array - revereses an array. 4 | *@a: pointer to array. 5 | *@n: number of elements of an array. 6 | * 7 | *Return: void. 8 | */ 9 | void reverse_array(int *a, int n) 10 | { 11 | int temp, counter; 12 | 13 | n = n - 1; 14 | counter = 0; 15 | while (counter <= n) 16 | { 17 | temp = a[counter]; 18 | a[counter++] = a[n]; 19 | a[n--] = temp; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/5-string_toupper -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *string_toupper - changes all lowercase letters of a string to uppercase. 4 | *@x: pointer to string. 5 | * 6 | *Return: pointer to uppercase string. 7 | */ 8 | char *string_toupper(char *x) 9 | { 10 | int length; 11 | 12 | length = 0; 13 | 14 | while (x[length] != '\0') 15 | { 16 | if (x[length] >= 97 && x[length] <= 122) 17 | { 18 | x[length] = x[length] - 32; 19 | } 20 | length++; 21 | } 22 | return (x); 23 | } 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/6-cap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/6-cap -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-1337: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x06-pointers_arrays_strings/7-1337 -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | readme.md 2 | -------------------------------------------------------------------------------- /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 | 15 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/0-memset -------------------------------------------------------------------------------- /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 to be filled 6 | * @b: char to copy 7 | * @n: number of times to copy b 8 | * 9 | * Return: 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 | { 17 | s[i] = b; 18 | } 19 | 20 | return (s); 21 | } 22 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/1-memcpy -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * *_memcpy - copies memory area 5 | * @dest: destination memory area 6 | * @src: memory area to copy from 7 | * @n: number of bytes to copy 8 | * 9 | * Return: pointer to dest 10 | */ 11 | char *_memcpy(char *dest, char *src, unsigned int n) 12 | { 13 | unsigned int i; 14 | 15 | for (i = 0; i < n; i++) 16 | { 17 | dest[i] = src[i]; 18 | } 19 | 20 | return (dest); 21 | } 22 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *s0 = "Bob Dylan"; 11 | char *s1 = "Robert Allen"; 12 | 13 | printf("%s, %s\n", s0, s1); 14 | set_string(&s1, s0); 15 | printf("%s, %s\n", s0, s1); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/100-set_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/100-set_string -------------------------------------------------------------------------------- /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: pointer to pointer we need to set to 6 | * @to: string to set 7 | */ 8 | void set_string(char **s, char *to) 9 | { 10 | *s = to; 11 | } 12 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/101-crackme_password: -------------------------------------------------------------------------------- 1 | abc123 -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *s = "hello"; 11 | char *f; 12 | 13 | f = _strchr(s, 'l'); 14 | 15 | if (f != NULL) 16 | { 17 | printf("%s\n", f); 18 | } 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/2-strchr -------------------------------------------------------------------------------- /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: string to search 7 | * @c: char to find 8 | * 9 | * Return: a pointer to the first occurrence of the character 10 | * c in the string s, or NULL if the character is not found 11 | */ 12 | char *_strchr(char *s, char c) 13 | { 14 | int a; 15 | 16 | while (1) 17 | { 18 | a = *s++; 19 | if (a == c) 20 | { 21 | return (s - 1); 22 | } 23 | if (a == 0) 24 | { 25 | return (NULL); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *s = "hello, world"; 11 | char *f = "oleh"; 12 | unsigned int n; 13 | 14 | n = _strspn(s, f); 15 | printf("%u\n", n); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-strspn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/3-strspn -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *s = "hello, world"; 11 | char *f = "world"; 12 | char *t; 13 | 14 | t = _strpbrk(s, f); 15 | printf("%s\n", t); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-strpbrk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/4-strpbrk -------------------------------------------------------------------------------- /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: string to search 7 | * @accept: stringcontaining the bytes to look for 8 | * 9 | * Return: pointer to the byte in s that matches one of the bytes in accept 10 | * 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 != '\0'; i++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (*s == accept[j]) 21 | { 22 | return (s); 23 | } 24 | } 25 | s++; 26 | } 27 | 28 | return (NULL); 29 | } 30 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *s = "hello, world"; 11 | char *f = "world"; 12 | char *t; 13 | 14 | t = _strstr(s, f); 15 | printf("%s\n", t); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-strstr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/5-strstr -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * *_strstr - locates a substring 6 | * @haystack: string to search in 7 | * @needle: substring to look for 8 | * 9 | * Return: pointer to the beginning of the located substring 10 | * or NULL if the substring is not found 11 | */ 12 | char *_strstr(char *haystack, char *needle) 13 | { 14 | int i, j; 15 | 16 | for (i = 0; haystack[i] != '\0'; i++) 17 | { 18 | for (j = 0; needle[j] != '\0'; j++) 19 | { 20 | if (haystack[i + j] != needle[j]) 21 | break; 22 | } 23 | if (!needle[j]) 24 | return (&haystack[i]); 25 | } 26 | return (NULL); 27 | } 28 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char board[8][8] = { 11 | {'r', 'k', 'b', 'q', 'k', 'b', 'k', 'r'}, 12 | {'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'}, 13 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 14 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 15 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 16 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 17 | {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'}, 18 | {'R', 'K', 'B', 'Q', 'K', 'B', 'K', 'R'}, 19 | }; 20 | print_chessboard(board); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/7-print_chessboard -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_chessboard - prints the chessboard 5 | * @a: two dimension array to print 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 | { 15 | _putchar(a[i][j]); 16 | } 17 | _putchar('\n'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int c3[3][3] = { 11 | {0, 1, 5}, 12 | {10, 11, 12}, 13 | {1000, 101, 102}, 14 | }; 15 | int c5[5][5] = { 16 | {0, 1, 5, 12124, 1234}, 17 | {10, 11, 12, 123521, 12512}, 18 | {1000, 101, 102, 12545, 214543435}, 19 | {100, 1012451, 11102, 12545, 214543435}, 20 | {10, 12401, 10452, 11542545, 1214543435}, 21 | }; 22 | print_diagsums((int *)c3, 3); 23 | print_diagsums((int *)c5, 5); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/8-print_diagsums -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * print_diagsums - prints the sum of the two diagonals 6 | * of a square matrix of integers 7 | * @a: square matrix of which we print the sum of diagonals 8 | * @size: size of the matrix 9 | */ 10 | void print_diagsums(int *a, int size) 11 | { 12 | int i; 13 | 14 | unsigned int sum, sum1; 15 | 16 | sum = 0; 17 | sum1 = 0; 18 | 19 | for (i = 0; i < size; i++) 20 | { 21 | sum += a[(size * i) + i]; 22 | sum1 += a[(size * (i + 1)) - (i + 1)]; 23 | } 24 | 25 | printf("%d, %d\n", sum, sum1); 26 | } 27 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/crackme2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x07-pointers_arrays_strings/crackme2 -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | #ifndef FILE_MAIN 2 | #define FILE_MAIN 3 | 4 | int _putchar(char c); 5 | char *_memset(char *s, char b, unsigned int n); 6 | char *_memcpy(char *dest, char *src, unsigned int n); 7 | char *_strchr(char *s, char c); 8 | unsigned int _strspn(char *s, char *accept); 9 | char *_strpbrk(char *s, char *accept); 10 | char *_strstr(char *haystack, char *needle); 11 | void print_chessboard(char (*a)[8]); 12 | void print_diagsums(int *a, int size); 13 | void set_string(char **s, char *to); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /0x08-recursion/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | _puts_recursion("Puts with recursion"); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/0-puts_recursion -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _puts_recursion - prints a string followed by a new line 4 | *@s:character to be printed 5 | *Return:returns void 6 | */ 7 | void _puts_recursion(char *s) 8 | { 9 | if (*s == '\0') 10 | _putchar('\n'); 11 | else 12 | { 13 | _putchar(s[0]); 14 | _puts_recursion(s + 1); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x08-recursion/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | _print_rev_recursion("\nColton Walker"); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/1-print_rev_recursion -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _print_rev_recursion - function that prints a string in reverse. 4 | *@s: parameter string 5 | * 6 | */ 7 | void _print_rev_recursion(char *s) 8 | { 9 | if (*s != '\0') 10 | { 11 | _print_rev_recursion(s + 1); 12 | _putchar(*s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /0x08-recursion/100-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = is_palindrome("level"); 13 | printf("%d\n", r); 14 | r = is_palindrome("redder"); 15 | printf("%d\n", r); 16 | r = is_palindrome("test"); 17 | printf("%d\n", r); 18 | r = is_palindrome("step on no pets"); 19 | printf("%d\n", r); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x08-recursion/100-palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/100-palindrome -------------------------------------------------------------------------------- /0x08-recursion/101-wildcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/101-wildcmp -------------------------------------------------------------------------------- /0x08-recursion/101-wildcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * wildcmp - compares two strings and returns 1 if identical 5 | * @s1: string to be checked 6 | * @s2: pattern to be used 7 | * 8 | * Return: 1 if identical, 0 otherwise 9 | */ 10 | 11 | int wildcmp(char *s1, char *s2) 12 | { 13 | if (*s2 == '\0') 14 | return (*s1 == '\0'); 15 | if (*s2 == *s1) 16 | return (*s1 != '\0' && wildcmp(s1 + 1, s2 + 1)); 17 | if (*s2 == '*') 18 | return (wildcmp(s1, s2 + 1) || (*s1 != '\0' && wildcmp(s1 + 1, s2))); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/2-strlen_recursion -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strlen_recursion - gives length of a string 4 | * @s: string to be measured 5 | *Return: length of the string 6 | */ 7 | 8 | int _strlen_recursion(char *s) 9 | { 10 | int len = 0; 11 | 12 | if (*s != '\0') 13 | { 14 | len++; 15 | len += _strlen_recursion(s + 1); 16 | } 17 | return (len); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/3-factorial: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/3-factorial -------------------------------------------------------------------------------- /0x08-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * factorial - searchs for the factorial of a number 5 | * @n: the number to find the factorial of 6 | * 7 | * Return: the factorial of the number 8 | */ 9 | 10 | int factorial(int n) 11 | { 12 | int next; 13 | 14 | if (n == 0) 15 | return (1); 16 | else if (n < 0) 17 | return (-1); 18 | 19 | next = factorial(n - 1); 20 | return (n * next); 21 | } 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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x08-recursion/4-pow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/4-pow -------------------------------------------------------------------------------- /0x08-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _pow_recursion - function that returns the 4 | * value of x raised to the power of y 5 | *@x: the base 6 | *@y: the exponent 7 | *Return: the value of x raised to the power of y 8 | */ 9 | int _pow_recursion(int x, int y) 10 | { 11 | if (y < 0) 12 | return (-1); 13 | else if (y == 0) 14 | return (1); 15 | return (_pow_recursion(x, y - 1) * x); 16 | } 17 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/5-sqrt -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _sqrt_recursion - returns the natural square root of a number 5 | * @n: number to be used 6 | * 7 | * Return: the square root of n 8 | */ 9 | 10 | int _sqrt_recursion(int n) 11 | { 12 | if (n == 0 || n == 1) 13 | return (n); 14 | return (_sqrt(0, n)); 15 | } 16 | 17 | /** 18 | * _sqrt - returns the square root of a number 19 | * @n: test number 20 | * @x: squared number 21 | * 22 | * Return: the square root of n 23 | */ 24 | 25 | int _sqrt(int n, int x) 26 | { 27 | if (n > x / 2) 28 | return (-1); 29 | else if (n * n == x) 30 | return (n); 31 | return (_sqrt(n + 1, x)); 32 | } 33 | -------------------------------------------------------------------------------- /0x08-recursion/6-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = is_prime_number(1); 13 | printf("%d\n", r); 14 | r = is_prime_number(1024); 15 | printf("%d\n", r); 16 | r = is_prime_number(16); 17 | printf("%d\n", r); 18 | r = is_prime_number(17); 19 | printf("%d\n", r); 20 | r = is_prime_number(25); 21 | printf("%d\n", r); 22 | r = is_prime_number(-1); 23 | printf("%d\n", r); 24 | r = is_prime_number(113); 25 | printf("%d\n", r); 26 | r = is_prime_number(7919); 27 | printf("%d\n", r); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x08-recursion/6-prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x08-recursion/6-prime -------------------------------------------------------------------------------- /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 | 15 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isupper - function that verifies if a character is uppercase or not 4 | *@c: tested character 5 | *Return: returns 1 if it is uppercase , 0 if not 6 | */ 7 | 8 | int _isupper(int c) 9 | { 10 | if ((c >= 'A') && (c <= 'Z')) 11 | return (1); 12 | 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/0-isupper.o -------------------------------------------------------------------------------- /0x09-static_libraries/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_memset - The _memset() function fills 4 | * the first n bytes of the memory area 5 | * pointed to by s with the constant byte b 6 | *@s:target 7 | *@b: constant byte 8 | *@n:number of byte 9 | *Return: returns new value of target 10 | */ 11 | 12 | char *_memset(char *s, char b, unsigned int n) 13 | { 14 | while (n) 15 | { 16 | s[n - 1] = b; 17 | n--; 18 | } 19 | return (s); 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/0-memset.o -------------------------------------------------------------------------------- /0x09-static_libraries/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_strcat - concatenates the string pointed to by @src to 5 | * the end of the string pointed to by @dest 6 | *@dest: String that will be appended 7 | *@src: String to be concatenated upon 8 | * 9 | * Return: returns poiner to @dest 10 | */ 11 | 12 | char *_strcat(char *dest, char *src) 13 | { 14 | 15 | int index = 0, dest_len = 0; 16 | 17 | while (dest[index++]) 18 | dest_len++; 19 | 20 | for (index = 0; src[index]; index++) 21 | dest[dest_len++] = src[index]; 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isdigit - function that verifies if a character is a digit or not 4 | *@c: tested character 5 | *Return: returns 1 if it is uppercase , 0 if not 6 | */ 7 | 8 | int _isdigit(int c) 9 | { 10 | if ((c >= 48) && (c <= 57)) 11 | return (1); 12 | 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x09-static_libraries/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/1-isdigit.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_memcpy - The _memcpy() function copies n bytes 4 | * from memory area src to memory area dest 5 | *@dest:area where bytes are copied to 6 | *@src:area where bytes are copied from 7 | *@n:number of bytes to copy 8 | *Return: returns a pointer to n 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | unsigned int i = 0; 13 | 14 | for (; i < n; i++) 15 | dest[i] = src[i]; 16 | 17 | return (dest); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/1-memcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strncat - concatenate two strings but add inputted number of bytes 4 | *@dest: string to be appended upon 5 | *@src: string to be completed at end of dest 6 | *@n:integer parameter to compare index to 7 | *Return: returns new concatenated string 8 | */ 9 | 10 | char *_strncat(char *dest, char *src, int n) 11 | { 12 | 13 | int index = 0, dest_len = 0; 14 | 15 | while (dest[index++]) 16 | dest_len++; 17 | 18 | for (index = 0; src[index] && index < n; index++) 19 | dest[dest_len++] = src[index]; 20 | 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/1-strncat.o -------------------------------------------------------------------------------- /0x09-static_libraries/100-atoi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _atoi - changes a string to an int 3 | * @s: the string to be changed 4 | * 5 | * Return: the converted int 6 | */ 7 | int _atoi(char *s) 8 | { 9 | int i = 1; 10 | unsigned int num = 0; 11 | do { 12 | if (*s == '-') 13 | i *= -1; 14 | else if (*s >= '0' && *s <= '9') 15 | num = num * 10 + (*s - '0'); 16 | else if (num > 0) 17 | break; 18 | } while (*s++); 19 | return (num *i); 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include   3 | /** 4 | *_strchr - Returns a pointer to the first occurrence 5 | *of the character c in the string s, or NULL if the 6 | *character is not found 7 | * 8 | *@s:string targeted 9 | *@c:character targeted 10 | * 11 | *Return: returns pointer to first occcurence of c 12 | */ 13 | char *_strchr(char *s, char c) 14 | { 15 | int i; 16 | 17 | for (i = 0; (s[i] != c) && (s[i] != '\0'); i++) 18 | ; 19 | if (s[i] == c) 20 | return (s + i); 21 | else 22 | return (NULL); 23 | } 24 | -------------------------------------------------------------------------------- /0x09-static_libraries/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/2-strchr.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strlen - returns the length of a string 4 | * @s: string 5 | *Return: returns lenght; 6 | */ 7 | int _strlen(char *s) 8 | { 9 | int count, inc; 10 | inc = 0; 11 | for (count = 0; s[count] != '\0'; count++) 12 | inc++; 13 | 14 | return (inc); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/2-strncpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_islower - controls if a character is in lowercase 4 | *@c: character to be verified 5 | *Return: return 0 or 1 6 | */ 7 | int _islower(int c) 8 | { 9 | if (c >= 'a' && c <= 'z') 10 | return (1); 11 | 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/3-islower.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_puts - prints a string 4 | * @str: string to print 5 | * 6 | * Description: prints a string 7 | * On success: return the number of characters printed 8 | */ 9 | 10 | void _puts(char *str) 11 | { 12 | while (*str) 13 | _putchar(*str++); 14 | 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/3-puts.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/3-strspn.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isalpha - controls if a character is alphabetical 4 | *@c: character to be verified 5 | *Return: return 0 or 1 6 | */ 7 | int _isalpha(int c) 8 | { 9 | if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) 10 | return (1); 11 | 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x09-static_libraries/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x09-static_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/5-strstr.o -------------------------------------------------------------------------------- /0x09-static_libraries/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _abs - prints the absolute value of a number 4 | *@i: number targeted 5 | *Return: returns 0 6 | */ 7 | int _abs(int i) 8 | { 9 | if (i > 0) 10 | return (i); 11 | else if (i < 0) 12 | return (-i); 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/6-abs.o -------------------------------------------------------------------------------- /0x09-static_libraries/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strcpy - Copy paste string 4 | *@dest: destination 5 | *@src: source 6 | *Return: dest 7 | */ 8 | char *_strcpy(char *dest, char *src) 9 | { 10 | int inc = 0; 11 | while (*(src + inc) != '\0') 12 | { 13 | *(dest + inc) = *(src + inc); 14 | inc++; 15 | } 16 | *(dest + inc) = '\0'; 17 | return (dest); 18 | } 19 | -------------------------------------------------------------------------------- /0x09-static_libraries/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/_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/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/_putchar.o -------------------------------------------------------------------------------- /0x09-static_libraries/create_static_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c ./*.c 3 | ar -rc liball.a ./*.o 4 | -------------------------------------------------------------------------------- /0x09-static_libraries/liball.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/liball.a -------------------------------------------------------------------------------- /0x09-static_libraries/libmy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x09-static_libraries/libmy.a -------------------------------------------------------------------------------- /0x0A-argc_argv/0-whatsmyname.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints program name 5 | *@argc: number of arguments 6 | *@argv: array of arguments 7 | *Return: 0 8 | */ 9 | int main(int __attribute__((__unused__)) argc, char *argv[]) 10 | { 11 | printf("%s\n", argv[0]); 12 | 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x0A-argc_argv/1-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints the number of arguments 5 | *@argc: number of arguments 6 | *@argv:array of arguments 7 | *Return: the number of arguments 8 | */ 9 | 10 | int main(int argc, char __attribute__((__unused__)) *argv[]) 11 | { 12 | printf("%d\n", argc - 1); 13 | 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0A-argc_argv/2-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints all arguments it received 5 | *@argc: argument count 6 | *@argv: argument vector 7 | *Return: returns 0 8 | */ 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 | -------------------------------------------------------------------------------- /0x0A-argc_argv/3-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - prints multiplication 5 | *of two numbers 6 | *@argc: number of arguments 7 | *@argv: array of arguments 8 | *Return: returns 0 9 | */ 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | int i, j, mul; 14 | 15 | if (argc <= 2) 16 | { 17 | printf("Error\n"); 18 | return (1); 19 | } 20 | 21 | i = atoi(argv[1]); 22 | j = atoi(argv[2]); 23 | mul = i * j; 24 | 25 | printf("%d\n", mul); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x0A-argc_argv/4-add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | *main - adds positive numbers 6 | *@argc: number of arguments 7 | *@argv: array of arguments 8 | *Return: 0 on success, 1 on failure 9 | */ 10 | 11 | int main(int argc, char *argv[]) 12 | { 13 | int i, j, sum = 0; 14 | 15 | for (i = 1; i < argc; i++) 16 | { 17 | for (j = 0; argv[i][j] != '\0'; j++) 18 | { 19 | if (argv[i][j] < '0' || argv[i][j] > '9') 20 | { 21 | printf("Error\n"); 22 | return (1); 23 | } 24 | } 25 | 26 | sum += atoi(argv[i]); 27 | } 28 | 29 | printf("%d\n", sum); 30 | 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x0A-argc_argv/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/add -------------------------------------------------------------------------------- /0x0A-argc_argv/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/args -------------------------------------------------------------------------------- /0x0A-argc_argv/change: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/change -------------------------------------------------------------------------------- /0x0A-argc_argv/mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/mul -------------------------------------------------------------------------------- /0x0A-argc_argv/mynewnameis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/mynewnameis -------------------------------------------------------------------------------- /0x0A-argc_argv/nargs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0A-argc_argv/nargs -------------------------------------------------------------------------------- /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("ALX SE"); 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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0B-malloc_free/4-free_grid.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * free_grid - frees a 2d array 5 | *@grid:memory block to be freed 6 | *@height:height of the array 7 | *Return:returns void 8 | */ 9 | 10 | void free_grid(int **grid, int height) 11 | { 12 | int i; 13 | 14 | for (i = 0; i < height; i++) 15 | free(grid[i]); 16 | 17 | free(grid); 18 | } 19 | -------------------------------------------------------------------------------- /0x0B-malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/a -------------------------------------------------------------------------------- /0x0B-malloc_free/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/args -------------------------------------------------------------------------------- /0x0B-malloc_free/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/c -------------------------------------------------------------------------------- /0x0B-malloc_free/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/f -------------------------------------------------------------------------------- /0x0B-malloc_free/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/g -------------------------------------------------------------------------------- /0x0B-malloc_free/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | 6 | void free_grid(int **grid, int height); 7 | char *create_array(unsigned int size, char c); 8 | char *_strdup(char *str); 9 | char *str_concat(char *s1, char *s2); 10 | char *argstostr(int ac, char **av); 11 | char **strtow(char *str); 12 | int **alloc_grid(int width, int height); 13 | int len(char *str); 14 | int num_words(char *str); 15 | #endif /* MAIN_H */ 16 | -------------------------------------------------------------------------------- /0x0B-malloc_free/s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/s -------------------------------------------------------------------------------- /0x0B-malloc_free/strtow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0B-malloc_free/strtow -------------------------------------------------------------------------------- /0x0C-more_malloc_free/0-malloc_checked.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * malloc_checked - allocates memory using malloc, exit(98) if it fails 5 | * @b: size of the memory block to be allocated 6 | * 7 | * Return: pointer to the address of the memory block 8 | */ 9 | void *malloc_checked(unsigned int b) 10 | { 11 | void *block; 12 | 13 | block = malloc(b); 14 | if (block == NULL) 15 | exit(98); 16 | return (block); 17 | } 18 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/1-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | #include 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *concat; 12 | 13 | concat = string_nconcat("Best ", "School !!!", 6); 14 | printf("%s\n", concat); 15 | free(concat); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/1-string_nconcat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/1-string_nconcat -------------------------------------------------------------------------------- /0x0C-more_malloc_free/100-realloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/100-realloc -------------------------------------------------------------------------------- /0x0C-more_malloc_free/101-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/101-mul -------------------------------------------------------------------------------- /0x0C-more_malloc_free/2-calloc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/2-calloc -------------------------------------------------------------------------------- /0x0C-more_malloc_free/2-calloc.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _calloc - allocate memory using malloc and initialize it to zero 5 | *@nmemb: number of elements 6 | *@size: size of the memory block to be allocated 7 | * 8 | *Return: poiner to the address of the memory block 9 | */ 10 | void *_calloc(unsigned int nmemb, unsigned int size) 11 | { 12 | char *block; 13 | unsigned int i; 14 | 15 | if (nmemb == 0 || size == 0) 16 | return (NULL); 17 | block = malloc(nmemb * size); 18 | if (block != NULL) 19 | { 20 | for (i = 0; i < (nmemb * size); i++) 21 | block[i] = 0; 22 | return (block); 23 | } 24 | else 25 | return (NULL); 26 | } 27 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/3-array_range: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/3-array_range -------------------------------------------------------------------------------- /0x0C-more_malloc_free/3-array_range.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * array_range - creates an array of integers 5 | * @min: smallest number in the array 6 | * @max: lagrest value in the array 7 | * 8 | * Return: pointer to the address of the memory block 9 | */ 10 | 11 | int *array_range(int min, int max) 12 | { 13 | int *block; 14 | int i, j = 0; 15 | 16 | if (min > max) 17 | return (NULL); 18 | block = malloc(sizeof(*block) * ((max - min) + 1)); 19 | if (block != NULL) 20 | { 21 | for (i = min; i <= max; i++) 22 | { 23 | block[j] = i; 24 | j++; 25 | } 26 | return (block); 27 | } 28 | else 29 | return (NULL); 30 | 31 | } 32 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/_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 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0C-more_malloc_free/a -------------------------------------------------------------------------------- /0x0D-preprocessor/0-main.c: -------------------------------------------------------------------------------- 1 | #include "0-object_like_macro.h" 2 | #include "0-object_like_macro.h" 3 | #include 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int s; 12 | 13 | s = 98 + SIZE; 14 | printf("%d\n", s); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0D-preprocessor/0-object_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef OBJECT_LIKE_MACRO_H 2 | #define OBJECT_LIKE_MACRO_H 3 | #define SIZE 1024 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /0x0D-preprocessor/02-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | *main - prints the name of 5 | *the file it was compiled from 6 | * 7 | *Return: nothing to be returned 8 | */ 9 | 10 | int main(void) 11 | { 12 | printf("%s\n", __FILE__); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0D-preprocessor/1-pi.h: -------------------------------------------------------------------------------- 1 | #ifndef PI_H 2 | #define PI_H 3 | 4 | #define PI 3.14159265359 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x0D-preprocessor/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | *main - prints the name of 5 | *the file it was compiled from 6 | * 7 | *Return: nothing to be returned 8 | */ 9 | 10 | int main(void) 11 | { 12 | printf("%s\n", __FILE__); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x0D-preprocessor/3-function_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_LIKE_MACRO_H 2 | #define FUNCTION_LIKE_MACRO_H 3 | 4 | #define ABS(x) (((x) < (0)) ? ((x) * (-1)) : (x)) 5 | 6 | #endif 7 | 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | s = SUM(98, 1024); 14 | printf("%d\n", s); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0D-preprocessor/4-sum.h: -------------------------------------------------------------------------------- 1 | #ifndef SUM_H 2 | #define SUM_H 3 | 4 | #define SUM(x, y) ((x) + (y)) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x0D-preprocessor/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/a -------------------------------------------------------------------------------- /0x0D-preprocessor/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/b -------------------------------------------------------------------------------- /0x0D-preprocessor/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/c -------------------------------------------------------------------------------- /0x0D-preprocessor/cc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/cc -------------------------------------------------------------------------------- /0x0D-preprocessor/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/d -------------------------------------------------------------------------------- /0x0D-preprocessor/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0D-preprocessor/e -------------------------------------------------------------------------------- /0x0E-structures_typedef/0-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 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | 3 | /** 4 | * init_dog - inits a variable of 5 | *type dog 6 | *@d: dog identification 7 | *@name: name of dog 8 | *@age: age of dog 9 | *@owner: owner's name 10 | */ 11 | 12 | void init_dog(struct dog *d, char *name, float age, char *owner) 13 | { 14 | if (d != NULL) 15 | { 16 | (*d).name = name; 17 | (*d).age = age; 18 | (*d).owner = owner; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-print_dog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dog.h" 4 | /** 5 | * print_dog - prints a struct dog 6 | * @d: struct dog to print 7 | */ 8 | void print_dog(struct dog *d) 9 | { 10 | if (d == NULL) 11 | return; 12 | if (d->name == NULL) 13 | d->name = "(nil)"; 14 | if (d->owner == NULL) 15 | d->owner = "(nil)"; 16 | printf("Name: %s\nAge: %f\nOwner: %s\n", d->name, d->age,d->owner); 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/3-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.name = "Poppy"; 14 | my_dog.age = 3.5; 15 | my_dog.owner = "Bob"; 16 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-free_dog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | *free_dog - Frees dog 6 | *@d: dog to be freed 7 | * 8 | */ 9 | void free_dog(dog_t *d) 10 | { 11 | if (d) 12 | { 13 | free(d->name); 14 | free(d->owner); 15 | free(d); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/a -------------------------------------------------------------------------------- /0x0E-structures_typedef/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/b -------------------------------------------------------------------------------- /0x0E-structures_typedef/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/c -------------------------------------------------------------------------------- /0x0E-structures_typedef/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/d -------------------------------------------------------------------------------- /0x0E-structures_typedef/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/e -------------------------------------------------------------------------------- /0x0E-structures_typedef/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0E-structures_typedef/f -------------------------------------------------------------------------------- /0x0F-function_pointers/0-print_name.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | *print_name - prints a name 5 | *@name:name to print 6 | *@f: function which print name 7 | */ 8 | 9 | void print_name(char *name, void (*f)(char *)) 10 | { 11 | 12 | if (name == NULL || f == NULL) 13 | return; 14 | 15 | f(name); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /0x0F-function_pointers/1-array_iterator.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | *array_iterator - executes a function on each element of an array 5 | *@array: array to be targeted 6 | *@size: size of array 7 | *@action: function to be executed 8 | * 9 | */ 10 | 11 | void array_iterator(int *array, size_t size, void (*action)(int)) 12 | { 13 | 14 | if (array == NULL || action == NULL) 15 | return; 16 | 17 | while (size-- > 0) 18 | { 19 | action(*array); 20 | array++; 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-calc.h: -------------------------------------------------------------------------------- 1 | #ifndef CALC_H 2 | #define CALC_H 3 | 4 | /** 5 | *struct op - Struct op 6 | *@op: The operator 7 | *@f: The function associated 8 | */ 9 | typedef struct op 10 | { 11 | char *op; 12 | int (*f)(int a, int b); 13 | } op_t; 14 | 15 | int op_add(int a, int b); 16 | int op_sub(int a, int b); 17 | int op_mul(int a, int b); 18 | int op_div(int a, int b); 19 | int op_mod(int a, int b); 20 | int (*get_op_func(char *s))(int, int); 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /0x0F-function_pointers/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0F-function_pointers/a -------------------------------------------------------------------------------- /0x0F-function_pointers/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0F-function_pointers/b -------------------------------------------------------------------------------- /0x0F-function_pointers/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0F-function_pointers/c -------------------------------------------------------------------------------- /0x0F-function_pointers/calc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0F-function_pointers/calc -------------------------------------------------------------------------------- /0x0F-function_pointers/function_pointers.h: -------------------------------------------------------------------------------- 1 | #ifndef FUNCTION_POINTERS_H 2 | #define FUNCTION_POINTERS_H 3 | 4 | #include 5 | #include 6 | 7 | void print_name(char *name, void (*f)(char *)); 8 | void array_iterator(int *array, size_t size, void (*action)(int)); 9 | int int_index(int *array, int size, int (*cmp)(int)); 10 | 11 | #endif /*MAIN_H*/ 12 | -------------------------------------------------------------------------------- /0x0F-function_pointers/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x0F-function_pointers/main -------------------------------------------------------------------------------- /0x10-variadic_functions/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "variadic_functions.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int sum; 11 | 12 | sum = sum_them_all(2, 98, 1024); 13 | printf("%d\n", sum); 14 | sum = sum_them_all(4, 98, 1024, 402, -1024); 15 | printf("%d\n", sum); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x10-variadic_functions/0-sum_them_all.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | 4 | /** 5 | *sum_them_all - sums all its parameters 6 | *@n: first parameter 7 | * 8 | *Return: 0 if n is null 9 | * or sum of parameters in other case 10 | */ 11 | 12 | int sum_them_all(const unsigned int n, ...) 13 | { 14 | 15 | va_list li; 16 | int sum = 0; 17 | unsigned int i; 18 | 19 | va_start(li, n); 20 | 21 | if (n != 0) 22 | { 23 | for (i = 0; i < n; i++) 24 | sum += va_arg(li, int); 25 | } 26 | 27 | va_end(li); 28 | return (sum); 29 | 30 | } 31 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | print_numbers(", ", 4, 0, 98, -1024, 402); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | *print_numbers - prints numbers followed by 5 | *new line 6 | *@separator: string to be printed between numbers 7 | *@n: number of integer to be passed 8 | * 9 | *Return: nothing 10 | */ 11 | 12 | void print_numbers(const char *separator, const unsigned int n, ...) 13 | { 14 | 15 | va_list li; 16 | unsigned int i; 17 | 18 | va_start(li, n); 19 | 20 | for (i = 0; i < n; i++) 21 | { 22 | 23 | 24 | printf("%d", va_arg(li, int)); 25 | 26 | if (i != (n - 1) && separator != NULL) 27 | printf("%s", separator); 28 | } 29 | printf("\n"); 30 | va_end(li); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /0x10-variadic_functions/2-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | print_strings(", ", 2, "Jay", "Django"); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x10-variadic_functions/2-print_strings.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * print_strings - prints strings 5 | *@separator: separator 6 | *@n: number of strings 7 | * 8 | *Return: nothing 9 | */ 10 | void print_strings(const char *separator, const unsigned int n, ...) 11 | { 12 | 13 | va_list li; 14 | unsigned int i; 15 | char *str; 16 | 17 | va_start(li, n); 18 | 19 | for (i = 0; i < n; i++) 20 | { 21 | str = va_arg(li, char *); 22 | if (str == NULL) 23 | printf("(nil)"); 24 | else 25 | printf("%s", str); 26 | 27 | if (i != (n - 1) && separator != NULL) 28 | printf("%s", separator); 29 | 30 | } 31 | 32 | printf("\n"); 33 | va_end(li); 34 | } 35 | -------------------------------------------------------------------------------- /0x10-variadic_functions/3-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | print_all("ceis", 'B', 3, "stSchool"); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x10-variadic_functions/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x10-variadic_functions/a -------------------------------------------------------------------------------- /0x10-variadic_functions/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x10-variadic_functions/b -------------------------------------------------------------------------------- /0x10-variadic_functions/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x10-variadic_functions/c -------------------------------------------------------------------------------- /0x10-variadic_functions/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x10-variadic_functions/d -------------------------------------------------------------------------------- /0x12-singly_linked_lists/0-print_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_list - prints all the elements of a list 5 | * 6 | * @h:pointer to the list 7 | * 8 | *Return: the number of nodes 9 | */ 10 | 11 | size_t print_list(const list_t *h) 12 | { 13 | const list_t *cursor = h; 14 | size_t count = 0; 15 | 16 | while (cursor != NULL) 17 | { 18 | if (cursor->str != NULL) 19 | printf("[%d] %s\n", cursor->len, cursor->str); 20 | else 21 | printf("[0] (nil)\n"); 22 | count += 1; 23 | cursor = cursor->next; 24 | } 25 | 26 | return (count); 27 | } 28 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * list_len - finds the number of elements in a linked list 5 | *@h: pointer to the list 6 | * 7 | *Return: the number of elements 8 | */ 9 | 10 | size_t list_len(const list_t *h) 11 | { 12 | size_t elements = 0; 13 | 14 | while (h) 15 | { 16 | elements++; 17 | h = h->next; 18 | } 19 | 20 | return (elements); 21 | } 22 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-first.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void __attribute__((constructor)) hare(void); 4 | 5 | /** 6 | * hare - Prints a string before the 7 | * main function is executed. 8 | */ 9 | void hare(void) 10 | { 11 | printf("You're beat! and yet, you must allow,\n" 12 | "I bore my house upon my back!\n"); 13 | } 14 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - check the code 4 | * 5 | * Return: Always 0. 6 | */ 7 | int main(void) 8 | { 9 | printf("(A tortoise, having pretty good sense of a hare's nature)"); 10 | printf("(challenges one to a race.)\n"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | extern printf 2 | 3 | section .text 4 | global main 5 | 6 | main: 7 | push rbp 8 | 9 | mov rdi, fmt 10 | mov rsi, msg 11 | mov rax, 0 12 | call printf 13 | 14 | pop rbp 15 | 16 | mov rax, 0 17 | ret 18 | 19 | section .data 20 | msg: db "Hello, Holberton", 0 21 | fmt: db "%s", 10, 0 22 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/101-hello_holberton.o -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-free_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *free_list - Frees a list 5 | *@head: A pointer to the list head 6 | * 7 | */ 8 | 9 | void free_list(list_t *head) 10 | { 11 | list_t *tmp; 12 | 13 | while (head) 14 | { 15 | tmp = head->next; 16 | free(head->str); 17 | free(head); 18 | head = tmp; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | list_t *head; 13 | 14 | head = NULL; 15 | add_node_end(&head, "Bob"); 16 | add_node_end(&head, "&"); 17 | add_node_end(&head, "Kris"); 18 | add_node_end(&head, "love"); 19 | add_node_end(&head, "asm"); 20 | print_list(head); 21 | free_list(head); 22 | head = NULL; 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/a -------------------------------------------------------------------------------- /0x12-singly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/b -------------------------------------------------------------------------------- /0x12-singly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/c -------------------------------------------------------------------------------- /0x12-singly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/d -------------------------------------------------------------------------------- /0x12-singly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/e -------------------------------------------------------------------------------- /0x12-singly_linked_lists/first: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/first -------------------------------------------------------------------------------- /0x12-singly_linked_lists/hello: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x12-singly_linked_lists/hello -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | listint_t *new; 14 | listint_t hello = {8, NULL}; 15 | size_t n; 16 | 17 | head = &hello; 18 | new = malloc(sizeof(listint_t)); 19 | if (new == NULL) 20 | { 21 | printf("Error\n"); 22 | return (1); 23 | } 24 | new->n = 9; 25 | new->next = head; 26 | head = new; 27 | n = print_listint(head); 28 | printf("-> %lu elements\n", n); 29 | free(new); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-print_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_listint - prints all the elements of a linked list 5 | * @h: head of the list 6 | * 7 | * Return: the number of nodes 8 | */ 9 | size_t print_listint(const listint_t *h) 10 | { 11 | const listint_t *cursor = h; 12 | size_t count = 0; 13 | 14 | while (cursor != NULL) 15 | { 16 | printf("%d\n", cursor->n); 17 | count += 1; 18 | cursor = cursor->next; 19 | } 20 | return (count); 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/1-listint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | 4 | /** 5 | *listint_len - Returns the number of elements 6 | *in a linked listint_t list 7 | *@h: A pointer to the head of the list 8 | * 9 | * 10 | *Return: the number of elements in the listint_t list 11 | */ 12 | 13 | size_t listint_len(const listint_t *h) 14 | { 15 | size_t nodes = 0; 16 | 17 | while (h) 18 | { 19 | nodes++; 20 | h = h->next; 21 | } 22 | return (nodes); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | listint_t *new; 14 | listint_t hello = {8, NULL}; 15 | size_t n; 16 | 17 | head = &hello; 18 | new = malloc(sizeof(listint_t)); 19 | if (new == NULL) 20 | { 21 | printf("Error\n"); 22 | return (1); 23 | } 24 | new->n = 9; 25 | new->next = head; 26 | head = new; 27 | n = listint_len(head); 28 | printf("-> %lu elements\n", n); 29 | free(new); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/2-add_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *add_nodeint - Adds a new node at the beginning 5 | *of a listint_t list 6 | *@head: A pointer to the address of the head of the listint_t list 7 | *@n: the integer for the new node to contain 8 | * 9 | *Return: NULL if function fails 10 | *Or address of element 11 | */ 12 | 13 | listint_t *add_nodeint(listint_t **head, const int n) 14 | { 15 | listint_t *new; 16 | 17 | new = malloc(sizeof(listint_t)); 18 | if (new == NULL) 19 | return (NULL); 20 | 21 | new->n = n; 22 | new->next = *head; 23 | 24 | *head = new; 25 | 26 | return (new); 27 | } 28 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | 14 | head = NULL; 15 | add_nodeint(&head, 0); 16 | add_nodeint(&head, 1); 17 | add_nodeint(&head, 2); 18 | add_nodeint(&head, 3); 19 | add_nodeint(&head, 4); 20 | add_nodeint(&head, 98); 21 | add_nodeint(&head, 402); 22 | add_nodeint(&head, 1024); 23 | print_listint(head); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | 14 | head = NULL; 15 | add_nodeint_end(&head, 0); 16 | add_nodeint_end(&head, 1); 17 | add_nodeint_end(&head, 2); 18 | add_nodeint_end(&head, 3); 19 | add_nodeint_end(&head, 4); 20 | add_nodeint_end(&head, 98); 21 | add_nodeint_end(&head, 402); 22 | add_nodeint_end(&head, 1024); 23 | print_listint(head); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/4-free_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *free_listint - frees a linked list 5 | *@head: head of the list 6 | * 7 | *Return: void 8 | */ 9 | 10 | void free_listint(listint_t *head) 11 | { 12 | listint_t *temp; 13 | 14 | while (head != NULL) 15 | { 16 | temp = head; 17 | head = head->next; 18 | free(temp); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | 14 | head = NULL; 15 | add_nodeint_end(&head, 0); 16 | add_nodeint_end(&head, 1); 17 | add_nodeint_end(&head, 2); 18 | add_nodeint_end(&head, 3); 19 | add_nodeint_end(&head, 4); 20 | add_nodeint_end(&head, 98); 21 | add_nodeint_end(&head, 402); 22 | add_nodeint_end(&head, 1024); 23 | print_listint(head); 24 | free_listint(head); 25 | head = NULL; 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-free_listint2.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_listint2 - Frees a listint_t list. 5 | * @head: A pointer to the address of the 6 | * head of the listint_t list. 7 | * 8 | * Description: Sets the head to NULL. 9 | */ 10 | void free_listint2(listint_t **head) 11 | { 12 | listint_t *tmp; 13 | 14 | if (head == NULL) 15 | return; 16 | 17 | while (*head) 18 | { 19 | tmp = (*head)->next; 20 | free(*head); 21 | *head = tmp; 22 | } 23 | 24 | head = NULL; 25 | } 26 | 27 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | listint_t *head; 13 | 14 | head = NULL; 15 | add_nodeint_end(&head, 0); 16 | add_nodeint_end(&head, 1); 17 | add_nodeint_end(&head, 2); 18 | add_nodeint_end(&head, 3); 19 | add_nodeint_end(&head, 4); 20 | add_nodeint_end(&head, 98); 21 | add_nodeint_end(&head, 402); 22 | add_nodeint_end(&head, 1024); 23 | print_listint(head); 24 | free_listint2(&head); 25 | printf("%p\n", (void *)head); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/6-pop_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * pop_listint - Deletes the head node of a listint_t list. 5 | * @head: A pointer to the address of the 6 | * head of the listint_t list. 7 | * 8 | * Return: If the linked list is empty - 0. 9 | * Otherwise - The head node's data (n). 10 | */ 11 | int pop_listint(listint_t **head) 12 | { 13 | listint_t *tmp; 14 | int ret; 15 | 16 | if (*head == NULL) 17 | return (0); 18 | 19 | tmp = *head; 20 | ret = (*head)->n; 21 | *head = (*head)->next; 22 | 23 | free(tmp); 24 | 25 | return (ret); 26 | } 27 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/7-get_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *get_nodeint_at_index - return the nth node of a linked list 5 | *@head: pointer to the head of the list 6 | *@index: index of the node required 7 | * 8 | *Return: the address of the node 9 | */ 10 | 11 | listint_t *get_nodeint_at_index(listint_t *head, unsigned int index) 12 | { 13 | listint_t *cursor = NULL; 14 | unsigned int i = 0; 15 | 16 | while (head != NULL) 17 | { 18 | if (i <= index) 19 | { 20 | if (i == index) 21 | { 22 | cursor = head; 23 | break; 24 | } 25 | head = head->next; 26 | i++; 27 | } 28 | else 29 | return (NULL); 30 | } 31 | return (cursor); 32 | } 33 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/8-sum_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *sum_listint - sums up all the data in a linked list 5 | *@head: head of the list 6 | * 7 | *Return: sum of the number 8 | */ 9 | 10 | int sum_listint(listint_t *head) 11 | { 12 | listint_t *cursor = head; 13 | size_t sum = 0; 14 | 15 | while (cursor != NULL) 16 | { 17 | sum += cursor->n; 18 | cursor = cursor->next; 19 | } 20 | return (sum); 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/a -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/b -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/c -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/d -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/e -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/f -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/g -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/h -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/i -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/j: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/j -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/k -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/l -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/m -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/n: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/n -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/next: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/next -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x13-more_singly_linked_lists/o -------------------------------------------------------------------------------- /0x14-bit_manipulation/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | unsigned int n; 11 | 12 | n = binary_to_uint("1"); 13 | printf("%u\n", n); 14 | n = binary_to_uint("101"); 15 | printf("%u\n", n); 16 | n = binary_to_uint("1e01"); 17 | printf("%u\n", n); 18 | n = binary_to_uint("1100010"); 19 | printf("%u\n", n); 20 | n = binary_to_uint("0000000000000000000110010010"); 21 | printf("%u\n", n); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_binary(0); 11 | printf("\n"); 12 | print_binary(1); 13 | printf("\n"); 14 | print_binary(98); 15 | printf("\n"); 16 | print_binary(1024); 17 | printf("\n"); 18 | print_binary((1 << 10) + 1); 19 | printf("\n"); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/1-print_binary.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *print_binary - prints the binary representation of a number 5 | *@n: number to be printed 6 | * 7 | *Return: void 8 | */ 9 | 10 | void print_binary(unsigned long int n) 11 | { 12 | if (n > 1) 13 | print_binary(n >> 1); 14 | 15 | _putchar((n & 1) + '0'); 16 | } 17 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-get_endianness.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * get_endianness - checks if is big endian or little 4 | * 5 | * Return: if little 1 , 0 otherwise 6 | */ 7 | int get_endianness(void) 8 | { 9 | unsigned int test = 1; 10 | char *endian = (char *)&test; 11 | 12 | if (*endian) 13 | { 14 | return (1); 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * main - Write a function that checks the endianness 6 | * 7 | * Return: 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | n = get_endianness(); 15 | if (n != 0) 16 | { 17 | printf("Little Endian\n"); 18 | } 19 | else 20 | { 21 | printf("Big Endian\n"); 22 | } 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/101-password: -------------------------------------------------------------------------------- 1 | Congratulations! 2 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-get_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *get_bit - get the value of a bit at the given index 5 | *@n: the number 6 | *@index: index starting from 0 of the bit required 7 | * 8 | *Return: The converted value 9 | */ 10 | 11 | int get_bit(unsigned long int n, unsigned int index) 12 | { 13 | if (index > 63) 14 | return (-1); 15 | 16 | return ((n >> index) & 1); 17 | } 18 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int n; 11 | 12 | n = get_bit(1024, 10); 13 | printf("%d\n", n); 14 | n = get_bit(98, 1); 15 | printf("%d\n", n); 16 | n = get_bit(1024, 0); 17 | printf("%d\n", n); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | unsigned long int n; 11 | 12 | n = 1024; 13 | set_bit(&n, 5); 14 | printf("%lu\n", n); 15 | n = 0; 16 | set_bit(&n, 10); 17 | printf("%lu\n", n); 18 | n = 98; 19 | set_bit(&n, 0); 20 | printf("%lu\n", n); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-set_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *set_bit - sets a bit at position to 1 5 | *@n: number to be used 6 | *@index: index to be set 7 | * 8 | *Return: 1 on success, -1 on failure 9 | */ 10 | 11 | int set_bit(unsigned long int *n, unsigned int index) 12 | { 13 | if (n == NULL || (index > (sizeof(unsigned long int) * 8) - 1)) 14 | return (-1); 15 | 16 | *n |= (1 << index); 17 | return (1); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-clear_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *clear_bit - sets a bit at a position to 0 5 | *@n: number to be used 6 | *@index: position to be cleared 7 | * 8 | *Return: 1 on success, -1 on fail 9 | */ 10 | 11 | int clear_bit(unsigned long int *n, unsigned int index) 12 | { 13 | if (n == NULL || (index > (sizeof(unsigned long int) * 8) - 1)) 14 | return (-1); 15 | 16 | *n &= ~(1 << index); 17 | return (1); 18 | } 19 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | unsigned long int n; 11 | 12 | n = 1024; 13 | clear_bit(&n, 10); 14 | printf("%lu\n", n); 15 | n = 0; 16 | clear_bit(&n, 10); 17 | printf("%lu\n", n); 18 | n = 98; 19 | clear_bit(&n, 1); 20 | printf("%lu\n", n); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-flip_bits.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * flip_bits - gets the number of bits to flip to get from n to m 5 | * @n : number 6 | * @m : final number 7 | * 8 | * Return: the number of flipped bits 9 | */ 10 | unsigned int flip_bits(unsigned long int n, unsigned long int m) 11 | { 12 | unsigned long int flipped = n ^ m; 13 | int count = 0; 14 | 15 | while (flipped) 16 | { 17 | if (flipped & 1) 18 | count++; 19 | flipped >>= 1; 20 | } 21 | return (count); 22 | } 23 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | /** 4 | * main - check the code 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | unsigned int n; 11 | 12 | n = flip_bits(1024, 1); 13 | printf("%u\n", n); 14 | n = flip_bits(402, 98); 15 | printf("%u\n", n); 16 | n = flip_bits(1024, 3); 17 | printf("%u\n", n); 18 | n = flip_bits(1024, 1025); 19 | printf("%u\n", n); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/_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 | 15 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/a -------------------------------------------------------------------------------- /0x14-bit_manipulation/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/b -------------------------------------------------------------------------------- /0x14-bit_manipulation/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/c -------------------------------------------------------------------------------- /0x14-bit_manipulation/crackme3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/crackme3 -------------------------------------------------------------------------------- /0x14-bit_manipulation/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/d -------------------------------------------------------------------------------- /0x14-bit_manipulation/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/e -------------------------------------------------------------------------------- /0x14-bit_manipulation/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/f -------------------------------------------------------------------------------- /0x14-bit_manipulation/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x14-bit_manipulation/h -------------------------------------------------------------------------------- /0x14-bit_manipulation/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | 7 | unsigned int binary_to_uint(const char *b); 8 | int check_valid_string(const char *b); 9 | int _putchar(char c); 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 | -------------------------------------------------------------------------------- /0x15-file_io/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "main.h" 4 | /** 5 | * main - check the code 6 | * @av : av . 7 | * @ac : ac . 8 | * 9 | * Return: Always 0. 10 | */ 11 | int main(int ac, char **av) 12 | { 13 | ssize_t n; 14 | 15 | if (ac != 2) 16 | { 17 | dprintf(2, "Usage: %s filename\n", av[0]); 18 | exit(1); 19 | } 20 | n = read_textfile(av[1], 114); 21 | printf("\n(printed chars: %li)\n", n); 22 | n = read_textfile(av[1], 1024); 23 | printf("\n(printed chars: %li)\n", n); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x15-file_io/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "main.h" 4 | /** 5 | * main - check the code 6 | * 7 | * @av : av 8 | * @ac :ac 9 | * Return: Always 0. 10 | */ 11 | int main(int ac, char **av) 12 | { 13 | int res; 14 | 15 | if (ac != 3) 16 | { 17 | dprintf(2, "Usage: %s filename text\n", av[0]); 18 | exit(1); 19 | } 20 | res = create_file(av[1], av[2]); 21 | printf("-> %i)\n", res); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x15-file_io/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "main.h" 4 | /** 5 | * main - check the code 6 | * 7 | * @ac : ac . 8 | * @av : av . 9 | * Return: Always 0. 10 | */ 11 | int main(int ac, char **av) 12 | { 13 | int res; 14 | 15 | if (ac != 3) 16 | { 17 | dprintf(2, "Usage: %s filename text\n", av[0]); 18 | exit(1); 19 | } 20 | res = append_text_to_file(av[1], av[2]); 21 | printf("-> %i)\n", res); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x15-file_io/Incitatous: -------------------------------------------------------------------------------- 1 | Why you should think twice before putting pictures on social media. 2 | (What you always wanted to know about @Incitatous) 3 | #PrivacyAware 4 | http://imgur.com/a/Mq1tc 5 | -------------------------------------------------------------------------------- /0x15-file_io/Requiescat: -------------------------------------------------------------------------------- 1 | Requiescat 2 | by Oscar Wilde 3 | 4 | Tread lightly, she is near 5 | Under the snow, 6 | Speak gently, she can hear 7 | The daisies grow. 8 | 9 | All her bright golden hair 10 | Tarnished with rust, 11 | She that was young and fair 12 | Fallen to dust. 13 | 14 | Lily-like, white as snow, 15 | She hardly knew 16 | She was a woman, so 17 | Sweetly she grew. 18 | 19 | Coffin-board, heavy stone, 20 | Lie on her breast, 21 | I vex my heart alone, 22 | She is at rest. 23 | 24 | Peace, Peace, she cannot hear 25 | Lyre or sonnet, 26 | All my life's buried here, 27 | Heap earth upon it. 28 | -------------------------------------------------------------------------------- /0x15-file_io/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x15-file_io/a -------------------------------------------------------------------------------- /0x15-file_io/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x15-file_io/b -------------------------------------------------------------------------------- /0x15-file_io/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x15-file_io/c -------------------------------------------------------------------------------- /0x15-file_io/cp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x15-file_io/cp -------------------------------------------------------------------------------- /0x15-file_io/hello: -------------------------------------------------------------------------------- 1 | Hello World! 2 | -------------------------------------------------------------------------------- /0x15-file_io/incitatous: -------------------------------------------------------------------------------- 1 | Why you should think twice before putting pictures on social media. 2 | (What you always wanted to know about @Incitatous) 3 | #PrivacyAware 4 | http://imgur.com/a/Mq1tc 5 | -------------------------------------------------------------------------------- /0x15-file_io/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | ssize_t read_textfile(const char *filename, size_t letters); 10 | int create_file(const char *filename, char *text_content); 11 | int append_text_to_file(const char *filename, char *text_content); 12 | 13 | #endif /* MAIN_H */ 14 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/0-print_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_dlistint- prints elements of a linked list 5 | * 6 | * @h: first node of the linked list 7 | * Return: number of elements in the linked list 8 | */ 9 | size_t print_dlistint(const dlistint_t *h) 10 | { 11 | size_t count = 0; 12 | 13 | while (h != NULL) 14 | { 15 | printf("%d\n", h->n); 16 | 17 | h = h->next; 18 | 19 | count++; 20 | } 21 | 22 | return (count); 23 | } 24 | 25 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/1-dlistint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * dlistint_len - returns number of elements in a linked list 5 | * 6 | * @h: first node of linked list 7 | * Return: number of elements in the linked list 8 | */ 9 | size_t dlistint_len(const dlistint_t *h) 10 | { 11 | size_t count = 0; 12 | 13 | while (h != NULL) 14 | { 15 | h = h->next; 16 | count++; 17 | } 18 | 19 | return (count); 20 | } 21 | 22 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/100-password: -------------------------------------------------------------------------------- 1 | en C Pyfo neZ 2 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/102-result: -------------------------------------------------------------------------------- 1 | 906609 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | /** 6 | * main - check the code 7 | * 8 | * Return: Always EXIT_SUCCESS. 9 | */ 10 | int main(void) 11 | { 12 | dlistint_t *head; 13 | 14 | head = NULL; 15 | add_dnodeint(&head, 0); 16 | add_dnodeint(&head, 1); 17 | add_dnodeint(&head, 2); 18 | add_dnodeint(&head, 3); 19 | add_dnodeint(&head, 4); 20 | add_dnodeint(&head, 98); 21 | add_dnodeint(&head, 402); 22 | add_dnodeint(&head, 1024); 23 | print_dlistint(head); 24 | return (EXIT_SUCCESS); 25 | 26 | } 27 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "lists.h" 5 | 6 | /** 7 | * main - check the code 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | 15 | head = NULL; 16 | add_dnodeint_end(&head, 0); 17 | add_dnodeint_end(&head, 1); 18 | add_dnodeint_end(&head, 2); 19 | add_dnodeint_end(&head, 3); 20 | add_dnodeint_end(&head, 4); 21 | add_dnodeint_end(&head, 98); 22 | add_dnodeint_end(&head, 402); 23 | add_dnodeint_end(&head, 1024); 24 | print_dlistint(head); 25 | return (EXIT_SUCCESS); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/4-free_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_dlistint - frees a linked list 5 | * 6 | * @head: first member of list 7 | * Return: void 8 | */ 9 | void free_dlistint(dlistint_t *head) 10 | { 11 | dlistint_t *tmp = NULL; 12 | 13 | while (head != NULL) 14 | { 15 | tmp = head->next; 16 | free(head); 17 | head = tmp; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/5-get_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_dnodeint_at_index - gets a node at an index 5 | * 6 | * @head: the first node of the linked list 7 | * @index: index at which to find the node 8 | * Return: the address of wanted node, or NULL if not within list 9 | */ 10 | dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index) 11 | { 12 | unsigned int i; 13 | 14 | for (i = 0; head != NULL && i < index; i++) 15 | head = head->next; 16 | 17 | if (i == index) 18 | return (head); 19 | 20 | return (NULL); 21 | } 22 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/6-sum_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_dlistint - sums the data of a linked list 5 | * 6 | * @head: first element of linked list 7 | * Return: 0 if empty, sum otherwise 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 | 19 | return (sum); 20 | } 21 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/a -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/b -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/c -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/crackme4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/crackme4 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/crackme4.py: -------------------------------------------------------------------------------- 1 | # uncompyle6 version 3.9.0 2 | # Python bytecode version base 3.4 (3310) 3 | # Decompiled from: Python 3.8.10 (default, Mar 15 2022, 12:22:08) 4 | # [GCC 9.4.0] 5 | # Embedded file name: 100-crackme.py 6 | # Compiled at: 2017-01-05 16:44:37 7 | # Size of source mod 2**32: 195 bytes 8 | pwd = input('Password: ') 9 | ok = 'Zen of Python' 10 | ok = ok + ' C' 11 | ok = ok[1:3] + ok[3] + ok[14] + ok[3] + ok[7:9] + ok[:6][::-1] 12 | if pwd == ok: 13 | print('OK') 14 | else: 15 | print('KO') 16 | # okay decompiling crackme4.pyc -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/crackme4.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/crackme4.pyc -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/crackme5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/crackme5 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/d -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/e -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/h -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/i -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/j: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/j -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/k -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/keygen5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x17-doubly_linked_lists/keygen5 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/largest_palindrome_102.py: -------------------------------------------------------------------------------- 1 | largest_palindrome = 0 2 | 3 | for i in range(100, 1000): 4 | for j in range(100, 1000): 5 | product = i * j 6 | if str(product) == str(product)[::-1]: # Check if the product is a palindrome 7 | if product > largest_palindrome: 8 | largest_palindrome = product 9 | 10 | # Save the result to the file 11 | with open("102-result", "w") as file: 12 | file.write(str(largest_palindrome)) 13 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isupper - function that verifies if a character is uppercase or not 4 | *@c: tested character 5 | *Return: returns 1 if it is uppercase , 0 if not 6 | */ 7 | 8 | int _isupper(int c) 9 | { 10 | if ((c >= 'A') && (c <= 'Z')) 11 | return (1); 12 | 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/0-isupper.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-main.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * main - check the code 6 | * 7 | * Return: Always EXIT_SUCCESS. 8 | */ 9 | int main(void) 10 | { 11 | printf("%d\n", _strlen("My Dyn Lib")); 12 | return (EXIT_SUCCESS); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/0-main.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_memset - The _memset() function fills 4 | * the first n bytes of the memory area 5 | * pointed to by s with the constant byte b 6 | *@s:target 7 | *@b: constant byte 8 | *@n:number of byte 9 | *Return: returns new value of target 10 | */ 11 | 12 | char *_memset(char *s, char b, unsigned int n) 13 | { 14 | while (n) 15 | { 16 | s[n - 1] = b; 17 | n--; 18 | } 19 | return (s); 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/0-memset.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_strcat - concatenates the string pointed to by @src to 5 | * the end of the string pointed to by @dest 6 | *@dest: String that will be appended 7 | *@src: String to be concatenated upon 8 | * 9 | * Return: returns poiner to @dest 10 | */ 11 | 12 | char *_strcat(char *dest, char *src) 13 | { 14 | 15 | int index = 0, dest_len = 0; 16 | 17 | while (dest[index++]) 18 | dest_len++; 19 | 20 | for (index = 0; src[index]; index++) 21 | dest[dest_len++] = src[index]; 22 | 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_alphabet - Entry point 4 | * Description: print all alphabet in lowercase 5 | * print_alphabet - prints the english alphabet from a-z. 6 | * Return: Always 0 (success) 7 | */ 8 | 9 | void print_alphabet(void) 10 | { 11 | char letter; 12 | 13 | for (letter = 'a'; letter <= 'z'; letter++) 14 | { 15 | /* Description : print_alphabet call putchar from main*/ 16 | _putchar(letter); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-alphabet.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/1-alphabet.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-create_dynamic_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -fPIC -g -c -Wall -pedantic -Werror -Wextra *.c 3 | gcc -shared -Wl,-soname,liball.so -o liball.so *.o -lc 4 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isdigit - function that verifies if a character is a digit or not 4 | *@c: tested character 5 | *Return: returns 1 if it is uppercase , 0 if not 6 | */ 7 | 8 | int _isdigit(int c) 9 | { 10 | if ((c >= 48) && (c <= 57)) 11 | return (1); 12 | 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/1-isdigit.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_memcpy - The _memcpy() function copies n bytes 4 | * from memory area src to memory area dest 5 | *@dest:area where bytes are copied to 6 | *@src:area where bytes are copied from 7 | *@n:number of bytes to copy 8 | *Return: returns a pointer to n 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | unsigned int i = 0; 13 | 14 | for (; i < n; i++) 15 | dest[i] = src[i]; 16 | 17 | return (dest); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/1-memcpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strncat - concatenate two strings but add inputted number of bytes 4 | *@dest: string to be appended upon 5 | *@src: string to be completed at end of dest 6 | *@n:integer parameter to compare index to 7 | *Return: returns new concatenated string 8 | */ 9 | 10 | char *_strncat(char *dest, char *src, int n) 11 | { 12 | 13 | int index = 0, dest_len = 0; 14 | 15 | while (dest[index++]) 16 | dest_len++; 17 | 18 | for (index = 0; src[index] && index < n; index++) 19 | dest[dest_len++] = src[index]; 20 | 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/1-strncat.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-atoi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _atoi - changes a string to an int 3 | * @s: the string to be changed 4 | * 5 | * Return: the converted int 6 | */ 7 | int _atoi(char *s) 8 | { 9 | int i = 1; 10 | unsigned int num = 0; 11 | do { 12 | if (*s == '-') 13 | i *= -1; 14 | else if (*s >= '0' && *s <= '9') 15 | num = num * 10 + (*s - '0'); 16 | else if (num > 0) 17 | break; 18 | } while (*s++); 19 | return (num *i); 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/100-operations.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/100-operations.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-tests.py: -------------------------------------------------------------------------------- 1 | import random 2 | import ctypes 3 | 4 | cops = ctypes.CDLL('./100-operations.so') 5 | a = random.randint(-111, 111) 6 | b = random.randint(-111, 111) 7 | print("{} + {} = {}".format(a, b, cops.add(a, b))) 8 | print("{} - {} = {}".format(a, b, cops.sub(a, b))) 9 | print("{} x {} = {}".format(a, b, cops.mul(a, b))) 10 | print("{} / {} = {}".format(a, b, cops.div(a, b))) 11 | print("{} % {} = {}".format(a, b, cops.mod(a, b))) 12 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-gm_overhaul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * srand - Overwrites the srand function in the libc shared object 6 | * @seed: The seed to use for the random number generator. [Will be Ignored] 7 | */ 8 | void srand(unsigned int seed) 9 | { 10 | const char *nums_txt = "9 8 10 24 75 - 9\n"; 11 | const char *txt = "Congratulations, you win the Jackpot!\n"; 12 | 13 | (void)seed; 14 | write(STDOUT_FILENO, (void *)nums_txt, 17); 15 | write(STDOUT_FILENO, (void *)txt, 38); 16 | exit(EXIT_SUCCESS); 17 | } 18 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-gm_overhaul.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/101-gm_overhaul.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-make_me_win.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget -q --output-document=$HOME/lib101-gm_overhaul.so https://github.com/bdftyousra/alx-low_level_programming/blob/master/0x18-dynamic_libraries/lib101-gm_overhaul.so 3 | export LD_PRELOAD=$HOME/lib101-gm_overhaul.so 4 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-md5_gm: -------------------------------------------------------------------------------- 1 | d52e6c18e0723f5b025a75dea19ef365 gm 2 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | *_strchr - Returns a pointer to the first occurrence 5 | *of the character c in the string s, or NULL if the 6 | *character is not found 7 | * 8 | *@s:string targeted 9 | *@c:character targeted 10 | * 11 | *Return: returns pointer to first occcurence of c 12 | */ 13 | char *_strchr(char *s, char c) 14 | { 15 | int i; 16 | 17 | for (i = 0; (s[i] != c) && (s[i] != '\0'); i++) 18 | ; 19 | if (s[i] == c) 20 | return (s + i); 21 | else 22 | return (NULL); 23 | } 24 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/2-strchr.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strlen - returns the length of a string 4 | * @s: string 5 | *Return: returns lenght; 6 | */ 7 | int _strlen(char *s) 8 | { 9 | int count, inc; 10 | inc = 0; 11 | for (count = 0; s[count] != '\0'; count++) 12 | inc++; 13 | 14 | return (inc); 15 | } 16 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/2-strncpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_islower - controls if a character is in lowercase 4 | *@c: character to be verified 5 | *Return: return 0 or 1 6 | */ 7 | int _islower(int c) 8 | { 9 | if (c >= 'a' && c <= 'z') 10 | return (1); 11 | 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/3-islower.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_puts - prints a string 4 | * @str: string to print 5 | * 6 | * Description: prints a string 7 | * On success: return the number of characters printed 8 | */ 9 | 10 | void _puts(char *str) 11 | { 12 | while (*str) 13 | _putchar(*str++); 14 | 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/3-puts.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/3-strspn.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_isalpha - controls if a character is alphabetical 4 | *@c: character to be verified 5 | *Return: return 0 or 1 6 | */ 7 | int _isalpha(int c) 8 | { 9 | if ((c >= 65 && c <= 90) || (c >= 97 && c <= 122)) 10 | return (1); 11 | 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/5-strstr.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _abs - prints the absolute value of a number 4 | *@i: number targeted 5 | *Return: returns 0 6 | */ 7 | int _abs(int i) 8 | { 9 | if (i > 0) 10 | return (i); 11 | else if (i < 0) 12 | return (-i); 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/6-abs.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strcpy - Copy paste string 4 | *@dest: destination 5 | *@src: source 6 | *Return: dest 7 | */ 8 | char *_strcpy(char *dest, char *src) 9 | { 10 | int inc = 0; 11 | while (*(src + inc) != '\0') 12 | { 13 | *(dest + inc) = *(src + inc); 14 | inc++; 15 | } 16 | *(dest + inc) = '\0'; 17 | return (dest); 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/README.md: -------------------------------------------------------------------------------- 1 | # Dynamic libraries 2 | 3 | This project contains __C__ tasks for learning about dynamic libraries. 4 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/_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 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/_putchar.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/a.out -------------------------------------------------------------------------------- /0x18-dynamic_libraries/gm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/gm -------------------------------------------------------------------------------- /0x18-dynamic_libraries/init.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | 3 | /** 4 | * init_dog - inits a variable of 5 | *type dog 6 | *@d: dog identification 7 | *@name: name of dog 8 | *@age: age of dog 9 | *@owner: owner's name 10 | */ 11 | 12 | void init_dog(struct dog *d, char *name, float age, char *owner) 13 | { 14 | if (d != NULL) 15 | { 16 | (*d).name = name; 17 | (*d).age = age; 18 | (*d).owner = owner; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/init.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/init.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/len: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/len -------------------------------------------------------------------------------- /0x18-dynamic_libraries/lib101-gm_overhaul.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/lib101-gm_overhaul.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/liball.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/liball.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/libdynamic.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x18-dynamic_libraries/libdynamic.so -------------------------------------------------------------------------------- /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 array 6 | * Return: table 7 | */ 8 | hash_table_t *hash_table_create(unsigned long int size) 9 | { 10 | hash_table_t *table = malloc(sizeof(hash_table_t)); 11 | 12 | if (size <= 0) 13 | { 14 | return (NULL); 15 | } 16 | if (table == NULL) 17 | { 18 | return (NULL); 19 | } 20 | table->size = size; 21 | table->array = calloc(size, sizeof(hash_node_t *)); 22 | if (table->array == NULL) 23 | { 24 | free(table); 25 | return (NULL); 26 | } 27 | return (table); 28 | } 29 | -------------------------------------------------------------------------------- /0x1A-hash_tables/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "hash_tables.h" 5 | 6 | /** 7 | * main - check the code for 8 | * Return: Always EXIT_SUCCESS. 9 | */ 10 | 11 | int main(void) 12 | { 13 | hash_table_t *ht; 14 | 15 | ht = hash_table_create(1024); 16 | printf("%p\n", (void *)ht); 17 | return (EXIT_SUCCESS); 18 | } 19 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-djb2.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | /** 3 | * hash_djb2 - implementation of the djb2 algorithm 4 | * @str: string that generates hash value 5 | * Return: hash 6 | */ 7 | 8 | unsigned long int hash_djb2(const unsigned char *str) 9 | { 10 | unsigned long int hash; 11 | int c; 12 | 13 | hash = 5381; 14 | while ((c = *str++)) 15 | { 16 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 17 | } 18 | return (hash); 19 | } 20 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "hash_tables.h" 5 | 6 | /** 7 | * main - check the code 8 | * Return: Always EXIT_SUCCESS. 9 | */ 10 | int main(void) 11 | { 12 | char *s; 13 | 14 | s = "cisfun"; 15 | printf("%lu\n", hash_djb2((unsigned char *)s)); 16 | s = "Don't forget to tweet today"; 17 | printf("%lu\n", hash_djb2((unsigned char *)s)); 18 | s = "98"; 19 | printf("%lu\n", hash_djb2((unsigned char *)s)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1A-hash_tables/2-key_index.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | /** 3 | * key_index - Gives you the index of a key 4 | * @key: key 5 | * @size: size of the array 6 | * Return: the index at which the key/value pair should be stored 7 | * in the array of the hash table 8 | */ 9 | unsigned long int key_index(const unsigned char *key, unsigned long int size) 10 | { 11 | unsigned long int idx; 12 | 13 | if (!key || !size) 14 | { 15 | return (0); 16 | } 17 | idx = hash_djb2(key) % size; 18 | return (idx); 19 | } 20 | -------------------------------------------------------------------------------- /0x1A-hash_tables/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | #include 6 | 7 | #include "hash_tables.h" 8 | 9 | 10 | 11 | /** 12 | 13 | * main - check the code 14 | 15 | * 16 | 17 | * Return: Always EXIT_SUCCESS. 18 | 19 | */ 20 | 21 | int main(void) 22 | 23 | { 24 | 25 | hash_table_t *ht; 26 | 27 | 28 | 29 | ht = hash_table_create(1024); 30 | 31 | hash_table_set(ht, "betty", "cool"); 32 | 33 | return (EXIT_SUCCESS); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /0x1A-hash_tables/README.md: -------------------------------------------------------------------------------- 1 | # HASH TABLE AND ITS IMPLIMENTATIONS 2 | -------------------------------------------------------------------------------- /0x1A-hash_tables/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/a -------------------------------------------------------------------------------- /0x1A-hash_tables/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/b -------------------------------------------------------------------------------- /0x1A-hash_tables/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/c -------------------------------------------------------------------------------- /0x1A-hash_tables/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/d -------------------------------------------------------------------------------- /0x1A-hash_tables/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/e -------------------------------------------------------------------------------- /0x1A-hash_tables/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/f -------------------------------------------------------------------------------- /0x1A-hash_tables/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/g -------------------------------------------------------------------------------- /0x1A-hash_tables/sht: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/bdftyousra/alx-low_level_programming/ec9f9bad99ac4bed221cc754e16b4116d639e440/0x1A-hash_tables/sht -------------------------------------------------------------------------------- /0x1C-makefiles/0-Makefile: -------------------------------------------------------------------------------- 1 | # -*- MakeFile -*- 2 | 3 | all: 4 | gcc main.c holberton.c -o holberton 5 | -------------------------------------------------------------------------------- /0x1C-makefiles/1-Makefile: -------------------------------------------------------------------------------- 1 | # -*- MakeFile -*- 2 | 3 | CC = gcc 4 | 5 | SRC = main.c holberton.c 6 | 7 | all: 8 | $(CC) $(SRC) -o holberton 9 | -------------------------------------------------------------------------------- /0x1C-makefiles/100-Makefile: -------------------------------------------------------------------------------- 1 | # -*- MakeFile -*- 2 | 3 | CC = gcc 4 | 5 | SRC = main.c holberton.c 6 | 7 | OBJ = $(SRC:.c=.o) 8 | 9 | NAME = holberton 10 | 11 | CFLAGS = -Wall -Werror -Wextra -pedantic 12 | 13 | .PHONY: all clean oclean fclean re 14 | 15 | all: m.h $(OBJ) 16 | $(CC) $(OBJ) -o $(NAME) 17 | 18 | clean: 19 | $(RM) *~ $(NAME) 20 | 21 | oclean: 22 | $(RM) $(OBJ) 23 | 24 | fclean: clean oclean 25 | 26 | re: oclean all 27 | -------------------------------------------------------------------------------- /0x1C-makefiles/2-Makefile: -------------------------------------------------------------------------------- 1 | # -*- MakeFile -*- 2 | 3 | CC = gcc 4 | 5 | SRC = main.c holberton.c 6 | 7 | OBJ = $(SRC:%.c=%.o) 8 | 9 | NAME = holberton 10 | 11 | all: $(OBJ) 12 | $(CC) $(OBJ) -o $(NAME) 13 | -------------------------------------------------------------------------------- /0x1C-makefiles/3-Makefile: -------------------------------------------------------------------------------- 1 | # -*- MakeFile -*- 2 | 3 | CC = gcc 4 | 5 | SRC = main.c holberton.c 6 | 7 | OBJ = $(SRC:%.c=%.o) 8 | 9 | NAME = holberton 10 | 11 | RM = rm -f 12 | 13 | all: $(OBJ) 14 | $(CC) $(OBJ) -o $(NAME) 15 | 16 | clean: 17 | $(RM) *~ $(NAME) 18 | 19 | oclean: 20 | $(RM) $(OBJ) 21 | 22 | fclean: clean oclean 23 | 24 | re: oclean all 25 | -------------------------------------------------------------------------------- /0x1C-makefiles/4-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c holberton.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = holberton 5 | RM = rm -f 6 | CFLAGS = -Wall -Werror -Wextra -pedantic 7 | 8 | all : $(OBJ) 9 | $(CC) $(OBJ) -o $(NAME) 10 | 11 | clean : 12 | $(RM) *~ $(NAME) 13 | 14 | oclean : 15 | $(RM) $(OBJ) 16 | 17 | fclean : clean oclean 18 | 19 | re : oclean all 20 | -------------------------------------------------------------------------------- /0x1C-makefiles/README.md: -------------------------------------------------------------------------------- 1 | # MAKEFILES 2 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/101-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/107-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/108-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/2-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/3-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/4-O: -------------------------------------------------------------------------------- 1 | O(log(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/5-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/6-O: -------------------------------------------------------------------------------- 1 | O(nm) 2 | --------------------------------------------------------------------------------