├── .gitmodules ├── .vscode └── c_cpp_properties.json ├── 0x00-hello_world ├── .gitignore ├── 0-preprocessor ├── 1-compiler ├── 100-intel ├── 101-quote.c ├── 2-assembler ├── 3-name ├── 4-puts.c ├── 5-printf.c ├── 6-size.c └── 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 ├── .gitignore ├── 0-holberton.c ├── 1-alphabet.c ├── 10-add.c ├── 100-times_table.c ├── 101-natural.c ├── 102-fibonacci.c ├── 103-fibonacci.c ├── 104-fibonacci.c ├── 11-print_to_98.c ├── 2-print_alphabet_x10.c ├── 3-islower.c ├── 4-isalpha.c ├── 5-sign.c ├── 6-abs.c ├── 7-print_last_digit.c ├── 8-24_hours.c ├── 9-times_table.c ├── README.md ├── holberton.h └── main.h ├── 0x03-debugging ├── 0-main.c ├── 1-main.c ├── 2-largest_number.c ├── 3-print_remaining_days.c ├── README.md └── main.h ├── 0x04-more_functions_nested_loops ├── .gitignore ├── 0-isupper.c ├── 1-isdigit.c ├── 10-print_triangle.c ├── 100-prime_factor.c ├── 101-print_number.c ├── 2-mul.c ├── 3-print_numbers.c ├── 4-print_most_numbers.c ├── 5-more_numbers.c ├── 6-print_line.c ├── 7-print_diagonal.c ├── 8-print_square.c ├── 9-fizz_buzz.c ├── README.md └── main.h ├── 0x05-pointers_arrays_strings ├── 0-reset_to_98.c ├── 1-swap.c ├── 100-atoi.c ├── 101-keygen.c ├── 2-strlen.c ├── 3-puts.c ├── 4-print_rev.c ├── 5-rev_string.c ├── 6-puts2.c ├── 7-puts_half.c ├── 8-print_array.c ├── 9-strcpy.c ├── README.md └── main.h ├── 0x06-pointers_arrays_strings ├── .gitignore ├── 0-strcat.c ├── 1-strncat.c ├── 100-rot13.c ├── 101-print_number.c ├── 102-magic.c ├── 103-infinite_add.c ├── 104-print_buffer.c ├── 2-strncpy.c ├── 3-strcmp.c ├── 4-rev_array.c ├── 5-string_toupper.c ├── 6-cap_string.c ├── 7-leet.c ├── README.md └── main.h ├── 0x07-pointers_arrays_strings ├── 0-memset.c ├── 1-memcpy.c ├── 101-crackme_password ├── 2-strchr.c ├── 3-strspn.c ├── 4-strpbrk.c ├── 5-strstr.c ├── 7-print_chessboard.c ├── 8-print_diagsums.c ├── 9-set_string.c ├── README.md └── main.h ├── 0x08-recursion ├── 0-puts_recursion.c ├── 1-print_rev_recursion.c ├── 100-is_palindrome.c ├── 101-wildcmp.c ├── 2-strlen_recursion.c ├── 3-factorial.c ├── 4-pow_recursion.c ├── 5-sqrt_recursion.c ├── 6-is_prime_number.c ├── README.md └── main.h ├── 0x09-static_libraries ├── .gitignore ├── 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 ├── 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 ├── 0x0B-malloc_free ├── 0-create_array.c ├── 1-strdup.c ├── 100-argstostr.c ├── 101-strtow.c ├── 2-str_concat.c ├── 3-alloc_grid.c ├── 4-free_grid.c ├── README.md └── main.h ├── 0x0C-more_malloc_free ├── 0-malloc_checked.c ├── 1-string_nconcat.c ├── 100-realloc.c ├── 2-calloc.c ├── 3-array_range.c ├── README.md └── main.h ├── 0x0D-preprocessor ├── 0-object_like_macro.h ├── 1-pi.h ├── 2-main.c ├── 3-function_like_macro.h ├── 4-sum.h └── README.md ├── 0x0E-structures_typedef ├── 1-init_dog.c ├── 2-print_dog.c ├── 4-new_dog.c ├── 5-free_dog.c ├── README.md └── dog.h ├── 0x0F-function_pointers ├── 0-print_name.c ├── 1-array_iterator.c ├── 100-main_opcodes.c ├── 2-int_index.c ├── 3-calc.h ├── 3-get_op_func.c ├── 3-main.c ├── 3-op_functions.c ├── README.md └── function_pointers.h ├── 0x10-variadic_functions ├── 0-sum_them_all.c ├── 1-print_numbers.c ├── 2-print_strings.c ├── 3-print_all.c ├── README.md └── variadic_functions.h ├── 0x12-singly_linked_lists ├── .gitignore ├── 0-print_list.c ├── 1-list_len.c ├── 100-first.c ├── 101-hello_holberton.asm ├── 2-add_node.c ├── 3-add_node_end.c ├── 4-free_list.c ├── README.md └── lists.h ├── 0x13-more_singly_linked_lists ├── .gitignore ├── 0-print_listint.c ├── 1-listint_len.c ├── 10-delete_nodeint.c ├── 100-reverse_listint.c ├── 101-print_listint_safe.c ├── 2-add_nodeint.c ├── 3-add_nodeint_end.c ├── 4-free_listint.c ├── 5-free_listint2.c ├── 6-pop_listint.c ├── 7-get_nodeint.c ├── 8-sum_listint.c ├── 9-insert_nodeint.c ├── README.md └── lists.h ├── 0x14-bit_manipulation ├── .gitignore ├── 0-binary_to_uint.c ├── 1-print_binary.c ├── 100-get_endianness.c ├── 101-password ├── 2-get_bit.c ├── 3-set_bit.c ├── 4-clear_bit.c ├── 5-flip_bits.c ├── README.md └── main.h ├── 0x15-file_io ├── .gitignore ├── 0-read_textfile.c ├── 1-create_file.c ├── 100-elf_header.c ├── 2-append_text_to_file.c ├── 3-cp.c ├── README.md └── main.h ├── 0x17-doubly_linked_lists ├── 0-print_dlistint.c ├── 1-dlistint_len.c ├── 100-password ├── 102-result ├── 103-keygen.c ├── 2-add_dnodeint.c ├── 3-add_dnodeint_end.c ├── 4-free_dlistint.c ├── 5-get_dnodeint.c ├── 6-sum_dlistint.c ├── 7-insert_dnodeint.c ├── 8-delete_dnodeint.c ├── README.md ├── lists.h └── tests │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ ├── 7-main.c │ └── 8-main.c ├── 0x18-dynamic_libraries ├── 0-isupper.c ├── 0-isupper.o ├── 0-memset.c ├── 0-memset.o ├── 0-strcat.c ├── 0-strcat.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.so ├── 101-make_me_win.sh ├── 101-makemewin.c ├── 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 ├── gm ├── lib101-makemewin.so ├── libdynamic.so ├── main.h └── tests │ ├── 0-main.c │ ├── 100-tests.py │ └── gm │ ├── 101-md5_gm │ ├── README.md │ └── gm ├── 0x1A-hash_tables ├── 0-hash_table_create.c ├── 1-djb2.c ├── 100-sorted_hash_table.c ├── 2-key_index.c ├── 3-hash_table_set.c ├── 4-hash_table_get.c ├── 5-hash_table_print.c ├── 6-hash_table_delete.c ├── README.md ├── hash_tables.h └── tests │ ├── 0-main.c │ ├── 100-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ └── 6-main.c ├── 0x1C-makefiles ├── 0-Makefile ├── 1-Makefile ├── 100-Makefile ├── 2-Makefile ├── 3-Makefile ├── 4-Makefile ├── 5-island_perimeter.py ├── README.md ├── m.h ├── main.c ├── school.c └── tests │ └── 5-main.py ├── 0x1E-search_algorithms ├── 0-linear.c ├── 1-binary.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 ├── listint │ ├── create_list.c │ ├── free_list.c │ └── print_list.c ├── search_algos.h ├── skiplist │ ├── create_skiplist.c │ ├── free_skiplist.c │ └── print_skiplist.c └── tests │ ├── 0-main.c │ ├── 1-main.c │ ├── 100-main.c │ ├── 102-main.c │ ├── 103-main.c │ ├── 104-main.c │ ├── 105-main.c │ └── 106-main.c ├── Betty-master ├── .travis.yml ├── LICENSE ├── README.md ├── betty-doc.pl ├── betty-style.pl ├── betty.sh ├── install.sh ├── man │ ├── betty-doc.1 │ ├── betty-style.1 │ └── betty.1 ├── test.sh └── tests │ ├── doc │ ├── doc0.c │ ├── doc0.expected.stderr │ ├── doc0.expected.stdout │ ├── doc1.c │ ├── doc1.expected.stderr │ ├── doc1.expected.stdout │ ├── doc10.c │ ├── doc10.expected.stderr │ ├── doc10.expected.stdout │ ├── doc11.c │ ├── doc11.expected.stderr │ ├── doc11.expected.stdout │ ├── doc12.c │ ├── doc12.expected.stderr │ ├── doc12.expected.stdout │ ├── doc13.expected.stderr │ ├── doc13.expected.stdout │ ├── doc13.h │ ├── doc14.c │ ├── doc14.expected.stderr │ ├── doc14.expected.stdout │ ├── doc2.c │ ├── doc2.expected.stderr │ ├── doc2.expected.stdout │ ├── doc3.c │ ├── doc3.expected.stderr │ ├── doc3.expected.stdout │ ├── doc4.c │ ├── doc4.expected.stderr │ ├── doc4.expected.stdout │ ├── doc5.c │ ├── doc5.expected.stderr │ ├── doc5.expected.stdout │ ├── doc6.expected.stderr │ ├── doc6.expected.stdout │ ├── doc6.h │ ├── doc7.expected.stderr │ ├── doc7.expected.stdout │ ├── doc7.h │ ├── doc8.expected.stderr │ ├── doc8.expected.stdout │ ├── doc8.h │ ├── doc9.c │ ├── doc9.expected.stderr │ └── doc9.expected.stdout │ └── style │ ├── braces │ ├── braces0.c │ ├── braces0.expected │ ├── braces1.c │ ├── braces1.expected │ ├── braces2.c │ ├── braces2.expected │ ├── braces3.c │ ├── braces3.expected │ ├── braces4.expected │ └── braces4.h │ ├── comments │ ├── comments0.c │ ├── comments0.expected │ ├── comments1.c │ └── comments1.expected │ ├── functions │ ├── functions0.c │ ├── functions0.expected │ ├── functions1.c │ ├── functions1.expected │ ├── functions2.c │ ├── functions2.expected │ ├── functions3.c │ ├── functions3.expected │ ├── functions4.c │ ├── functions4.expected │ ├── functions5.expected │ ├── functions5.h │ ├── functions6.c │ └── functions6.expected │ ├── headers │ ├── headers0.expected │ ├── headers0.h │ ├── headers1.expected │ ├── headers1.h │ ├── headers2.c │ ├── headers2.expected │ ├── headers3.expected │ ├── headers3.h │ ├── headers4.c │ └── headers4.expected │ ├── indentation │ ├── indentation0.c │ └── indentation0.expected │ ├── line_break │ ├── line_break0.c │ ├── line_break0.expected │ ├── line_break1.c │ ├── line_break1.expected │ ├── line_break2.c │ ├── line_break2.expected │ ├── line_break3.c │ ├── line_break3.expected │ ├── line_break4.c │ ├── line_break4.expected │ ├── line_break5.c │ └── line_break5.expected │ ├── spaces │ ├── spaces0.c │ ├── spaces0.expected │ ├── spaces1.c │ ├── spaces1.expected │ ├── spaces2.c │ ├── spaces2.expected │ ├── spaces3.c │ ├── spaces3.expected │ ├── spaces4.c │ ├── spaces4.expected │ ├── spaces5.c │ ├── spaces5.expected │ ├── spaces6.c │ └── spaces6.expected │ └── variables │ ├── variables0.c │ ├── variables0.expected │ ├── variables1.c │ ├── variables1.expected │ ├── variables2.c │ ├── variables2.expected │ ├── variables3.c │ ├── variables3.expected │ ├── variables4.c │ └── variables4.expected └── README.md /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "printf"] 2 | path = printf 3 | url = https://github.com/Pericles001/printf.git 4 | [submodule "simple_shell"] 5 | path = simple_shell 6 | url = https://github.com/underscoDe/simple_shell.git 7 | [submodule "monty"] 8 | path = monty 9 | url = https://github.com/underscoDe/monty 10 | [submodule "binary_trees"] 11 | path = binary_trees 12 | url = https://github.com/underscoDe/binary_trees.git 13 | [submodule "sorting_algorithms"] 14 | path = sorting_algorithms 15 | url = https://github.com/underscoDe/sorting_algorithms.git 16 | -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Linux", 5 | "includePath": [ 6 | "${default}", 7 | "${workspaceRoot}/**" 8 | ], 9 | "compilerPath": "/usr/bin/gcc", 10 | "cStandard": "gnu17", 11 | "cppStandard": "gnu++14", 12 | "intelliSenseMode": "linux-gcc-x64", 13 | "browse": { 14 | "path": [ 15 | "${workspaceFolder}" 16 | ], 17 | "limitSymbolsToIncludedHeaders": true, 18 | "databaseFilename": "" 19 | } 20 | } 21 | ], 22 | "version": 4 23 | } -------------------------------------------------------------------------------- /0x00-hello_world/.gitignore: -------------------------------------------------------------------------------- 1 | *~ -------------------------------------------------------------------------------- /0x00-hello_world/0-preprocessor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -E $CFILE -o c 3 | -------------------------------------------------------------------------------- /0x00-hello_world/1-compiler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/100-intel: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S -masm=intel $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/101-quote.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - Entry point 6 | * 7 | * Return: return 1 8 | */ 9 | 10 | int main(void) 11 | { 12 | write(2, "and that piece of art is useful\" - Dora Korpar, 2015-10-19\n", 59); 13 | return (1); 14 | } 15 | -------------------------------------------------------------------------------- /0x00-hello_world/2-assembler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/3-name: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -o cisfun $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/4-puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | /** 5 | * main - This is the entry point of the project 6 | * 7 | * Return: always 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | puts("\"Programming is like building a multilingual puzzle"); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x00-hello_world/5-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | printf("with proper grammar, but the outcome is a piece of art,\n"); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x00-hello_world/6-size.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: 0 7 | */ 8 | 9 | int main(void) 10 | { 11 | printf("Size of a char: %d byte(s)\n", sizeof(char)); 12 | printf("Size of an int: %d byte(s)\n", sizeof(int)); 13 | printf("Size of a long int: %d byte(s)\n", sizeof(long int)); 14 | printf("Size of a long long int: %d byte(s)\n", sizeof(long long int)); 15 | printf("Size of a float: %d byte(s)\n", sizeof(float)); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: returns 0 when everything works fine 9 | * 10 | */ 11 | 12 | int main(void) 13 | { 14 | int n; 15 | 16 | srand(time(0)); 17 | n = rand() - RAND_MAX / 2; 18 | if (n > 0) 19 | printf("%d is positive\n", n); 20 | else if (n == 0) 21 | printf("%d is zero\n", n); 22 | else 23 | printf("%d is negative\n", n); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: returns 0 when everything works fine 9 | * 10 | */ 11 | 12 | int main(void) 13 | { 14 | int n, last; 15 | 16 | srand(time(0)); 17 | n = rand() - RAND_MAX / 2; 18 | last = n % 10; 19 | if (last > 5) 20 | printf("Last digit of %d is %d and is greater than 5\n", n, last); 21 | else if (last < 6 && last != 0) 22 | printf("Last digit of %d is %d and is less than 6 and not 0\n", n, last); 23 | else if (last == 0) 24 | printf("Last digit of %d is %d and is 0\n", n, last); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - entry point 5 | * 6 | * Return: always 0 7 | */ 8 | int main(void) 9 | { 10 | int c, c_two; 11 | 12 | for (c = 48; c <= 56; c++) 13 | { 14 | for (c_two = c + 1; c_two <= 57; c_two++) 15 | { 16 | putchar(c); 17 | putchar(c_two); 18 | if (c != 56 || c_two != 57) 19 | { 20 | putchar(44); 21 | putchar(32); 22 | } 23 | } 24 | } 25 | 26 | putchar(10); 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - entry point 5 | * 6 | * Return: always 0 7 | */ 8 | int main(void) 9 | { 10 | int c, c_two, c_three; 11 | 12 | for (c = 48; c <= 55; c++) 13 | { 14 | for (c_two = c + 1; c_two <= 56; c_two++) 15 | { 16 | for (c_three = c_two + 1; c_three <= 57; c_three++) 17 | { 18 | putchar(c); 19 | putchar(c_two); 20 | putchar(c_three); 21 | if (c != 55 || c_two != 56 || c_three != 57) 22 | { 23 | putchar(44); 24 | putchar(32); 25 | } 26 | } 27 | } 28 | } 29 | 30 | putchar(10); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/102-print_comb5.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - entry point 5 | * 6 | * Return: always 0 7 | */ 8 | int main(void) 9 | { 10 | int c, c_two; 11 | 12 | for (c = 0; c <= 98; c++) 13 | { 14 | for (c_two = c + 1; c_two <= 99; c_two++) 15 | { 16 | putchar('0' + c / 10); 17 | putchar('0' + c % 10); 18 | putchar(32); 19 | putchar('0' + c_two / 10); 20 | putchar('0' + c_two % 10); 21 | if (c / 10 != 9 || c % 10 != 8) 22 | { 23 | putchar(44); 24 | putchar(32); 25 | } 26 | } 27 | } 28 | 29 | putchar(10); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 97; n <= 122; ++n) 15 | putchar(n); 16 | putchar(10); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 97; n <= 122; ++n) 15 | putchar(n); 16 | for (n = 65; n <= 90; ++n) 17 | putchar(n); 18 | putchar(10); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 97; n <= 122; ++n) 15 | { 16 | if (n != 101 && n != 113) 17 | { 18 | putchar(n); 19 | } 20 | } 21 | putchar(10); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 0; n < 10; ++n) 15 | { 16 | printf("%d", n); 17 | } 18 | putchar(10); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 48; n < 58; ++n) 15 | { 16 | putchar(n); 17 | } 18 | putchar(10); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 122; n >= 97; --n) 15 | { 16 | putchar(n); 17 | } 18 | putchar(10); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int n; 13 | 14 | for (n = 48; n <= 57; ++n) 15 | putchar(n); 16 | for (n = 97; n <= 102; ++n) 17 | putchar(n); 18 | putchar(10); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: returns 0 when everything works fine 7 | * 8 | */ 9 | 10 | int main(void) 11 | { 12 | int c; 13 | 14 | for (c = 48; c <= 57; c++) 15 | { 16 | putchar(c); 17 | if (c <= 56) 18 | { 19 | putchar(44); 20 | putchar(32); 21 | } 22 | } 23 | 24 | putchar(10); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/.gitignore: -------------------------------------------------------------------------------- 1 | _putchar.c 2 | *.out 3 | *~ 4 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *main - function prints text as output 5 | * 6 | *Return:return 0 7 | */ 8 | int main(void) 9 | { 10 | char school[10] = "_putchar"; 11 | int i; 12 | for (i = 0; i < 8; i++) 13 | { 14 | _putchar(school[i]); 15 | } 16 | _putchar(10); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_alphabet - function that print alphabet 4 | *it prints in lowercase 5 | *Return: no return 6 | */ 7 | void print_alphabet(void) 8 | { 9 | int letter; 10 | for (letter = 'a'; letter <= 'z'; letter++) 11 | { 12 | _putchar (letter); 13 | } 14 | _putchar (10); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *add - sums up two numbers 4 | *@n:first integer 5 | *@m:second integer 6 | *Return: returns 0 7 | */ 8 | int add(int n, int m) 9 | { 10 | return (n + m); 11 | } 12 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/100-times_table.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_times_table - prints the times table with 4 | *parameter 5 | *@n: parameter 6 | *Return: returns nothing 7 | */ 8 | void print_times_table(int n) 9 | { 10 | int digit, mult, result; 11 | if (n <= 15 && n >= 0) 12 | { 13 | for (digit = 0; digit <= n; digit++) 14 | { 15 | _putchar('0'); 16 | 17 | for (mult = 1; mult <= n; mult++) 18 | { 19 | _putchar(','); 20 | _putchar(' '); 21 | result = digit * mult; 22 | if (result <= 99) 23 | _putchar(' '); 24 | 25 | if (result <= 9) 26 | _putchar(' '); 27 | if (result >= 100) 28 | { 29 | _putchar((result / 100) + '0'); 30 | _putchar((result / 10) % 10 + '0'); 31 | } 32 | else if (result <= 99 && result >= 10) 33 | { 34 | _putchar((result / 10) + '0'); 35 | } 36 | _putchar((result % 10) + '0'); 37 | } 38 | _putchar('\n'); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | *main - prints count of multiples 4 | *of 3 or 5 below 1024 5 | *Return: return 0 6 | */ 7 | int main(void) 8 | { 9 | int n, sum = 0; 10 | for (n = 0; n < 1024; n++) 11 | { 12 | if ((n % 3) == 0 || (n % 5) == 0) 13 | sum += n; 14 | } 15 | printf("%d\n", sum); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | *main - prints out first 50 4 | *fibonacci suit numbers 5 | *Return: return 0 6 | */ 7 | int main(void) 8 | { 9 | int inc; 10 | unsigned long n1 = 0, n2 = 1, n3; 11 | for (inc = 0; inc < 50; inc++) 12 | { 13 | n3 = n1 + n2; 14 | printf("%lu", n3); 15 | n1 = n2; 16 | n2 = n3; 17 | 18 | if (inc == 49) 19 | printf("\n"); 20 | else 21 | printf(", "); 22 | 23 | } 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | *main - prints sum of even fibonacci 4 | *suit elements 5 | *fibonacci suit numbers 6 | *Return: return 0 7 | */ 8 | int main(void) 9 | { 10 | unsigned long n1 = 0, n2 = 1, n3 = 0, sum = 0; 11 | while (n3 <= 4000000) 12 | { 13 | n3 = n1 + n2; 14 | n1 = n2; 15 | n2 = n3; 16 | 17 | if ((n1 % 2) == 0) 18 | sum += n1; 19 | 20 | } 21 | printf("%ld\n", sum); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/104-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point, prints the first 50 fibonacci numbers 5 | * 6 | * Return: Always 0 7 | */ 8 | int main(void) 9 | { 10 | int counter = 0; 11 | unsigned long first = 0; 12 | unsigned long second = 1; 13 | unsigned long fib; 14 | 15 | while (counter <= 97) 16 | { 17 | fib = first + second; 18 | if (counter < 97) 19 | { 20 | printf("%lu, ", fib); 21 | } 22 | else 23 | { 24 | printf("%lu", fib); 25 | } 26 | first = second; 27 | second = fib; 28 | counter++; 29 | } 30 | printf("\n"); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-print_to_98.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | /** 4 | *print_to_98 - prints natural 5 | *numbers from n to 98 6 | *@n:integer to start by 7 | *return: returns nothing 8 | */ 9 | void print_to_98(int n) 10 | { 11 | if (n >= 98) 12 | { 13 | while (n > 98) 14 | printf("%d, ", n--); 15 | 16 | printf("%d\n", n); 17 | } 18 | else 19 | { 20 | while (n < 98) 21 | printf("%d, ", n++); 22 | 23 | printf("%d\n", n); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_alphabet_x10 - prints alphabet letters 4 | * ten times 5 | *desc: The function uses loop to operate 6 | *Return: no return 7 | */ 8 | void print_alphabet_x10(void) 9 | { 10 | int counter = 0; 11 | int letter; 12 | while (counter++ <= 9) 13 | { 14 | for (letter = 'a'; letter <= 'z'; letter++) 15 | _putchar(letter); 16 | 17 | _putchar(10); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_sign-prints sign of a number 4 | *@n: character to be verified 5 | *Return: return 0 or 1 6 | */ 7 | int print_sign(int n) 8 | { 9 | if (n == 0) 10 | { 11 | _putchar('0'); 12 | return (0); 13 | } 14 | else if (n > 0) 15 | { 16 | _putchar('+'); 17 | return (1); 18 | } 19 | else 20 | { 21 | _putchar('-'); 22 | return (-1); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-print_last_digit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *print_last_digit - function that print last digit of a number 4 | *@n: number to be targeted 5 | *Return: returns 0 6 | */ 7 | int print_last_digit(int n) 8 | { 9 | int lastdigit = n % 10; 10 | if (lastdigit < 0) 11 | lastdigit *= -1; 12 | 13 | _putchar (lastdigit + '0'); 14 | return (lastdigit); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24_hours.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *jack_bauer - prints each minute of the day 4 | * 5 | *Return:returns 0 6 | */ 7 | void jack_bauer(void) 8 | { 9 | int min, hour; 10 | for (hour = 0; hour <= 23; hour++) 11 | { 12 | for (min = 0; min <= 59; min++) 13 | { 14 | _putchar((hour / 10) + '0'); 15 | _putchar((hour % 10) + '0'); 16 | _putchar(':'); 17 | _putchar((min / 10) + '0'); 18 | _putchar((min % 10) + '0'); 19 | _putchar(10); 20 | } 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-times_table.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *times_table - prints the 9 times table 4 | * 5 | *Return: returns nothing 6 | */ 7 | void times_table(void) 8 | { 9 | int digit, mult, result; 10 | for (digit = 0; digit <= 9; digit++) 11 | { 12 | _putchar('0'); 13 | 14 | for (mult = 1; mult <= 9; mult++) 15 | { 16 | _putchar(','); 17 | _putchar(' '); 18 | result = digit * mult; 19 | if (result <= 9) 20 | _putchar(' '); 21 | else 22 | _putchar((result / 10) + '0'); 23 | 24 | _putchar((result % 10) + '0'); 25 | } 26 | _putchar('\n'); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # Nested loops \*codes in confusion xD\* 2 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void print_alphabet(void); 3 | void print_alphabet_x10(void); 4 | int _islower(int c); 5 | int _isalpha(int c); 6 | int print_sign(int n); 7 | int _abs(int); 8 | int print_last_digit(int); 9 | void jack_bauer(void); 10 | void times_table(void); 11 | int add(int, int); 12 | void print_to_98(int n); 13 | void print_times_table(int n); 14 | int len(int n); 15 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | /** 2 | *File: main.h 3 | *Author: Arsene Awounou 4 | *Desc: header file 5 | */ 6 | 7 | void print_alphabet(void); 8 | void jack_bauer(void); 9 | void print_alphabet_x10(void); 10 | void times_table(); 11 | void print_to_98(int); 12 | void print_times_table(int); 13 | int _putchar(char); 14 | int _islower(int c); 15 | int _isalpha(int c); 16 | int print_sign(int n); 17 | int _abs(int); 18 | int add(int n, int m); 19 | int print_last_digit(int n); 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.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 | { 13 | int largest; 14 | if (a >= b && a >= c) 15 | { 16 | largest = a; 17 | } 18 | else if (b >= a && b >= c) 19 | { 20 | largest = b; 21 | } 22 | else 23 | { 24 | largest = c; 25 | } 26 | return (largest); 27 | } 28 | -------------------------------------------------------------------------------- /0x03-debugging/3-print_remaining_days.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * print_remaining_days - takes a date and prints how many days are 6 | * left in the year, taking leap years into account 7 | * @month: month in number format 8 | * @day: day of month 9 | * @year: year 10 | * Return: void 11 | */ 12 | 13 | void print_remaining_days(int month, int day, int year) 14 | { 15 | if ((year % 4 == 0) && (year % 400 == 0 || year % 100 != 0)) 16 | { 17 | if (month >= 3 && day >= 60) 18 | { 19 | day++; 20 | } 21 | 22 | printf("Day of the year: %d\n", day); 23 | printf("Remaining days: %d\n", 366 - day); 24 | } 25 | else 26 | { 27 | if (month == 2 && day == 60) 28 | { 29 | printf("Invalid date: %02d/%02d/%04d\n", month, day - 31, year); 30 | } 31 | else 32 | { 33 | printf("Day of the year: %d\n", day); 34 | printf("Remaining days: %d\n", 365 - day); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /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, int, int); 8 | void print_remaining_days(int, int, int); 9 | int convert_day(int, int); 10 | 11 | #endif /* MAIN_H */ 12 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/.gitignore: -------------------------------------------------------------------------------- 1 | _putchar.c 2 | main.c 3 | tests/ 4 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_isupper - checks if a character is uppercase or not 5 | *@c: character to be tested 6 | *Return: 1 whether it is, 0 otherwise 7 | */ 8 | 9 | int _isupper(int c) 10 | { 11 | if ((c >= 'A') && (c <= 'Z')) 12 | { 13 | return (1); 14 | } 15 | 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_isdigit - checks whether a character is a digit or not 5 | *@c: tested character 6 | *Return: 1 if it is, 0 otherwise 7 | */ 8 | 9 | int _isdigit(int c) 10 | { 11 | if ((c >= 48) && (c <= 57)) 12 | { 13 | return (1); 14 | } 15 | 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-print_triangle.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_triangle - prints a triangle 6 | *@size:size parameter of triangle 7 | *Return: returns nothing 8 | */ 9 | 10 | void print_triangle(int size) 11 | { 12 | int inc1, inc2; 13 | 14 | if (size > 0) 15 | { 16 | for (inc1 = 1; inc1 <= size; inc1++) 17 | { 18 | for ((inc2 = size - inc1); inc2 > 0; inc2--) 19 | { 20 | putchar(' '); 21 | } 22 | 23 | for (inc2 = 0; inc2 < inc1; inc2++) 24 | { 25 | putchar('#'); 26 | } 27 | 28 | if (inc1 == size) 29 | { 30 | continue; 31 | } 32 | 33 | putchar('\n'); 34 | } 35 | } 36 | putchar('\n'); 37 | } 38 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | *main- prints the largest prime factor 5 | *of a number 6 | * 7 | *Return: returns 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | long number = 612852475143; 13 | int inc; 14 | 15 | while (inc++ < number / 2) 16 | { 17 | if (number % inc == 0) 18 | { 19 | number /= 2; 20 | continue; 21 | } 22 | 23 | for (inc = 3; inc < number / 2; inc += 2) 24 | { 25 | if (number % inc == 0) 26 | number /= inc; 27 | } 28 | } 29 | printf("%ld\n", number); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * print_number - Prints a number 6 | * @n: The number to print 7 | */ 8 | 9 | void print_number(int n) 10 | { 11 | unsigned int num = n; 12 | if (n < 0) 13 | { 14 | putchar('-'); 15 | num = -num; 16 | } 17 | if (num > 9) 18 | { 19 | print_number(num / 10); 20 | } 21 | putchar(num % 10 + '0'); 22 | } 23 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *mul - multiplies two numbers 5 | *@a: first number 6 | *@b: second number 7 | *Return: returns result 8 | */ 9 | 10 | int mul(int a, int b) 11 | { 12 | return (a * b); 13 | } 14 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_numbers - function that print all numbers from 6 | *0 to 9 7 | * 8 | *Return: returns nothing 9 | */ 10 | 11 | void print_numbers(void) 12 | { 13 | int n; 14 | 15 | for (n = 48; n < 58; n++) 16 | { 17 | putchar(n); 18 | } 19 | putchar(10); 20 | } 21 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_most_numbers - prints numbers except 2 and 4 6 | * 7 | *Return: returns nothing 8 | */ 9 | 10 | void print_most_numbers(void) 11 | { 12 | int n; 13 | 14 | for (n = 48; n < 58; n++) 15 | { 16 | if ((n == 50) || (n == 52)) 17 | { 18 | continue; 19 | } 20 | putchar(n); 21 | } 22 | putchar(10); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *more_numbers - prints numbers to 14 6 | * 7 | *Return: returns nothing 8 | */ 9 | 10 | void more_numbers(void) 11 | { 12 | int n1, n2; 13 | 14 | for (n1 = 0; n1 < 10; n1++) 15 | { 16 | for (n2 = 0; n2 <= 14; n2++) 17 | { 18 | if (n2 > 9) 19 | { 20 | putchar((n2 / 10) + '0'); 21 | } 22 | putchar((n2 % 10) + '0'); 23 | } 24 | putchar(10); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_line - prints a straight line 6 | *@n: parameter 7 | *Return:returns nothing 8 | */ 9 | 10 | void print_line(int n) 11 | { 12 | while (n-- > 0) 13 | { 14 | putchar('_'); 15 | } 16 | putchar('\n'); 17 | } 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_diagonal - prints a diagonal 6 | *@n: parameter 7 | *Return: returns nothing 8 | */ 9 | 10 | void print_diagonal(int n) 11 | { 12 | int len, space; 13 | 14 | if (n > 0) 15 | { 16 | for (len = 0; len < n; len++) 17 | { 18 | for (space = 0; space < len; space++) 19 | { 20 | putchar(' '); 21 | } 22 | 23 | putchar('\\'); 24 | 25 | if (len == (n - 1)) 26 | { 27 | continue; 28 | } 29 | putchar('\n'); 30 | } 31 | } 32 | putchar('\n'); 33 | } 34 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *print_square - prints squares 6 | *@size: parameter 7 | *Return: returns nothing 8 | */ 9 | 10 | void print_square(int size) 11 | { 12 | int inc1, inc2; 13 | 14 | if (size > 0) 15 | { 16 | for (inc1 = 0; inc1 < size; inc1++) 17 | { 18 | for (inc2 = 0; inc2 < (size - 1); inc2++) 19 | { 20 | putchar('#'); 21 | } 22 | 23 | putchar('#'); 24 | putchar('\n'); 25 | } 26 | } 27 | else 28 | { 29 | putchar('\n'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | *main - program that prints either number 5 | *or fizz or buzz or fizzBuzz 6 | * 7 | * 8 | *Return: returns 0 9 | */ 10 | 11 | int main(void) 12 | { 13 | int num = 1; 14 | 15 | while (num++ < 100) 16 | { 17 | if ((num % 3 == 0) && (num % 5 == 0)) 18 | { 19 | printf("FizzBuzz "); 20 | } 21 | else if ((num % 3) == 0) 22 | { 23 | printf("Fizz "); 24 | } 25 | else if ((num % 5) == 0) 26 | { 27 | if (num != 100) 28 | { 29 | printf("Buzz "); 30 | } 31 | else 32 | { 33 | printf("Buzz"); 34 | } 35 | } 36 | else 37 | { 38 | printf("%d ", num); 39 | } 40 | } 41 | printf("\n"); 42 | 43 | return (0); 44 | } 45 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | /** 5 | *main - header file for protoypes 6 | *void protoypes (void) 7 | *int protoypes (int) 8 | */ 9 | 10 | void print_numbers(void); 11 | void print_most_numbers(void); 12 | void more_numbers(void); 13 | void print_line(int n); 14 | void print_diagonal(int n); 15 | void print_square(int size); 16 | void print_triangle(int size); 17 | void print_number(int n); 18 | int _putchar(char); 19 | int _isupper(int); 20 | int _isdigit(int); 21 | int mul(int, int); 22 | 23 | #endif /* MAIN_H */ 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *reset_to_98 - resets the value of given integer to 98 5 | *@n: parameter 6 | *Return : nothing 7 | */ 8 | 9 | void reset_to_98(int *n) 10 | { 11 | *n = 98; 12 | } 13 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *swap_int - swaps two integers' values 5 | *@a: first integer 6 | *@b: second integer 7 | *Return: returns nothing 8 | */ 9 | 10 | void swap_int(int *a, int *b) 11 | { 12 | int tmp = *a; 13 | 14 | *a = *b; 15 | *b = tmp; 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/100-atoi.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _atoi - converts a string to an int 5 | * @s: the string to be changed 6 | * 7 | * Return: the converted int 8 | */ 9 | 10 | int _atoi(char *s) 11 | { 12 | int sign = 1; 13 | unsigned int num = 0; 14 | 15 | do { 16 | if (*s == '-') 17 | sign *= -1; 18 | else if (*s >= '0' && *s <= '9') 19 | num = num * 10 + (*s - '0'); 20 | else if (num > 0) 21 | break; 22 | } while (*s++); 23 | 24 | return (num * sign); 25 | } 26 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "main.h" 5 | 6 | /** 7 | * main - entry point 8 | * 9 | * Return: generated password 10 | */ 11 | 12 | int main(void) 13 | { 14 | char c; 15 | int x; 16 | 17 | srand(time(0)); 18 | while (x <= 2645) 19 | { 20 | c = rand() % 128; 21 | x += c; 22 | putchar(c); 23 | } 24 | putchar(2772 - x); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | *_strlen - returns the length of a string 5 | * @s: string 6 | *Return: returns length as integer; 7 | */ 8 | 9 | int _strlen(char *s) 10 | { 11 | int len = 0; 12 | 13 | while (*(s + len) != '\0') 14 | len++; 15 | 16 | return (len); 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | *_puts - prints a string 6 | * @str: string to print 7 | * 8 | * Description: prints a string 9 | * On success: returns no error 10 | */ 11 | 12 | void _puts(char *str) 13 | { 14 | int i = 0; 15 | 16 | while (*(str + i) != '\0') 17 | { 18 | putchar(*(str + i)); 19 | i++; 20 | } 21 | putchar(10); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "main.h" 4 | 5 | /** 6 | *print_rev - Prints a string in reverse order 7 | *@s: String to reverse 8 | *Return: Nothing 9 | */ 10 | 11 | void print_rev(char *s) 12 | { 13 | int len = strlen(s); 14 | 15 | while (len--) 16 | putchar(*(s + len)); 17 | putchar(10); 18 | } 19 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * rev_string - Reverses a string 6 | * @s: string to be reversed 7 | * 8 | * Return: nothing 9 | */ 10 | 11 | void rev_string(char *s) 12 | { 13 | int i, tmp, len = _strlen(s); 14 | 15 | for (i = 0; i < len / 2; i++) 16 | { 17 | tmp = *(s + i); 18 | *(s + i) = *(s + len - i - 1); 19 | *(s + len - i - 1) = tmp; 20 | } 21 | } 22 | 23 | /** 24 | * _strlen - returns the length of a string 25 | * @s: string 26 | * 27 | * Return: the length of the given string 28 | */ 29 | 30 | int _strlen(char *s) 31 | { 32 | int len = 0; 33 | 34 | while (*(s + len) != '\0') 35 | len++; 36 | 37 | return (len); 38 | } 39 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * puts2 - prints every other character 6 | * @str: string 7 | * 8 | * Return: nothing 9 | */ 10 | 11 | void puts2(char *str) 12 | { 13 | int i = 0; 14 | 15 | while (*(str + i) != '\0') 16 | { 17 | if (i % 2 == 0) 18 | putchar(*(str + i)); 19 | i++; 20 | } 21 | putchar(10); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * puts_half - prints a string 6 | * @str: string to print 7 | * 8 | * Return: nothing 9 | */ 10 | 11 | void puts_half(char *str) 12 | { 13 | int i, len = _strlen(str); 14 | 15 | for (i = ((len - 1) / 2) + 1; i < len; i++) 16 | putchar(*(str + i)); 17 | putchar(10); 18 | } 19 | 20 | /** 21 | * _strlen - returns the length of a string 22 | * @s: string 23 | * 24 | * Return: the length of the given string 25 | */ 26 | 27 | int _strlen(char *s) 28 | { 29 | int len = 0; 30 | 31 | while (*(s + len) != '\0') 32 | len++; 33 | 34 | return (len); 35 | } 36 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "main.h" 3 | 4 | /** 5 | * print_array - prints n element of array 6 | * @a: array 7 | * @n: number of elements 8 | * Return: nothing 9 | */ 10 | 11 | void print_array(int *a, int n) 12 | { 13 | int inc; 14 | 15 | for (inc = 0; inc < n ; inc++) 16 | { 17 | if (inc != n - 1) 18 | printf("%d, ", a[inc]); 19 | else 20 | printf("%d", a[inc]); 21 | 22 | } 23 | putchar(10); 24 | } 25 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcpy - Copy paste string 5 | * @dest: destination 6 | * @src: source 7 | * 8 | * Return: destination 9 | */ 10 | 11 | char *_strcpy(char *dest, char *src) 12 | { 13 | int inc = 0; 14 | 15 | while (*(src + inc) != '\0') 16 | { 17 | *(dest + inc) = *(src + inc); 18 | inc++; 19 | } 20 | *(dest + inc) = '\0'; 21 | 22 | return (dest); 23 | } 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | /** 5 | * void prototypes() 6 | * int prototypes() 7 | */ 8 | 9 | void reset_to_98(int *n); 10 | void swap_int(int *a, int *b); 11 | int _strlen(char *s); 12 | void _puts(char *str); 13 | void print_rev(char *s); 14 | void rev_string(char *s); 15 | void puts2(char *str); 16 | void puts_half(char *str); 17 | void print_array(int *a, int n); 18 | char *_strcpy(char *dest, char *src); 19 | int _atoi(char *str); 20 | 21 | #endif /*MAIN_H*/ 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/.gitignore: -------------------------------------------------------------------------------- 1 | tests/ 2 | main.c 3 | _putchar.c 4 | .vscode/ -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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 | } 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * print_number - prints an integer 4 | *@n:integer to be printed 5 | * 6 | */ 7 | void print_number(int n) 8 | { 9 | unsigned int num = n; 10 | 11 | if (n < 0) 12 | { 13 | _putchar('-'); 14 | num = -num; 15 | } 16 | 17 | if ((num / 10) > 0) 18 | print_number(num / 10); 19 | 20 | _putchar((num % 10) + '0'); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/102-magic.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | int n; 6 | int a[5]; 7 | int *p; 8 | 9 | a[2] = 1024; 10 | p = &n; 11 | /* 12 | * write your line of code here... 13 | * Remember: 14 | * - you are not allowed to use a 15 | * - you are not allowed to modify p 16 | * - only one statement 17 | * - you are not allowed to code anything else than this line of code 18 | */ 19 | *(p + 5) = 98; 20 | /* ...so that this prints 98\n */ 21 | printf("a[2] = %d\n", a[2]); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strncpy - C function that copies a string, including the 4 | * terminating null byte, using at most an inputted number of bytes. 5 | * If the length of the source string is less than the maximum byte number, 6 | * the remainder of the destination string is filled with null bytes. 7 | * Works identically to the standard library function `strncpy`. 8 | *@dest: buffer storing the string copy 9 | *@src:the source string 10 | *@n:max nummber of byte copied 11 | *Return: returns 12 | */ 13 | 14 | char *_strncpy(char *dest, char *src, int n) 15 | { 16 | int i; 17 | 18 | for (i = 0; i < n && src[i] != '\0'; i++) 19 | dest[i] = src[i]; 20 | 21 | for ( ; i < n; i++) 22 | dest[i] = '\0'; 23 | 24 | return (dest); 25 | } 26 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - Function which compare two strings and 5 | *@s1: first string 6 | *@s2:second string 7 | *Return: 8 | * returns zero if s1 == s2 9 | * returns negative number if s1 < s2 10 | * returns positive number if s1 > s2 11 | */ 12 | 13 | int _strcmp(char *s1, char *s2) 14 | { 15 | int i = 0, diff = 0; 16 | 17 | while (1) 18 | { 19 | if (s1[i] == '\0' && s2[i] == '\0') 20 | break; 21 | else if (s1[i] == '\0') 22 | { 23 | diff = s2[i]; 24 | break; 25 | } 26 | else if (s2[i] == '\0') 27 | { 28 | diff = s1[i]; 29 | break; 30 | } 31 | else if (s1[i] != s2[i]) 32 | { 33 | diff = s1[i] - s2[i]; 34 | break; 35 | } 36 | else 37 | i++; 38 | 39 | } 40 | return (diff); 41 | } 42 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * reverse_array - function that reverse content of array 5 | * @a: array 6 | * @n: number of elements 7 | */ 8 | 9 | void reverse_array(int *a, int n) 10 | { 11 | int tmp, index; 12 | for (index = n - 1; index > n / 2; index--) 13 | { 14 | tmp = a[n - 1 - index]; 15 | a[n - 1 - index] = a[index]; 16 | a[index] = tmp; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * string_toupper - changes all lowercase letters to uppercase 5 | * @str: string to be changed 6 | * 7 | * Return: address tp the string 8 | */ 9 | 10 | char *string_toupper(char *str) 11 | { 12 | int i = 0; 13 | 14 | while (str[i] != '\0') 15 | { 16 | if (str[i] >= 'a' && str[i] <= 'z') 17 | str[i] -= 32; 18 | i++; 19 | } 20 | return (str); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | #include 4 | /** 5 | *void prototypes() 6 | *int prototypes() 7 | *char prototypes() 8 | */ 9 | void reverse_array(int *a, int n); 10 | void print_number(int n); 11 | void print_buffer(char *b, int size); 12 | int _strcmp(char *s1, char *s2); 13 | char *_strcat(char *dest, char *src); 14 | char *_strncat(char *dest, char *src, int n); 15 | char *_strncpy(char *dest, char *src, int n); 16 | char *string_toupper(char *); 17 | char *cap_string(char *); 18 | char *leet(char *); 19 | char *rot13(char *); 20 | char *infinite_add(char *n1, char *n2, char *r, int size_r); 21 | char *add_strings(char *n1, char *n2, char *r, int r_index); 22 | 23 | #endif /*MAIN_H*/ -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memset - fills a memory block with a constant byte 5 | * @s: address to memory block 6 | * @b: char to be used 7 | * @n: number of bytes to be used 8 | * 9 | * Return: pointer to the memory block 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 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _memcpy - copies a memory area 5 | * @dest: memory area to be copied to 6 | * @src: memory area to be copied from 7 | * @n: number of bytes to be copied 8 | * 9 | * Return: pointer to the copied memory block 10 | */ 11 | 12 | char *_memcpy(char *dest, char *src, unsigned int n) 13 | { 14 | unsigned int i = 0; 15 | 16 | for (; i < n; i++) 17 | { 18 | dest[i] = src[i]; 19 | } 20 | 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/101-crackme_password: -------------------------------------------------------------------------------- 1 | abc123 -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strchr - locates a char in a string 6 | * @s: string to be searched 7 | * @c: char to be checked 8 | * 9 | * Return: pointer to the first occurence of c in s 10 | */ 11 | 12 | char *_strchr(char *s, char c) 13 | { 14 | int i = 0; 15 | 16 | for (; s[i] != c && s[i] != '\0'; i++) 17 | ; 18 | 19 | if (s[i] == c) 20 | return (s + i); 21 | else 22 | return (NULL); 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * _strstr - locates a substring 6 | * @haystack: string to be searched in 7 | * @needle: string to be searched 8 | * 9 | * Return: Returns a pointer to the beginning of the located substring 10 | */ 11 | 12 | char *_strstr(char *haystack, char *needle) 13 | { 14 | int i = 0, flag = 0; 15 | 16 | if (*needle == '\0') 17 | { 18 | return (haystack); 19 | } 20 | for (; haystack[i] != '\0'; i++) 21 | { 22 | int j = 0; 23 | 24 | if (haystack[i] == needle[0]) 25 | { 26 | while (needle[j] != '\0') 27 | { 28 | if (haystack[i + j] != needle[j]) 29 | { 30 | flag = 0; 31 | break; 32 | } 33 | else 34 | flag = 1; 35 | j++; 36 | } 37 | if (flag) 38 | break; 39 | } 40 | } 41 | if (flag) 42 | return (haystack + i); 43 | else 44 | return (NULL); 45 | } 46 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_chessboard - print's a chessboard 5 | * @a: array to be printed 6 | * 7 | * Return: void 8 | */ 9 | 10 | void print_chessboard(char (*a)[8]) 11 | { 12 | int i = 0; 13 | 14 | for (; i < 8; i++) 15 | { 16 | int j = 0; 17 | 18 | for (; j < 8; j++) 19 | { 20 | _putchar(a[i][j]); 21 | } 22 | _putchar('\n'); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /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 of a square matrix 6 | * @a: array to be used 7 | * @size: size of the matrix 8 | * 9 | * Return: void 10 | */ 11 | 12 | void print_diagsums(int *a, int size) 13 | { 14 | int i = 0, j = 0, sum_1 = 0, sum_2 = 0; 15 | 16 | for (; i < size * size; i += size) 17 | { 18 | sum_1 += a[i + j]; 19 | sum_2 += a[i + (size - 1) - j]; 20 | j++; 21 | } 22 | printf("%d, %d\n", sum_1, sum_2); 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/9-set_string.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * set_string - sets the value of a pointer to a char 5 | * 6 | * @s: address of the pointer 7 | * @to: new value 8 | * 9 | * Return: void 10 | */ 11 | 12 | void set_string(char **s, char *to) 13 | { 14 | *s = to; 15 | } 16 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | /** 5 | * void prototypes() 6 | * int prototypes() 7 | */ 8 | 9 | char *_memset(char *, char, unsigned int); 10 | char *_memcpy(char *, char *, unsigned int); 11 | char *_strchr(char *, char); 12 | unsigned int _strspn(char *, char *); 13 | char *_strpbrk(char *, char *); 14 | char *_strstr(char *, char *); 15 | void print_chessboard(char (*a)[8]); 16 | void print_diagsums(int *, int); 17 | void set_string(char **s, char *to); 18 | 19 | #endif /*MAIN_H*/ 20 | -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _puts_recursion - prints's a string followed by a new line 5 | * @s: string to be printed 6 | * 7 | * Return: void 8 | */ 9 | void _puts_recursion(char *s) 10 | { 11 | if (*s == '\0') 12 | { 13 | _putchar('\n'); 14 | } 15 | else 16 | { 17 | _putchar(s[0]); 18 | _puts_recursion(s + 1); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _print_rev_recursion - prints a string in reverse 5 | * @s: string to be printed 6 | * 7 | * Return: void 8 | */ 9 | void _print_rev_recursion(char *s) 10 | { 11 | if (*s != '\0') 12 | { 13 | _print_rev_recursion(s + 1); 14 | _putchar(*s); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /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 | int wildcmp(char *s1, char *s2) 11 | { 12 | if (*s2 == '\0') 13 | return (*s1 == '\0'); 14 | if (*s2 == *s1) 15 | return (*s1 != '\0' && wildcmp(s1 + 1, s2 + 1)); 16 | if (*s2 == '*') 17 | return (wildcmp(s1, s2 + 1) || (*s1 != '\0' && wildcmp(s1 + 1, s2))); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strlen_recursion - calculates the length of a string 5 | * @s: string to be used 6 | * 7 | * Return: length of the string 8 | */ 9 | int _strlen_recursion(char *s) 10 | { 11 | int sum = 0; 12 | 13 | if (*s != '\0') 14 | { 15 | sum++; 16 | sum += _strlen_recursion(s + 1); 17 | } 18 | return (sum); 19 | } 20 | -------------------------------------------------------------------------------- /0x08-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * factorial - returns the factorial of a given number 5 | * @n: number to be used 6 | * 7 | * Return: the factorial of the number 8 | */ 9 | int factorial(int n) 10 | { 11 | int next_factorial; 12 | 13 | if (n < 0) 14 | return (-1); 15 | else if (n == 0) 16 | return (1); 17 | next_factorial = factorial(n - 1); 18 | return (n * next_factorial); 19 | } 20 | -------------------------------------------------------------------------------- /0x08-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _pow_recursion - returns the value of x raised to the power of y 5 | * @x: number to be used 6 | * @y: exponent to be used 7 | * 8 | * Return: x ^ y 9 | */ 10 | int _pow_recursion(int x, int y) 11 | { 12 | if (y < 0) 13 | return (-1); 14 | else if (y == 0) 15 | return (1); 16 | return (x * _pow_recursion(x, y - 1)); 17 | } 18 | -------------------------------------------------------------------------------- /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 | int _sqrt_recursion(int n) 10 | { 11 | if (n == 1 || n == 0) 12 | return (n); 13 | return (_sqrt(0, n)); 14 | } 15 | 16 | /** 17 | * _sqrt - returns the square root of a number 18 | * @n: test number 19 | * @x: squared number 20 | * 21 | * Return: the square root of n 22 | */ 23 | int _sqrt(int n, int x) 24 | { 25 | if (n > x / 2) 26 | return (-1); 27 | else if (n * n == x) 28 | return (n); 29 | return (_sqrt(n + 1, x)); 30 | } 31 | -------------------------------------------------------------------------------- /0x08-recursion/6-is_prime_number.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * is_prime_number - returns the 1 if n is prime 5 | * @n: number to be checked 6 | * 7 | * Return: 1 if n is prime, 0 otherwise 8 | */ 9 | int is_prime_number(int n) 10 | { 11 | int start = n / 2; 12 | 13 | if (n <= 1) 14 | return (0); 15 | return (is_prime(n, start)); 16 | } 17 | 18 | /** 19 | * is_prime - returns the 1 if n is prime 20 | * @n: number to be checked 21 | * @start: number to start checking from 22 | * 23 | * Return: 1 if n is prime, 0 otherwise 24 | */ 25 | int is_prime(int n, int start) 26 | { 27 | if (start <= 1) 28 | return (1); 29 | else if (n % start == 0) 30 | return (0); 31 | return (is_prime(n, start - 1)); 32 | } 33 | -------------------------------------------------------------------------------- /0x08-recursion/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | 6 | int _putchar(char c); 7 | void _puts_recursion(char *s); 8 | void _print_rev_recursion(char *s); 9 | int _strlen_recursion(char *s); 10 | int factorial(int n); 11 | int _pow_recursion(int x, int y); 12 | int _sqrt_recursion(int n); 13 | int is_prime_number(int n); 14 | int _sqrt(int n, int x); 15 | int is_prime(int n, int start); 16 | void check(char *s, int start, int end, int *flag); 17 | int wildcmp(char *s1, char *s2); 18 | 19 | #endif /*MAIN_H*/ 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/.gitignore: -------------------------------------------------------------------------------- 1 | _putchar.* -------------------------------------------------------------------------------- /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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strncpy - C function that copies a string, including the 4 | * terminating null byte, using at most an inputted number of bytes. 5 | * If the length of the source string is less than the maximum byte number, 6 | * the remainder of the destination string is filled with null bytes. 7 | * Works identically to the standard library function `strncpy`. 8 | *@dest: buffer storing the string copy 9 | *@src:the source string 10 | *@n:max nummber of byte copied 11 | *Return: returns 12 | */ 13 | 14 | char *_strncpy(char *dest, char *src, int n) 15 | { 16 | int i; 17 | 18 | for (i = 0; i < n && src[i] != '\0'; i++) 19 | dest[i] = src[i]; 20 | 21 | for ( ; i < n; i++) 22 | dest[i] = '\0'; 23 | 24 | return (dest); 25 | } 26 | -------------------------------------------------------------------------------- /0x09-static_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/3-puts.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - Function which compare two strings and 5 | *@s1: first string 6 | *@s2:second string 7 | *Return: 8 | * returns zero if s1 == s2 9 | * returns negative number if s1 < s2 10 | * returns positive number if s1 > s2 11 | */ 12 | 13 | int _strcmp(char *s1, char *s2) 14 | { 15 | int i = 0, diff = 0; 16 | 17 | while (1) 18 | { 19 | if (s1[i] == '\0' && s2[i] == '\0') 20 | break; 21 | else if (s1[i] == '\0') 22 | { 23 | diff = s2[i]; 24 | break; 25 | } 26 | else if (s2[i] == '\0') 27 | { 28 | diff = s1[i]; 29 | break; 30 | } 31 | else if (s1[i] != s2[i]) 32 | { 33 | diff = s1[i] - s2[i]; 34 | break; 35 | } 36 | else 37 | i++; 38 | 39 | } 40 | return (diff); 41 | } 42 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strspn - search the number of bytes in the initial 4 | * segment of s which consist only of bytes from accept 5 | *@s:segment targeted 6 | *@accept:reference bytes container 7 | * 8 | *Return:returns the number of bytes in the initial 9 | * segment of s which consist only of bytes from accept 10 | */ 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int bytes = 0; 14 | int i; 15 | 16 | while (*s) 17 | { 18 | for (i = 0; accept[i]; i++) 19 | { 20 | if (accept[i] == *s) 21 | { 22 | bytes++; 23 | break; 24 | } 25 | else if ((accept[i + 1]) == '\0') 26 | return (bytes); 27 | } 28 | s++; 29 | } 30 | return (bytes); 31 | } 32 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strpbrk - The _strpbrk() function locates the first 4 | * occurrence in the string s of any of the bytes in 5 | *the string accept 6 | * 7 | *@s: string where search is made 8 | *@accept: string where searched bytes are located 9 | * 10 | *Return:Returns a pointer to the byte in s that matches 11 | * one of the bytes in accept, or NULL if no such byte is found 12 | */ 13 | 14 | char *_strpbrk(char *s, char *accept) 15 | { 16 | int i; 17 | 18 | while (*s) 19 | { 20 | for (i = 0; accept[i]; i++) 21 | { 22 | if (accept[i] == *s) 23 | return (s); 24 | } 25 | s++; 26 | } 27 | 28 | return ('\0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x09-static_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x09-static_libraries/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strstr - The _strstr() function finds the first occurrence 4 | * of the substring needle in the string haystack. 5 | * The terminating null bytes (\0) are not compared 6 | *@haystack: string where the search is made 7 | *@needle: string whose occurence is searched in haystack 8 | *Return:Returns a pointer to the beginning of the located 9 | * substring, or NULL if the substring is not found. 10 | */ 11 | 12 | char *_strstr(char *haystack, char *needle) 13 | { 14 | int i; 15 | 16 | if (*needle == 0) 17 | return (haystack); 18 | 19 | while (*haystack) 20 | { 21 | i = 0; 22 | 23 | if (haystack[i] == needle[i]) 24 | { 25 | do { 26 | if (needle[i + 1] == '\0') 27 | return (haystack); 28 | i++; 29 | } while (haystack[i] == needle[i]); 30 | } 31 | haystack++; 32 | } 33 | return ('\0'); 34 | } 35 | -------------------------------------------------------------------------------- /0x09-static_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/9-strcpy.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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/liball.a -------------------------------------------------------------------------------- /0x09-static_libraries/libmy.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x09-static_libraries/libmy.a -------------------------------------------------------------------------------- /0x09-static_libraries/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | 5 | int _putchar(char c); 6 | int _islower(int c); 7 | int _isalpha(int c); 8 | int _abs(int n); 9 | int _isupper(int c); 10 | int _isdigit(int c); 11 | int _strlen(char *s); 12 | void _puts(char *s); 13 | char *_strcpy(char *dest, char *src); 14 | int _atoi(char *s); 15 | char *_strcat(char *dest, char *src); 16 | char *_strncat(char *dest, char *src, int n); 17 | char *_strncpy(char *dest, char *src, int n); 18 | int _strcmp(char *s1, char *s2); 19 | char *_memset(char *s, char b, unsigned int n); 20 | char *_memcpy(char *dest, char *src, unsigned int n); 21 | char *_strchr(char *s, char c); 22 | unsigned int _strspn(char *s, char *accept); 23 | char *_strpbrk(char *s, char *accept); 24 | char *_strstr(char *haystack, char *needle); 25 | 26 | #endif /* MAIN_H */ 27 | -------------------------------------------------------------------------------- /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/100-change.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | *main - prints the minimum number of coins to make change 6 | * for an amount of money 7 | *@argc: number of arguments 8 | *@argv: array of arguments 9 | *Return: returns 1 if there is an error; else returns 0 10 | */ 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | int cents, coins = 0; 15 | 16 | if (argc != 2) 17 | { 18 | printf("Error\n"); 19 | return (1); 20 | } 21 | cents = atoi(argv[1]); 22 | while (cents > 0) 23 | { 24 | coins++; 25 | if ((cents - 25) >= 0) 26 | { 27 | cents -= 25; 28 | continue; 29 | } 30 | if ((cents - 10) >= 0) 31 | { 32 | cents -= 10; 33 | continue; 34 | } 35 | if ((cents - 5) >= 0) 36 | { 37 | cents -= 5; 38 | continue; 39 | } 40 | if ((cents - 2) >= 0) 41 | { 42 | cents -= 2; 43 | continue; 44 | } 45 | cents--; 46 | } 47 | printf("%d\n", coins); 48 | return (0); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0B-malloc_free/0-create_array.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * create_array - creates an array of chars, and 5 | * initializes it with a specific char. 6 | *@size: Size of the array 7 | *@c: Character to insert 8 | *Return: NULL if size is zero or if it fails, 9 | *pointer to array if everything is normal. 10 | */ 11 | 12 | char *create_array(unsigned int size, char c) 13 | { 14 | char *array; 15 | unsigned int index; 16 | 17 | if (size == 0) 18 | return (NULL); 19 | array = malloc(sizeof(char) * size); 20 | 21 | if (array == NULL) 22 | return (NULL); 23 | 24 | for (index = 0; index < size; index++) 25 | array[index] = c; 26 | 27 | return (array); 28 | } 29 | -------------------------------------------------------------------------------- /0x0B-malloc_free/1-strdup.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strdup - returns a pointer to a newly allocated 5 | *space in memory, which contains a copy of the 6 | *string given as a parameter. 7 | *@str:String to be copied 8 | * 9 | *Return: NULL in case of error, pointer to allocated 10 | *space 11 | */ 12 | 13 | char *_strdup(char *str) 14 | { 15 | char *cpy; 16 | int index, len; 17 | 18 | if (str == NULL) 19 | return (NULL); 20 | 21 | for (index = 0; str[index]; index++) 22 | len++; 23 | cpy = malloc(sizeof(char) * (len + 1)); 24 | 25 | if (cpy == NULL) 26 | return (NULL); 27 | 28 | for (index = 0; str[index]; index++) 29 | { 30 | cpy[index] = str[index]; 31 | } 32 | 33 | cpy[len] = '\0'; 34 | 35 | return (cpy); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /0x0B-malloc_free/2-str_concat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * str_concat - a function that concatenates two strings. 5 | *@s1:First string 6 | *@s2:Second string 7 | * 8 | *Return: NULL in case of failure , but pointer to new string in 9 | *case of success 10 | */ 11 | 12 | char *str_concat(char *s1, char *s2) 13 | { 14 | char *concat_str; 15 | int index, concat_index = 0, len = 0; 16 | 17 | if (s1 == NULL) 18 | s1 = ""; 19 | 20 | if (s2 == NULL) 21 | s2 = ""; 22 | 23 | for (index = 0; s1[index] || s2[index]; index++) 24 | len++; 25 | 26 | concat_str = malloc(sizeof(char) * len); 27 | 28 | if (concat_str == NULL) 29 | return (NULL); 30 | 31 | for (index = 0; s1[index]; index++) 32 | concat_str[concat_index++] = s1[index]; 33 | 34 | for (index = 0; s2[index]; index++) 35 | concat_str[concat_index++] = s2[index]; 36 | 37 | return (concat_str); 38 | } 39 | -------------------------------------------------------------------------------- /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/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | 6 | char *create_array(unsigned int size, char c); 7 | 8 | #endif /* MAIN_H */ -------------------------------------------------------------------------------- /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 | 10 | void *malloc_checked(unsigned int b) 11 | { 12 | void *block; 13 | 14 | block = malloc(b); 15 | if (block == NULL) 16 | exit(98); 17 | return (block); 18 | } 19 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/1-string_nconcat.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * string_nconcat - concatenates 2 strings, takes the first n chars of s2 6 | * @s1: string 1 7 | * @s2: string 2 8 | * @n: amount of chars to be used from s2 9 | * 10 | * Return: pointer to the new string 11 | */ 12 | 13 | char *string_nconcat(char *s1, char *s2, unsigned int n) 14 | { 15 | char *new_string; 16 | int i = 0, j = 0, size_1 = strlen(s1), size_2; 17 | 18 | n < (unsigned int) strlen(s2) ? (size_2 = n) : (size_2 = strlen(s2)); 19 | new_string = (char *) malloc(size_1 + size_2 + 1); 20 | if (new_string != NULL) 21 | { 22 | for (; i < size_1; i++) 23 | { 24 | new_string[i] = s1[i]; 25 | } 26 | for (; j < size_2; j++) 27 | { 28 | new_string[i + j] = s2[j]; 29 | } 30 | new_string[i + j] = '\0'; 31 | } 32 | else 33 | { 34 | return (NULL); 35 | } 36 | 37 | return (new_string); 38 | } 39 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/2-calloc.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _calloc - allocates memory using malloc, and initializes it to zero 5 | * @size: size of the memory block to be allocated 6 | * @nmemb: number of elements 7 | * 8 | * Return: pointer to the address of the memory block 9 | */ 10 | 11 | void *_calloc(unsigned int nmemb, unsigned int size) 12 | { 13 | char *block; 14 | unsigned int i; 15 | 16 | if (nmemb == 0 || size == 0) 17 | return (NULL); 18 | block = malloc(nmemb * size); 19 | if (block != NULL) 20 | { 21 | for (i = 0; i < (nmemb * size); i++) 22 | block[i] = 0; 23 | return (block); 24 | } 25 | else 26 | return (NULL); 27 | } 28 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/3-array_range.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * array_range - creates an array of integers 6 | * @min: smallest number in the array 7 | * @max: largest value in the array 8 | * 9 | * Return: pointer to the address of the memory block 10 | */ 11 | 12 | int *array_range(int min, int max) 13 | { 14 | int *block; 15 | int i, j = 0; 16 | 17 | if (min > max) 18 | return (NULL); 19 | block = malloc(sizeof(*block) * ((max - min) + 1)); 20 | if (block != NULL) 21 | { 22 | for (i = min; i <= max; i++) 23 | { 24 | block[j] = i; 25 | j++; 26 | } 27 | return (block); 28 | } 29 | else 30 | return (NULL); 31 | } 32 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | #define min(x, y) (((x) < (y)) ? (x) : (y)) 7 | 8 | int _putchar(char c); 9 | void *malloc_checked(unsigned int b); 10 | char *string_nconcat(char *s1, char *s2, unsigned int n); 11 | int len(char *str); 12 | void *_calloc(unsigned int nmemb, unsigned int size); 13 | int *array_range(int min, int max); 14 | void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size); 15 | 16 | #endif /*MAIN_H*/ 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/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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/2-print_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | 3 | /** 4 | * print_dog - prints a struct dog 5 | * @d: pointer to the struct dog 6 | * 7 | * Return: void 8 | */ 9 | 10 | void print_dog(struct dog *d) 11 | { 12 | if (d != NULL) 13 | { 14 | if (d->name != NULL) 15 | printf("Name: %s\n", d->name); 16 | else 17 | printf("Name: (nil)\n"); 18 | printf("Age: %f\n", d->age); 19 | if (d->owner != NULL) 20 | printf("Owner: %s\n", d->owner); 21 | else 22 | printf("Owner: (nil)\n"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-free_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | 3 | /** 4 | * free_dog - frees a memory block of type dog_t 5 | * @d: address to the memory block to be freed 6 | * 7 | * Return: void 8 | */ 9 | 10 | void free_dog(dog_t *d) 11 | { 12 | if (d != NULL) 13 | { 14 | free(d->name); 15 | free(d->owner); 16 | free(d); 17 | } 18 | } -------------------------------------------------------------------------------- /0x0E-structures_typedef/dog.h: -------------------------------------------------------------------------------- 1 | #ifndef DOG_H 2 | #define DOG_H 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | *struct dog - a new type of data 9 | *representing a dog 10 | *@name: name of dog 11 | *@age: age of dog 12 | *@owner: owner's name 13 | */ 14 | struct dog 15 | { 16 | char *name; 17 | float age; 18 | char *owner; 19 | }; 20 | 21 | 22 | /** 23 | *dog_t - Typedef for struct dog 24 | */ 25 | typedef struct dog dog_t; 26 | 27 | 28 | void init_dog(struct dog *d, char *name, float age, char *owner); 29 | void print_dog(struct dog *d); 30 | dog_t *new_dog(char *name, float age, char *owner); 31 | void free_dog(dog_t *d); 32 | int _strlen(char *str); 33 | char *_strcopy(char *dest, char *src); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x0F-function_pointers/100-main_opcodes.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - prints the opcodes of the main function 6 | * @argc: number of arguments passed to the program 7 | * @argv: array of arguments passed to the function 8 | * 9 | * Return: 0 on success, 1 or 2 otherwise 10 | */ 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | unsigned char *f; 15 | int i = 0, bytes; 16 | 17 | if (argc != 2) 18 | { 19 | printf("Error\n"); 20 | exit(1); 21 | } 22 | if (atoi(argv[1]) < 0) 23 | { 24 | printf("Error\n"); 25 | exit(2); 26 | } 27 | f = (unsigned char *) main; 28 | bytes = atoi(argv[1]); 29 | for (; i < bytes; i++) 30 | { 31 | printf("%02x", *(f + i)); 32 | if (i != bytes - 1) 33 | printf(" "); 34 | } 35 | printf("\n"); 36 | 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /0x0F-function_pointers/2-int_index.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * int_index - searches for an integer 5 | * @array: Array containing elements 6 | * @size: number of elements in array 7 | * @cmp: function which compare values 8 | * 9 | * Return: returns -1 if no element match 10 | * or when size is less than zero 11 | * return pointer to the first corresponding element 12 | * 13 | */ 14 | 15 | int int_index(int *array, int size, int (*cmp)(int)) 16 | { 17 | int index = 0; 18 | 19 | if (array == NULL || cmp == NULL) 20 | return (-1); 21 | 22 | for (; index < size; index++) 23 | { 24 | if (cmp(array[index]) != 0) 25 | return (index); 26 | } 27 | 28 | return (-1); 29 | } 30 | -------------------------------------------------------------------------------- /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 | 10 | typedef struct op 11 | { 12 | char *op; 13 | int (*f)(int a, int b); 14 | } op_t; 15 | 16 | int op_add(int a, int b); 17 | int op_sub(int a, int b); 18 | int op_mul(int a, int b); 19 | int op_div(int a, int b); 20 | int op_mod(int a, int b); 21 | int (*get_op_func(char *s))(int, int); 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-get_op_func.c: -------------------------------------------------------------------------------- 1 | #include "3-calc.h" 2 | #include 3 | 4 | /** 5 | * get_op_func - selects the correct function to perform 6 | * the operation asked by the user. You’re not allowed 7 | * to declare any other function. 8 | * @s: operator passed as argument 9 | * 10 | * Return: A pointer to the function corresponding to 11 | * the operator given in parameter 12 | */ 13 | 14 | int (*get_op_func(char *s))(int, int) 15 | { 16 | op_t ops[] = { 17 | {"+", op_add}, 18 | {"-", op_sub}, 19 | {"*", op_mul}, 20 | {"/", op_div}, 21 | {"%", op_mod}, 22 | {NULL, NULL} 23 | }; 24 | int i = 0; 25 | 26 | while (ops[i].op != NULL && *(ops[i].op) != *s) 27 | i++; 28 | 29 | return (ops[i].f); 30 | } 31 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-main.c: -------------------------------------------------------------------------------- 1 | #include "3-calc.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Prints the result of simple operations. 7 | * @argc: The number of arguments supplied to the program. 8 | * @argv: An array of pointers to the arguments. 9 | * 10 | * Return: Always 0. 11 | */ 12 | 13 | int main(int __attribute__((__unused__)) argc, char *argv[]) 14 | { 15 | int num1, num2; 16 | char *op; 17 | 18 | if (argc != 4) 19 | { 20 | printf("Error\n"); 21 | exit(98); 22 | } 23 | 24 | num1 = atoi(argv[1]); 25 | op = argv[2]; 26 | num2 = atoi(argv[3]); 27 | 28 | if (get_op_func(op) == NULL || op[1] != '\0') 29 | { 30 | printf("Error\n"); 31 | exit(99); 32 | } 33 | 34 | if ((*op == '/' && num2 == 0) || (*op == '%' && num2 == 0)) 35 | { 36 | printf("Error\n"); 37 | exit(100); 38 | } 39 | printf("%d\n", get_op_func(op)(num1, num2)); 40 | 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x10-variadic_functions/0-sum_them_all.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * sum_them_all - adds all the parameters passed to it 5 | * @n: number of args passed 6 | * 7 | * Return: sum of all the parameters 8 | */ 9 | 10 | int sum_them_all(const unsigned int n, ...) 11 | { 12 | int sum = 0; 13 | unsigned int i; 14 | va_list params; 15 | 16 | va_start(params, n); 17 | if (n != 0) 18 | { 19 | for (i = 0; i < n; i++) 20 | sum += va_arg(params, int); 21 | } 22 | va_end(params); 23 | 24 | return (sum); 25 | } 26 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * print_numbers - prints all the parameters passed to it 5 | * @n: number of args passed 6 | * @separator: is the string to be printed between numbers 7 | * 8 | * Return: void 9 | */ 10 | 11 | void print_numbers(const char *separator, const unsigned int n, ...) 12 | { 13 | unsigned int i; 14 | va_list params; 15 | 16 | va_start(params, n); 17 | if (n != 0) 18 | { 19 | for (i = 0; i < n; i++) 20 | { 21 | if (i != n - 1) 22 | { 23 | if (separator != NULL) 24 | printf("%d%s", va_arg(params, int), separator); 25 | else 26 | printf("%d", va_arg(params, int)); 27 | } 28 | else 29 | { 30 | printf("%d", va_arg(params, int)); 31 | } 32 | } 33 | } 34 | printf("\n"); 35 | va_end(params); 36 | } 37 | -------------------------------------------------------------------------------- /0x10-variadic_functions/variadic_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIADIC_FUNC 2 | #define VARIADIC_FUNC 3 | 4 | #include 5 | #include 6 | 7 | int sum_them_all(const unsigned int n, ...); 8 | void print_numbers(const char *separator, const unsigned int n, ...); 9 | void print_strings(const char *separator, const unsigned int n, ...); 10 | void print_all(const char * const format, ...); 11 | char *make_nil(char *s); 12 | int count_format(const char * const format); 13 | void print_comma(int j, int x); 14 | 15 | #endif /*VARIADIC_FUNC*/ 16 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/.gitignore: -------------------------------------------------------------------------------- 1 | test.c -------------------------------------------------------------------------------- /0x12-singly_linked_lists/0-print_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_list - 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_list(const list_t *h) 10 | { 11 | const list_t *cursor = h; 12 | size_t count = 0; 13 | 14 | while (cursor != NULL) 15 | { 16 | if (cursor->str != NULL) 17 | printf("[%d] %s\n", cursor->len, cursor->str); 18 | else 19 | printf("[0] (nil)\n"); 20 | count += 1; 21 | cursor = cursor->next; 22 | } 23 | return (count); 24 | } 25 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * list_len - counts the number of nodes in a linked list 5 | * @h: head of the list 6 | * 7 | * Return: the number of elements 8 | */ 9 | size_t list_len(const list_t *h) 10 | { 11 | const list_t *cursor = h; 12 | size_t count = 0; 13 | 14 | while (cursor != NULL) 15 | { 16 | count += 1; 17 | cursor = cursor->next; 18 | } 19 | return (count); 20 | } 21 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-first.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void start_up_func(void)__attribute__((constructor)); 4 | 5 | /** 6 | * start_up_func - function that get's executed before the main function 7 | * 8 | * Return: void 9 | */ 10 | void start_up_func(void) 11 | { 12 | printf("You're beat! and yet, you must allow,\n" 13 | "I bore my house upon my back!\n"); 14 | } 15 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | global main 2 | 3 | section .text 4 | 5 | main: 6 | mov rax, 1 7 | mov rdi, 1 8 | mov rsi, msg 9 | mov rdx, msglen 10 | syscall 11 | 12 | mov rax, 60 13 | mov rdi, 0 14 | syscall 15 | 16 | section .rodata 17 | msg: db "Hello, Holberton", 10 18 | msglen: equ $ - msg 19 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-free_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_list - frees a linked list 5 | * @head: head of the list 6 | * 7 | * Return: void 8 | */ 9 | void free_list(list_t *head) 10 | { 11 | list_t *temp; 12 | 13 | if (head != NULL) 14 | { 15 | while (head != NULL) 16 | { 17 | temp = head; 18 | head = head->next; 19 | free(temp->str); 20 | free(temp); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef LISTS_H 2 | #define LISTS_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * struct list_s - singly linked list 10 | * @str: string - (malloc'ed string) 11 | * @len: length of the string 12 | * @next: points to the next node 13 | * 14 | * Description: singly linked list node structure 15 | * for Holberton project 16 | */ 17 | typedef struct list_s 18 | { 19 | char *str; 20 | unsigned int len; 21 | struct list_s *next; 22 | } list_t; 23 | 24 | size_t print_list(const list_t *h); 25 | size_t list_len(const list_t *h); 26 | list_t *add_node(list_t **head, const char *str); 27 | list_t *add_node_end(list_t **head, const char *str); 28 | void free_list(list_t *head); 29 | int _strlen(const char *str); 30 | 31 | #endif /*LISTS_H*/ 32 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.out 3 | test.c -------------------------------------------------------------------------------- /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 | * listint_len - counts the number of nodes in a linked list 5 | * @h: head of the list 6 | * 7 | * Return: the number of elements 8 | */ 9 | size_t listint_len(const listint_t *h) 10 | { 11 | const listint_t *cursor = h; 12 | size_t count = 0; 13 | 14 | while (cursor != NULL) 15 | { 16 | count += 1; 17 | cursor = cursor->next; 18 | } 19 | return (count); 20 | } 21 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/100-reverse_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * reverse_listint - reverses a linked list 5 | * @head: head of the list 6 | * 7 | * Return: the first node of the reversed node 8 | */ 9 | listint_t *reverse_listint(listint_t **head) 10 | { 11 | listint_t *next_node = NULL; 12 | listint_t *prev_node = NULL; 13 | 14 | if (head == NULL) 15 | return (NULL); 16 | while (*head != NULL) 17 | { 18 | next_node = (*head)->next; 19 | (*head)->next = prev_node; 20 | prev_node = *head; 21 | *head = next_node; 22 | } 23 | *head = prev_node; 24 | return (*head); 25 | } 26 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/2-add_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_nodeint - adds a node to the beginning of a linked list 5 | * @head: pointer to the head of the list 6 | * @n: integer to be used as content 7 | * 8 | * Return: address of the newly added node 9 | */ 10 | listint_t *add_nodeint(listint_t **head, const int n) 11 | { 12 | listint_t *new_node; 13 | 14 | new_node = malloc(sizeof(listint_t)); 15 | if (new_node != NULL) 16 | { 17 | new_node->n = n; 18 | new_node->next = *head; 19 | } 20 | else 21 | return (NULL); 22 | if (*head != NULL) 23 | new_node->next = *head; 24 | *head = new_node; 25 | return (new_node); 26 | } 27 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/3-add_nodeint_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_nodeint_end - adds a node to the end of a linked list 5 | * @head: pointer to the head of the list 6 | * @n: number to be used as content 7 | * 8 | * Return: address of the newly added node 9 | */ 10 | listint_t *add_nodeint_end(listint_t **head, const int n) 11 | { 12 | listint_t *new_node; 13 | listint_t *cursor = *head; 14 | 15 | new_node = malloc(sizeof(listint_t)); 16 | if (new_node != NULL) 17 | { 18 | new_node->n = n; 19 | new_node->next = NULL; 20 | } 21 | else 22 | return (NULL); 23 | if (cursor != NULL) 24 | { 25 | while (cursor->next != NULL) 26 | cursor = cursor->next; 27 | cursor->next = new_node; 28 | } 29 | else 30 | *head = new_node; 31 | return (new_node); 32 | } 33 | -------------------------------------------------------------------------------- /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 | void free_listint(listint_t *head) 10 | { 11 | listint_t *temp; 12 | 13 | while (head != NULL) 14 | { 15 | temp = head; 16 | head = head->next; 17 | free(temp); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-free_listint2.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *free_listint2 - frees a linked list 5 | *@head: pointer to the head of the list 6 | * 7 | *Return: void 8 | */ 9 | 10 | void free_listint2(listint_t **head) 11 | { 12 | listint_t *cursor; 13 | listint_t **temp = head; 14 | 15 | if (temp != NULL) 16 | { 17 | while (*head != NULL) 18 | { 19 | cursor = *head; 20 | free(cursor); 21 | *head = (*head)->next; 22 | } 23 | 24 | *temp = NULL; 25 | } 26 | } -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/6-pop_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | *pop_listint - deletes the head node of a linked list 5 | *@head: head of the list 6 | * 7 | *Return: the deleted node data 8 | */ 9 | 10 | int pop_listint(listint_t **head) 11 | { 12 | listint_t *popped; 13 | int content; 14 | 15 | if (*head == NULL) 16 | return (0); 17 | 18 | popped = *head; 19 | content = popped->n; 20 | free(popped); 21 | 22 | *head = (*head)->next; 23 | return (content); 24 | } 25 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/7-get_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_nodeint_at_index - returns 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 | listint_t *get_nodeint_at_index(listint_t *head, unsigned int index) 11 | { 12 | listint_t *cursor = NULL; 13 | unsigned int i = 0; 14 | 15 | while (head != NULL) 16 | { 17 | if (i <= index) 18 | { 19 | if (i == index) 20 | { 21 | cursor = head; 22 | break; 23 | } 24 | head = head->next; 25 | i++; 26 | } 27 | else 28 | return (NULL); 29 | } 30 | return (cursor); 31 | } 32 | -------------------------------------------------------------------------------- /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 | int sum_listint(listint_t *head) 10 | { 11 | listint_t *cursor = head; 12 | size_t sum = 0; 13 | 14 | while (cursor != NULL) 15 | { 16 | sum += cursor->n; 17 | cursor = cursor->next; 18 | } 19 | return (sum); 20 | } 21 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/.gitignore: -------------------------------------------------------------------------------- 1 | test.c -------------------------------------------------------------------------------- /0x14-bit_manipulation/1-print_binary.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_binary - prints the binary representaion of a number 5 | * @n: number to be used 6 | * 7 | * Return: void 8 | */ 9 | void print_binary(unsigned long int n) 10 | { 11 | if (n > 1) 12 | print_binary(n >> 1); 13 | _putchar((n & 1) + '0'); 14 | } 15 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-get_endianness.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * get_endianness - checks whether a machine is big endian or little 5 | * 6 | * Return: 1 if little endian, 0 otherwise 7 | */ 8 | int get_endianness(void) 9 | { 10 | unsigned int test = 1; 11 | char *endian = (char *)&test; 12 | 13 | if (*endian) 14 | return (1); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/101-password: -------------------------------------------------------------------------------- 1 | Hol -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-get_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * get_bit - gets the value of a bit at a given index 5 | * @n: the number 6 | * @index: index staring from 0 of the bit required 7 | * 8 | * Return: the converted value 9 | */ 10 | int get_bit(unsigned long int n, unsigned int index) 11 | { 12 | if (index > 63) 13 | return (-1); 14 | return ((n >> index) & 1); 15 | } 16 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-set_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * set_bit - sets a bit at a position to 1 6 | * @n: number to be used 7 | * @index: index to be set 8 | * 9 | * Return: 1 on success, -1 on fail 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 | *n |= (1 << index); 16 | return (1); 17 | } 18 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-clear_bit.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | #include 3 | 4 | /** 5 | * clear_bit - sets a bit at a position to 0 6 | * @n: number to be used 7 | * @index: position to be cleared 8 | * 9 | * Return: 1 on success, -1 on fail 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 | *n &= ~(1 << index); 16 | return (1); 17 | } 18 | -------------------------------------------------------------------------------- /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: initial 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/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | unsigned int binary_to_uint(const char *b); 5 | int check_valid_string(const char *b); 6 | void print_binary(unsigned long int n); 7 | int _putchar(char c); 8 | int get_bit(unsigned long int n, unsigned int index); 9 | int set_bit(unsigned long int *n, unsigned int index); 10 | int clear_bit(unsigned long int *n, unsigned int index); 11 | unsigned int flip_bits(unsigned long int n, unsigned long int m); 12 | int get_endianness(void); 13 | 14 | #endif /*MAIN_H*/ 15 | -------------------------------------------------------------------------------- /0x15-file_io/.gitignore: -------------------------------------------------------------------------------- 1 | Requiescat 2 | test.c -------------------------------------------------------------------------------- /0x15-file_io/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int _putchar(char c); 12 | ssize_t read_textfile(const char *filename, size_t letters); 13 | int create_file(const char *filename, char *text_content); 14 | int _strlen(char *str); 15 | int append_text_to_file(const char *filename, char *text_content); 16 | 17 | #endif /*MAIN_H*/ 18 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/0-print_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_dlistint - prints all the elements of a dlistint_t list. 5 | * @h: The head of the dlistint_t list. 6 | * 7 | * Return: The number of nodes in the list. 8 | */ 9 | size_t print_dlistint(const dlistint_t *h) 10 | { 11 | size_t nodes = 0; 12 | 13 | while (h) 14 | { 15 | nodes++; 16 | printf("%d\n", h->n); 17 | h = h->next; 18 | } 19 | 20 | return (nodes); 21 | } 22 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/1-dlistint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * dlistint_len - Counts the number of elements in a linked dlistint_t list. 5 | * @h: The head of the dlistint_t list. 6 | * 7 | * Return: The number of elements in the dlistint_t list. 8 | */ 9 | size_t dlistint_len(const dlistint_t *h) 10 | { 11 | size_t nodes = 0; 12 | 13 | while (h) 14 | { 15 | nodes++; 16 | h = h->next; 17 | } 18 | 19 | return (nodes); 20 | } 21 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/100-password: -------------------------------------------------------------------------------- 1 | en C Pyfo neZ -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/102-result: -------------------------------------------------------------------------------- 1 | 906609 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/2-add_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_dnodeint - Adds a new node at the beginning of a dlistint_t list. 5 | * @head: A pointer to the head of the dlistint_t list. 6 | * @n: The integer for the new node to contain. 7 | * 8 | * Return: If the function fails - NULL. 9 | * Otherwise - the address of the new node. 10 | */ 11 | dlistint_t *add_dnodeint(dlistint_t **head, const int n) 12 | { 13 | dlistint_t *new; 14 | 15 | new = malloc(sizeof(dlistint_t)); 16 | if (new == NULL) 17 | return (NULL); 18 | 19 | new->n = n; 20 | new->prev = NULL; 21 | new->next = *head; 22 | if (*head != NULL) 23 | (*head)->prev = new; 24 | *head = new; 25 | 26 | return (new); 27 | } 28 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/3-add_dnodeint_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_dnodeint_end - Adds a new node at the end of a dlistint_t list. 5 | * @head: A pointer to the head of the dlistint_t list. 6 | * @n: The integer for the new node to contain. 7 | * 8 | * Return: If the function fails - NULL. 9 | * Otherwise - the address of the new node. 10 | */ 11 | dlistint_t *add_dnodeint_end(dlistint_t **head, const int n) 12 | { 13 | dlistint_t *new, *last; 14 | 15 | new = malloc(sizeof(dlistint_t)); 16 | if (new == NULL) 17 | return (NULL); 18 | 19 | new->n = n; 20 | new->next = NULL; 21 | 22 | if (*head == NULL) 23 | { 24 | new->prev = NULL; 25 | *head = new; 26 | return (new); 27 | } 28 | 29 | last = *head; 30 | while (last->next != NULL) 31 | last = last->next; 32 | last->next = new; 33 | new->prev = last; 34 | 35 | return (new); 36 | } 37 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/4-free_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_dlistint - Frees a linked dlistint_t list. 5 | * @head: The head of the dlistint_t list. 6 | */ 7 | void free_dlistint(dlistint_t *head) 8 | { 9 | dlistint_t *tmp; 10 | 11 | while (head) 12 | { 13 | tmp = head->next; 14 | free(head); 15 | head = tmp; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/5-get_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_dnodeint_at_index - Locates a node in a dlistint_t list. 5 | * @head: The head of the dlistint_t list. 6 | * @index: The node to locate. 7 | * 8 | * Return: If the node does not exist - NULL. 9 | * Otherwise - the address of the located node. 10 | */ 11 | dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index) 12 | { 13 | for (; index != 0; index--) 14 | { 15 | if (head == NULL) 16 | return (NULL); 17 | head = head->next; 18 | } 19 | 20 | return (head); 21 | } 22 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/6-sum_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_dlistint - Sums all the data of a dlistint_t list. 5 | * @head: The head of the dlistint_t list. 6 | * 7 | * Return: The sum of all the data. 8 | */ 9 | int sum_dlistint(dlistint_t *head) 10 | { 11 | int sum = 0; 12 | 13 | while (head) 14 | { 15 | sum += head->n; 16 | head = head->next; 17 | } 18 | 19 | return (sum); 20 | } 21 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | dlistint_t *new; 15 | dlistint_t hello = {8, NULL, NULL}; 16 | size_t n; 17 | 18 | head = &hello; 19 | new = malloc(sizeof(dlistint_t)); 20 | if (new == NULL) 21 | { 22 | dprintf(2, "Error: Can't malloc\n"); 23 | return (EXIT_FAILURE); 24 | } 25 | new->n = 9; 26 | head->prev = new; 27 | new->next = head; 28 | new->prev = NULL; 29 | head = new; 30 | n = print_dlistint(head); 31 | printf("-> %lu elements\n", n); 32 | free(new); 33 | return (EXIT_SUCCESS); 34 | } 35 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | dlistint_t *new; 15 | dlistint_t hello = {8, NULL, NULL}; 16 | size_t n; 17 | 18 | head = &hello; 19 | new = malloc(sizeof(dlistint_t)); 20 | if (new == NULL) 21 | { 22 | dprintf(2, "Error: Can't malloc\n"); 23 | return (EXIT_FAILURE); 24 | } 25 | new->n = 9; 26 | head->prev = new; 27 | new->next = head; 28 | new->prev = NULL; 29 | head = new; 30 | n = dlistint_len(head); 31 | printf("-> %lu elements\n", n); 32 | free(new); 33 | return (EXIT_SUCCESS); 34 | } 35 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | 15 | head = NULL; 16 | add_dnodeint(&head, 0); 17 | add_dnodeint(&head, 1); 18 | add_dnodeint(&head, 2); 19 | add_dnodeint(&head, 3); 20 | add_dnodeint(&head, 4); 21 | add_dnodeint(&head, 98); 22 | add_dnodeint(&head, 402); 23 | add_dnodeint(&head, 1024); 24 | print_dlistint(head); 25 | return (EXIT_SUCCESS); 26 | } 27 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 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 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 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 | free_dlistint(head); 26 | head = NULL; 27 | return (EXIT_SUCCESS); 28 | } 29 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | dlistint_t *node; 15 | 16 | head = NULL; 17 | add_dnodeint_end(&head, 0); 18 | add_dnodeint_end(&head, 1); 19 | add_dnodeint_end(&head, 2); 20 | add_dnodeint_end(&head, 3); 21 | add_dnodeint_end(&head, 4); 22 | add_dnodeint_end(&head, 98); 23 | add_dnodeint_end(&head, 402); 24 | add_dnodeint_end(&head, 1024); 25 | print_dlistint(head); 26 | node = get_dnodeint_at_index(head, 5); 27 | printf("%d\n", node->n); 28 | free_dlistint(head); 29 | head = NULL; 30 | return (EXIT_SUCCESS); 31 | } 32 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/6-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | dlistint_t *head; 14 | int sum; 15 | 16 | head = NULL; 17 | add_dnodeint_end(&head, 0); 18 | add_dnodeint_end(&head, 1); 19 | add_dnodeint_end(&head, 2); 20 | add_dnodeint_end(&head, 3); 21 | add_dnodeint_end(&head, 4); 22 | add_dnodeint_end(&head, 98); 23 | add_dnodeint_end(&head, 402); 24 | add_dnodeint_end(&head, 1024); 25 | sum = sum_dlistint(head); 26 | printf("sum = %d\n", sum); 27 | free_dlistint(head); 28 | head = NULL; 29 | return (EXIT_SUCCESS); 30 | } 31 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/tests/7-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../lists.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 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 | printf("-----------------\n"); 26 | insert_dnodeint_at_index(&head, 5, 4096); 27 | print_dlistint(head); 28 | free_dlistint(head); 29 | head = NULL; 30 | return (EXIT_SUCCESS); 31 | } 32 | -------------------------------------------------------------------------------- /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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/0-isupper.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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-create_dynamic_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -fPIC -c *.c 3 | gcc -shared -o liball.so *.o 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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/100-operations.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-make_me_win.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | wget -q --output-document=$HOME/lib101-makemewin.so https://github.com/B3zaleel/alx-low_level_programming/raw/main/0x18-dynamic_libraries/lib101-makemewin.so 3 | export LD_PRELOAD=$HOME/lib101-makemewin.so 4 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/101-makemewin.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-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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | * _strncpy - C function that copies a string, including the 4 | * terminating null byte, using at most an inputted number of bytes. 5 | * If the length of the source string is less than the maximum byte number, 6 | * the remainder of the destination string is filled with null bytes. 7 | * Works identically to the standard library function `strncpy`. 8 | *@dest: buffer storing the string copy 9 | *@src:the source string 10 | *@n:max nummber of byte copied 11 | *Return: returns 12 | */ 13 | 14 | char *_strncpy(char *dest, char *src, int n) 15 | { 16 | int i; 17 | 18 | for (i = 0; i < n && src[i] != '\0'; i++) 19 | dest[i] = src[i]; 20 | 21 | for ( ; i < n; i++) 22 | dest[i] = '\0'; 23 | 24 | return (dest); 25 | } 26 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/3-puts.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _strcmp - Function which compare two strings and 5 | *@s1: first string 6 | *@s2:second string 7 | *Return: 8 | * returns zero if s1 == s2 9 | * returns negative number if s1 < s2 10 | * returns positive number if s1 > s2 11 | */ 12 | 13 | int _strcmp(char *s1, char *s2) 14 | { 15 | int i = 0, diff = 0; 16 | 17 | while (1) 18 | { 19 | if (s1[i] == '\0' && s2[i] == '\0') 20 | break; 21 | else if (s1[i] == '\0') 22 | { 23 | diff = s2[i]; 24 | break; 25 | } 26 | else if (s2[i] == '\0') 27 | { 28 | diff = s1[i]; 29 | break; 30 | } 31 | else if (s1[i] != s2[i]) 32 | { 33 | diff = s1[i] - s2[i]; 34 | break; 35 | } 36 | else 37 | i++; 38 | 39 | } 40 | return (diff); 41 | } 42 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strspn - search the number of bytes in the initial 4 | * segment of s which consist only of bytes from accept 5 | *@s:segment targeted 6 | *@accept:reference bytes container 7 | * 8 | *Return:returns the number of bytes in the initial 9 | * segment of s which consist only of bytes from accept 10 | */ 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int bytes = 0; 14 | int i; 15 | 16 | while (*s) 17 | { 18 | for (i = 0; accept[i]; i++) 19 | { 20 | if (accept[i] == *s) 21 | { 22 | bytes++; 23 | break; 24 | } 25 | else if ((accept[i + 1]) == '\0') 26 | return (bytes); 27 | } 28 | s++; 29 | } 30 | return (bytes); 31 | } 32 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strpbrk - The _strpbrk() function locates the first 4 | * occurrence in the string s of any of the bytes in 5 | *the string accept 6 | * 7 | *@s: string where search is made 8 | *@accept: string where searched bytes are located 9 | * 10 | *Return:Returns a pointer to the byte in s that matches 11 | * one of the bytes in accept, or NULL if no such byte is found 12 | */ 13 | 14 | char *_strpbrk(char *s, char *accept) 15 | { 16 | int i; 17 | 18 | while (*s) 19 | { 20 | for (i = 0; accept[i]; i++) 21 | { 22 | if (accept[i] == *s) 23 | return (s); 24 | } 25 | s++; 26 | } 27 | 28 | return ('\0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | /** 3 | *_strstr - The _strstr() function finds the first occurrence 4 | * of the substring needle in the string haystack. 5 | * The terminating null bytes (\0) are not compared 6 | *@haystack: string where the search is made 7 | *@needle: string whose occurence is searched in haystack 8 | *Return:Returns a pointer to the beginning of the located 9 | * substring, or NULL if the substring is not found. 10 | */ 11 | 12 | char *_strstr(char *haystack, char *needle) 13 | { 14 | int i; 15 | 16 | if (*needle == 0) 17 | return (haystack); 18 | 19 | while (*haystack) 20 | { 21 | i = 0; 22 | 23 | if (haystack[i] == needle[i]) 24 | { 25 | do { 26 | if (needle[i + 1] == '\0') 27 | return (haystack); 28 | i++; 29 | } while (haystack[i] == needle[i]); 30 | } 31 | haystack++; 32 | } 33 | return ('\0'); 34 | } 35 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/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/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/gm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/gm -------------------------------------------------------------------------------- /0x18-dynamic_libraries/lib101-makemewin.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/lib101-makemewin.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/libdynamic.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/libdynamic.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | 7 | int _putchar(char c); 8 | int _islower(int c); 9 | int _isalpha(int c); 10 | int _abs(int n); 11 | int _isupper(int c); 12 | int _isdigit(int c); 13 | int _strlen(char *s); 14 | void _puts(char *s); 15 | char *_strcpy(char *dest, char *src); 16 | int _atoi(char *s); 17 | char *_strcat(char *dest, char *src); 18 | char *_strncat(char *dest, char *src, int n); 19 | char *_strncpy(char *dest, char *src, int n); 20 | int _strcmp(char *s1, char *s2); 21 | char *_memset(char *s, char b, unsigned int n); 22 | char *_memcpy(char *dest, char *src, unsigned int n); 23 | char *_strchr(char *s, char c); 24 | unsigned int _strspn(char *s, char *accept); 25 | char *_strpbrk(char *s, char *accept); 26 | char *_strstr(char *haystack, char *needle); 27 | 28 | #endif /* MAIN_H */ 29 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tests/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("Holberton")); 12 | return (EXIT_SUCCESS); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tests/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/tests/gm/101-md5_gm: -------------------------------------------------------------------------------- 1 | d52e6c18e0723f5b025a75dea19ef365 gm 2 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/tests/gm/gm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/0x18-dynamic_libraries/tests/gm/gm -------------------------------------------------------------------------------- /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: The size of the array. 6 | * 7 | * Return: If an error occurs - NULL. 8 | * Otherwise - a pointer to the new hash table. 9 | */ 10 | hash_table_t *hash_table_create(unsigned long int size) 11 | { 12 | hash_table_t *ht; 13 | unsigned long int i; 14 | 15 | ht = malloc(sizeof(hash_table_t)); 16 | if (ht == NULL) 17 | return (NULL); 18 | 19 | ht->size = size; 20 | ht->array = malloc(sizeof(hash_node_t *) * size); 21 | if (ht->array == NULL) 22 | return (NULL); 23 | for (i = 0; i < size; i++) 24 | ht->array[i] = NULL; 25 | 26 | return (ht); 27 | } 28 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-djb2.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_djb2 - Hash function implementing the djb2 algorithm. 5 | * @str: The string to hash. 6 | * 7 | * Return: The calculated hash. 8 | */ 9 | unsigned long int hash_djb2(const unsigned char *str) 10 | { 11 | unsigned long int hash; 12 | int c; 13 | 14 | hash = 5381; 15 | while ((c = *str++)) 16 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 17 | 18 | return (hash); 19 | } 20 | -------------------------------------------------------------------------------- /0x1A-hash_tables/2-key_index.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * key_index - Get the index at which a key/value pair should 5 | * be stored in array of a hash table. 6 | * @key: The key to get the index of. 7 | * @size: The size of the array of the hash table. 8 | * 9 | * Return: The index of the key. 10 | * 11 | * Description: Uses the djb2 algorithm. 12 | */ 13 | unsigned long int key_index(const unsigned char *key, unsigned long int size) 14 | { 15 | return (hash_djb2(key) % size); 16 | } 17 | -------------------------------------------------------------------------------- /0x1A-hash_tables/4-hash_table_get.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_table_get - Retrieve the value associated with 5 | * a key in a hash table. 6 | * @ht: A pointer to the hash table. 7 | * @key: The key to get the value of. 8 | * 9 | * Return: If the key cannot be matched - NULL. 10 | * Otherwise - the value associated with key in ht. 11 | */ 12 | char *hash_table_get(const hash_table_t *ht, const char *key) 13 | { 14 | hash_node_t *node; 15 | unsigned long int index; 16 | 17 | if (ht == NULL || key == NULL || *key == '\0') 18 | return (NULL); 19 | 20 | index = key_index((const unsigned char *)key, ht->size); 21 | if (index >= ht->size) 22 | return (NULL); 23 | 24 | node = ht->array[index]; 25 | while (node && strcmp(node->key, key) != 0) 26 | node = node->next; 27 | 28 | return ((node == NULL) ? NULL : node->value); 29 | } 30 | -------------------------------------------------------------------------------- /0x1A-hash_tables/6-hash_table_delete.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_table_delete - Deletes a hash table. 5 | * @ht: A pointer to a hash table. 6 | */ 7 | void hash_table_delete(hash_table_t *ht) 8 | { 9 | hash_table_t *head = ht; 10 | hash_node_t *node, *tmp; 11 | unsigned long int i; 12 | 13 | for (i = 0; i < ht->size; i++) 14 | { 15 | if (ht->array[i] != NULL) 16 | { 17 | node = ht->array[i]; 18 | while (node != NULL) 19 | { 20 | tmp = node->next; 21 | free(node->key); 22 | free(node->value); 23 | free(node); 24 | node = tmp; 25 | } 26 | } 27 | } 28 | free(head->array); 29 | free(head); 30 | } 31 | -------------------------------------------------------------------------------- /0x1A-hash_tables/tests/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../hash_tables.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 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/tests/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../hash_tables.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | char *s; 14 | unsigned long int hash_table_array_size; 15 | 16 | hash_table_array_size = 1024; 17 | s = "cisfun"; 18 | printf("%lu\n", hash_djb2((unsigned char *)s)); 19 | printf("%lu\n", key_index((unsigned char *)s, hash_table_array_size)); 20 | s = "Don't forget to tweet today"; 21 | printf("%lu\n", hash_djb2((unsigned char *)s)); 22 | printf("%lu\n", key_index((unsigned char *)s, hash_table_array_size)); 23 | s = "98"; 24 | printf("%lu\n", hash_djb2((unsigned char *)s)); 25 | printf("%lu\n", key_index((unsigned char *)s, hash_table_array_size)); 26 | return (EXIT_SUCCESS); 27 | } 28 | -------------------------------------------------------------------------------- /0x1A-hash_tables/tests/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../hash_tables.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | hash_table_t *ht; 14 | 15 | ht = hash_table_create(1024); 16 | hash_table_set(ht, "betty", "holberton"); 17 | return (EXIT_SUCCESS); 18 | } 19 | -------------------------------------------------------------------------------- /0x1A-hash_tables/tests/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "../hash_tables.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | hash_table_t *ht; 14 | 15 | ht = hash_table_create(1024); 16 | hash_table_print(ht); 17 | hash_table_set(ht, "c", "fun"); 18 | hash_table_set(ht, "python", "awesome"); 19 | hash_table_set(ht, "Jennie", "and Jay love asm"); 20 | hash_table_set(ht, "N", "queens"); 21 | hash_table_set(ht, "Asterix", "Obelix"); 22 | hash_table_set(ht, "Betty", "Holberton"); 23 | hash_table_set(ht, "98", "Battery Street"); 24 | hash_table_print(ht); 25 | return (EXIT_SUCCESS); 26 | } 27 | -------------------------------------------------------------------------------- /0x1C-makefiles/0-Makefile: -------------------------------------------------------------------------------- 1 | all: main.c school.c 2 | gcc main.c school.c -o school 3 | -------------------------------------------------------------------------------- /0x1C-makefiles/1-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | 4 | all: $(SRC) 5 | $(CC) $(SRC) -o school 6 | -------------------------------------------------------------------------------- /0x1C-makefiles/100-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | CFLAGS = -Wall -Werror -Wextra -pedantic 6 | 7 | .PHONY: all clean oclean fclean re 8 | 9 | all: m.h $(OBJ) 10 | $(CC) $(OBJ) -o $(NAME) 11 | 12 | clean: 13 | $(RM) *~ $(NAME) 14 | 15 | oclean: 16 | $(RM) $(OBJ) 17 | 18 | fclean: clean oclean 19 | 20 | re: fclean all 21 | -------------------------------------------------------------------------------- /0x1C-makefiles/2-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | 6 | all: $(OBJ) 7 | $(CC) $(OBJ) -o $(NAME) 8 | -------------------------------------------------------------------------------- /0x1C-makefiles/3-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | RM = rm -f 6 | 7 | all: $(OBJ) 8 | $(CC) $(OBJ) -o $(NAME) 9 | 10 | clean: 11 | $(RM) *~ $(NAME) 12 | 13 | oclean: 14 | $(RM) $(OBJ) 15 | 16 | fclean: clean oclean 17 | 18 | re: fclean all 19 | -------------------------------------------------------------------------------- /0x1C-makefiles/4-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = main.c school.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = school 5 | RM = rm -f 6 | CFLAGS = -Wall -Werror -Wextra -pedantic 7 | 8 | all: $(OBJ) 9 | $(CC) $(CLFAGS) $(OBJ) -o $(NAME) 10 | 11 | clean: 12 | $(RM) *~ $(NAME) 13 | 14 | oclean: 15 | $(RM) $(OBJ) 16 | 17 | fclean: clean oclean 18 | 19 | re: fclean all 20 | -------------------------------------------------------------------------------- /0x1C-makefiles/5-island_perimeter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """Defines an island perimeter measuring function.""" 3 | 4 | 5 | def island_perimeter(grid): 6 | """Return the perimiter of an island. 7 | 8 | The grid represents water by 0 and land by 1. 9 | 10 | Args: 11 | grid (list): A list of list of integers representing an island. 12 | Returns: 13 | The perimeter of the island defined in grid. 14 | """ 15 | width = len(grid[0]) 16 | height = len(grid) 17 | edges = 0 18 | size = 0 19 | 20 | for i in range(height): 21 | for j in range(width): 22 | if grid[i][j] == 1: 23 | size += 1 24 | if (j > 0 and grid[i][j - 1] == 1): 25 | edges += 1 26 | if (i > 0 and grid[i - 1][j] == 1): 27 | edges += 1 28 | return size * 4 - edges * 2 29 | -------------------------------------------------------------------------------- /0x1C-makefiles/m.h: -------------------------------------------------------------------------------- 1 | #ifndef __M_H__ 2 | #define __M_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_school(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x1C-makefiles/main.c: -------------------------------------------------------------------------------- 1 | #include "m.h" 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 7 | */ 8 | int main(void) 9 | { 10 | print_school(); 11 | return (EXIT_SUCCESS); 12 | } 13 | -------------------------------------------------------------------------------- /0x1C-makefiles/tests/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 5-main 4 | """ 5 | island_perimeter = __import__('5-island_perimeter').island_perimeter 6 | 7 | if __name__ == "__main__": 8 | grid = [ 9 | [0, 0, 0, 0, 0, 0], 10 | [0, 1, 0, 0, 0, 0], 11 | [0, 1, 0, 0, 0, 0], 12 | [0, 1, 1, 1, 0, 0], 13 | [0, 0, 0, 0, 0, 0] 14 | ] 15 | print(island_perimeter(grid)) 16 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/0-linear.c: -------------------------------------------------------------------------------- 1 | #include "search_algos.h" 2 | 3 | /** 4 | * linear_search - Searches for a value in an array 5 | * of integers using linear search. 6 | * @array: A pointer to the first element of the array to search. 7 | * @size: The number of elements in the array. 8 | * @value: The value to search for. 9 | * 10 | * Return: If the value is not present or the array is NULL, -1. 11 | * Otherwise, the first index where the value is located. 12 | * 13 | * Description: Prints a value every time it is compared in the array. 14 | */ 15 | int linear_search(int *array, size_t size, int value) 16 | { 17 | size_t i; 18 | 19 | if (array == NULL) 20 | return (-1); 21 | 22 | for (i = 0; i < size; i++) 23 | { 24 | printf("Value checked array[%ld] = [%d]\n", i, array[i]); 25 | if (array[i] == value) 26 | return (i); 27 | } 28 | 29 | return (-1); 30 | } 31 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/listint/create_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../search_algos.h" 3 | 4 | void free_list(listint_t *list); 5 | 6 | /** 7 | * create_list - Creates a single linked list 8 | * 9 | * @array: Pointer to the array to use to fill the list 10 | * @size: Size of the array 11 | * 12 | * Return: A pointer to the head of the created list (NULL on failure) 13 | */ 14 | listint_t *create_list(int *array, size_t size) 15 | { 16 | listint_t *list; 17 | listint_t *node; 18 | 19 | list = NULL; 20 | while (array && size--) 21 | { 22 | node = malloc(sizeof(*node)); 23 | if (!node) 24 | { 25 | free_list(list); 26 | return (NULL); 27 | } 28 | node->n = array[size]; 29 | node->index = size; 30 | node->next = list; 31 | list = node; 32 | } 33 | return (list); 34 | } 35 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/listint/free_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../search_algos.h" 3 | 4 | /** 5 | * free_list - Deallocates a singly linked list 6 | * 7 | * @list: Pointer to the linked list to be freed 8 | */ 9 | void free_list(listint_t *list) 10 | { 11 | listint_t *node; 12 | 13 | if (list) 14 | { 15 | node = list->next; 16 | free(list); 17 | free_list(node); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/listint/print_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../search_algos.h" 3 | 4 | /** 5 | * print_list - Prints the content of a listint_t 6 | * 7 | * @list: Pointer to the head of the list 8 | */ 9 | void print_list(const listint_t *list) 10 | { 11 | printf("List :\n"); 12 | while (list) 13 | { 14 | printf("Index[%lu] = [%d]\n", list->index, list->n); 15 | list = list->next; 16 | } 17 | printf("\n"); 18 | } 19 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/skiplist/free_skiplist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "../search_algos.h" 3 | 4 | /** 5 | * free_skiplist - Deallocates a singly linked list 6 | * 7 | * @list: Pointer to the linked list to be freed 8 | */ 9 | void free_skiplist(skiplist_t *list) 10 | { 11 | skiplist_t *node; 12 | 13 | if (list) 14 | { 15 | node = list->next; 16 | free(list); 17 | free_skiplist(node); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/skiplist/print_skiplist.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * print_skiplist - dump the content of a skiplist_t 7 | * 8 | * @list: Pointer to the head of the list 9 | * 10 | * Return: void 11 | */ 12 | void print_skiplist(const skiplist_t *list) 13 | { 14 | const skiplist_t *node; 15 | 16 | printf("List :\n"); 17 | for (node = list; node; node = node->next) 18 | { 19 | printf("Index[%lu] = [%d]\n", node->index, node->n); 20 | } 21 | printf("\nExpress lane :\n"); 22 | for (node = list; node; node = node->express) 23 | { 24 | printf("Index[%lu] = [%d]\n", node->index, node->n); 25 | } 26 | printf("\n"); 27 | } 28 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 10, 1, 42, 3, 4, 42, 6, 7, -1, 9 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 3, linear_search(array, size, 3)); 18 | printf("Found %d at index: %d\n\n", 42, linear_search(array, size, 42)); 19 | printf("Found %d at index: %d\n", 999, linear_search(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 2, binary_search(array, size, 2)); 18 | printf("Found %d at index: %d\n\n", 5, binary_search(array, 5, 5)); 19 | printf("Found %d at index: %d\n", 999, binary_search(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/100-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 6, jump_search(array, size, 6)); 18 | printf("Found %d at index: %d\n\n", 1, jump_search(array, size, 1)); 19 | printf("Found %d at index: %d\n", 999, jump_search(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/102-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 0, 0, 1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 7, 8, 8, 8, 9, 9 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 3, interpolation_search(array, size, 3)); 18 | printf("Found %d at index: %d\n\n", 7, interpolation_search(array, size, 7)); 19 | printf("Found %d at index: %d\n", 999, interpolation_search(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/103-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 0, 1, 2, 3, 4, 7, 12, 15, 18, 19, 23, 54, 61, 62, 76, 99 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 62, exponential_search(array, size, 62)); 18 | printf("Found %d at index: %d\n\n", 3, exponential_search(array, size, 3)); 19 | printf("Found %d at index: %d\n", 999, exponential_search(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/tests/104-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "../search_algos.h" 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always EXIT_SUCCESS 9 | */ 10 | int main(void) 11 | { 12 | int array[] = { 13 | 0, 1, 2, 5, 5, 6, 6, 7, 8, 9 14 | }; 15 | size_t size = sizeof(array) / sizeof(array[0]); 16 | 17 | printf("Found %d at index: %d\n\n", 8, advanced_binary(array, size, 8)); 18 | printf("Found %d at index: %d\n\n", 5, advanced_binary(array, size, 5)); 19 | printf("Found %d at index: %d\n", 999, advanced_binary(array, size, 999)); 20 | return (EXIT_SUCCESS); 21 | } 22 | -------------------------------------------------------------------------------- /Betty-master/.travis.yml: -------------------------------------------------------------------------------- 1 | language: perl 2 | perl: 3 | - "5.26" 4 | - "5.24" 5 | - "5.22" 6 | - "5.20" 7 | - "5.18" 8 | - "5.16" 9 | install: true 10 | sudo: false 11 | script: bash test.sh 12 | branches: 13 | only: 14 | - master 15 | - v2 16 | -------------------------------------------------------------------------------- /Betty-master/betty.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Simply a wrapper script to keep you from having to use betty-style 3 | # and betty-doc separately on every item. 4 | # Originally by Tim Britton (@wintermanc3r), multiargument added by 5 | # Larry Madeo (@hillmonkey) 6 | 7 | BIN_PATH="/usr/local/bin" 8 | BETTY_STYLE="betty-style" 9 | BETTY_DOC="betty-doc" 10 | 11 | if [ "$#" = "0" ]; then 12 | echo "No arguments passed." 13 | exit 1 14 | fi 15 | 16 | for argument in "$@" ; do 17 | echo -e "\n========== $argument ==========" 18 | ${BIN_PATH}/${BETTY_STYLE} "$argument" 19 | ${BIN_PATH}/${BETTY_DOC} "$argument" 20 | done 21 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc0.c: -------------------------------------------------------------------------------- 1 | /** 2 | * op_add - Do a sum 3 | * @arg1: First operand 4 | * @arg2: Second operand 5 | * 6 | * Return: Sum of two operands 7 | */ 8 | int op_add(int arg1, int arg2) 9 | { 10 | return (arg1 + arg2); 11 | } 12 | 13 | /** 14 | * main - Program entry point 15 | * @ac: Number of arguments 16 | * @av: Arguments 17 | * 18 | * Return: 0 on success. Error code otherwise 19 | */ 20 | int main(int ac, char **av) 21 | { 22 | (void)ac; 23 | (void)av; 24 | op_add(1, 2); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc0.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc0.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc0.expected.stdout: -------------------------------------------------------------------------------- 1 | op_add 2 | main 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc1.c: -------------------------------------------------------------------------------- 1 | int op_add(int arg1, int arg2) 2 | { 3 | return (arg1 + arg2); 4 | } 5 | 6 | int main(int ac, char **av) 7 | { 8 | (void)ac; 9 | (void)av; 10 | op_add(1, 2); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc1.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc1.c:1: warning: no description found for function op_add 2 | tests/doc/doc1.c:6: warning: no description found for function main 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc1.expected.stdout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc1.expected.stdout -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc10.c: -------------------------------------------------------------------------------- 1 | /** 2 | * first - Called before main 3 | */ 4 | void __attribute__((constructor)) first(void) 5 | { 6 | printf("test\n"); 7 | } 8 | 9 | /** 10 | * first - Called before main 11 | */ 12 | void __attribute__ ((constructor)) first(void) 13 | { 14 | printf("test\n"); 15 | } 16 | 17 | /** 18 | * first - Called before main 19 | */ 20 | void __attribute__((constructor))first(void) 21 | { 22 | printf("test\n"); 23 | } 24 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc10.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc10.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc10.expected.stdout: -------------------------------------------------------------------------------- 1 | first 2 | first 3 | first 4 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc11.c: -------------------------------------------------------------------------------- 1 | binary_tree_t *binary_trees_ancestor(const binary_tree_t *, 2 | const binary_tree_t *); 3 | 4 | /** 5 | * sample - Sample 6 | * 7 | * @tmp1: tmp1 8 | * @tmp2: tmp2 9 | * 10 | * Return: Test 11 | */ 12 | binary_tree_t *sample(const binary_tree_t *tmp1, 13 | const binary_tree_t *tmp2) 14 | { 15 | return (NULL); 16 | } 17 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc11.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc11.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc11.expected.stdout: -------------------------------------------------------------------------------- 1 | sample 2 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc12.c: -------------------------------------------------------------------------------- 1 | /** 2 | * tester - return updated struct 3 | * @s: structure to get 4 | * 5 | * Return: s but with s.item multiplied by 2 6 | */ 7 | struct test tester(struct test s) 8 | { 9 | s.item *= 2; 10 | return (s); 11 | } 12 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc12.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc12.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc12.expected.stdout: -------------------------------------------------------------------------------- 1 | tester 2 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc13.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc13.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc13.expected.stdout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc13.expected.stdout -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc14.c: -------------------------------------------------------------------------------- 1 | /** 2 | * constructor - Test function 3 | * 4 | * @path: Hello 5 | * @test: World 6 | * 7 | * Return: 0 8 | */ 9 | int constructor(char **path, int test) 10 | { 11 | return (0); 12 | } 13 | 14 | /** 15 | * constructor - Test function 16 | * 17 | * @path: Hello 18 | * @test: World 19 | * 20 | * Return: 0 21 | */ 22 | int *constructor(char **path, int test) 23 | { 24 | return ((int *)0); 25 | } 26 | 27 | /** 28 | * ructor - Test function 29 | * 30 | * @path: Hello 31 | * @test: World 32 | * 33 | * Return: 0 34 | */ 35 | int constructor(char **path, int test) 36 | { 37 | return (0); 38 | } 39 | 40 | /** 41 | * ructor - Test function 42 | * 43 | * @path: Hello 44 | * @test: World 45 | * 46 | * Return: 0 47 | */ 48 | int *constructor(char **path, int test) 49 | { 50 | return ((int *)0); 51 | } -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc14.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc14.c:35: warning: no description found for function constructor 2 | tests/doc/doc14.c:48: warning: no description found for function constructor 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc14.expected.stdout: -------------------------------------------------------------------------------- 1 | constructor 2 | constructor 3 | constructor 4 | constructor 5 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc2.c: -------------------------------------------------------------------------------- 1 | /** 2 | * op_add - Do a sum 3 | * @arg1: First operand 4 | * 5 | * Return: Sum of two operands 6 | */ 7 | int op_add(int arg1, int arg2) 8 | { 9 | return (arg1 + arg2); 10 | } 11 | 12 | /** 13 | * main - Program entry point 14 | * @av: Arguments 15 | * 16 | * Return: 0 on success. Error code otherwise 17 | */ 18 | int main(int ac, char **av) 19 | { 20 | (void)ac; 21 | (void)av; 22 | op_add(1, 2); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc2.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc2.c:7: warning: No description found for parameter or member 'arg2' 2 | tests/doc/doc2.c:18: warning: No description found for parameter or member 'ac' 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc2.expected.stdout: -------------------------------------------------------------------------------- 1 | op_add 2 | main 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc3.c: -------------------------------------------------------------------------------- 1 | /** 2 | * op_add - 3 | * @arg1: First operand 4 | * @arg2: Second operand 5 | * 6 | * Return: Sum of two operands 7 | */ 8 | int op_add(int arg1, int arg2) 9 | { 10 | return (arg1 + arg2); 11 | } 12 | 13 | /** 14 | * main - Program entry point 15 | * @ac: Number of arguments 16 | * @av: Arguments 17 | */ 18 | int main(int ac, char **av) 19 | { 20 | (void)ac; 21 | (void)av; 22 | op_add(1, 2); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc3.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc3.c:2: warning: missing initial short description 2 | tests/doc/doc3.c:18: warning: No description found for return value of 'main' 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc3.expected.stdout: -------------------------------------------------------------------------------- 1 | op_add 2 | main 3 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc4.c: -------------------------------------------------------------------------------- 1 | /** 2 | * print_chessboard - Prints a board 3 | * 4 | * @a: The board to be printed 5 | * 6 | * Return: 0 7 | */ 8 | int print_chessboard(char (*a)[8]) 9 | { 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc4.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc4.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc4.expected.stdout: -------------------------------------------------------------------------------- 1 | print_chessboard 2 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc5.c: -------------------------------------------------------------------------------- 1 | /** 2 | * alloc_grid - Aloocates a grid 3 | * 4 | * @width: Width 5 | * @height: Height 6 | * 7 | * Return: The allocated grid 8 | */ 9 | int **alloc_grid(int width, int height) 10 | { 11 | return ((void *)0); 12 | } 13 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc5.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc5.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc5.expected.stdout: -------------------------------------------------------------------------------- 1 | alloc_grid 2 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc6.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc6.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc6.expected.stdout: -------------------------------------------------------------------------------- 1 | struct dog 2 | test 3 | struct color 4 | struct animal 5 | test2 6 | struct color2 7 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc7.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc7.h:14: warning: No description found for parameter or member 'owner' 2 | tests/doc/doc7.h:28: warning: Enum value 'FIRST' not described in enum 'test' 3 | tests/doc/doc7.h:38: warning: No description found for parameter or member 'rgba' 4 | tests/doc/doc7.h:51: warning: No description found for parameter or member 'race' 5 | tests/doc/doc7.h:65: warning: Enum value 'SECOND' not described in enum 'test2' 6 | tests/doc/doc7.h:75: warning: No description found for parameter or member 'value' 7 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc7.expected.stdout: -------------------------------------------------------------------------------- 1 | struct dog 2 | test 3 | struct color 4 | struct animal 5 | test2 6 | struct color2 7 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc8.expected.stderr: -------------------------------------------------------------------------------- 1 | tests/doc/doc8.h:11: warning: no description found for struct dog 2 | tests/doc/doc8.h:25: warning: no description found for enum test 3 | tests/doc/doc8.h:38: warning: no description found for union color 4 | tests/doc/doc8.h:51: warning: no description found for struct animal 5 | tests/doc/doc8.h:65: warning: no description found for enum test2 6 | tests/doc/doc8.h:78: warning: no description found for union color2 7 | -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc8.expected.stdout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc8.expected.stdout -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc9.expected.stderr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/doc/doc9.expected.stderr -------------------------------------------------------------------------------- /Betty-master/tests/doc/doc9.expected.stdout: -------------------------------------------------------------------------------- 1 | get_op_func 2 | get_op_func 3 | get_valid_type 4 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces0.c: -------------------------------------------------------------------------------- 1 | int func0(void) { 2 | if (1) { 3 | func0(); 4 | return (1); 5 | } 6 | else if (2) { 7 | func0(); 8 | return (2); 9 | } 10 | else { 11 | func0(); 12 | return (0); 13 | } 14 | while (1) { 15 | func0(); 16 | return (1); 17 | } 18 | for (; 1;) { 19 | func0(); 20 | return (1); 21 | } 22 | do 23 | { 24 | func0(); 25 | return (1); 26 | } while (1); 27 | } 28 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces0.expected: -------------------------------------------------------------------------------- 1 | tests/style/braces/braces0.c:1: ERROR: open brace '{' following function declarations go on the next line 2 | tests/style/braces/braces0.c:2: ERROR: that open brace { should be on the next line 3 | tests/style/braces/braces0.c:6: ERROR: that open brace { should be on the next line 4 | tests/style/braces/braces0.c:10: ERROR: that open brace { should be on the next line 5 | tests/style/braces/braces0.c:14: ERROR: that open brace { should be on the next line 6 | tests/style/braces/braces0.c:18: ERROR: that open brace { should be on the next line 7 | tests/style/braces/braces0.c:23: ERROR: that open brace { should be on the previous line 8 | total: 7 errors, 0 warnings, 27 lines checked 9 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces1.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | if (1) 4 | { 5 | func0(); 6 | return (1); 7 | } 8 | else if (2) 9 | { 10 | func0(); 11 | return (2); 12 | } 13 | else 14 | { 15 | func0(); 16 | return (0); 17 | } 18 | while (1) 19 | { 20 | func0(); 21 | return (1); 22 | } 23 | for (; 1;) 24 | { 25 | func0(); 26 | return (1); 27 | } 28 | do { 29 | func0(); 30 | return (1); 31 | } while (1); 32 | } 33 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces1.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/braces/braces1.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces2.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | if (1) 4 | return (1); 5 | else if (2) 6 | return (2); 7 | else 8 | return (0); 9 | while (1) 10 | return (1); 11 | for (; 1;) 12 | return (1); 13 | } 14 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces2.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/braces/braces2.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces3.c: -------------------------------------------------------------------------------- 1 | int randompart(int total, int count, char *s, char *code, int *index) 2 | { 3 | return (0); 4 | } 5 | 6 | dog_t *new_dog(char *name, float age, char *owner) 7 | { 8 | dog_t *new_dog; 9 | 10 | new_dog = malloc(sizeof(dog_t)); 11 | if (new_dog == NULL) 12 | { 13 | return (NULL); 14 | } 15 | new_dog->name = strdup(name); 16 | new_dog->age = age; 17 | new_dog->owner = strdup(owner); 18 | return (new_dog); 19 | } 20 | -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces3.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/braces/braces3.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces4.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/braces/braces4.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/braces/braces4.h: -------------------------------------------------------------------------------- 1 | #ifndef _DOG_ 2 | #define _DOG_ 3 | 4 | struct dog 5 | { 6 | char *name; 7 | float age; 8 | char *owner; 9 | }; 10 | 11 | void init_dog(struct dog *d, char *name, float age, char *owner); 12 | void print_dog(struct dog *d); 13 | 14 | #endif 15 | -------------------------------------------------------------------------------- /Betty-master/tests/style/comments/comments0.c: -------------------------------------------------------------------------------- 1 | /* This comment is OK */ 2 | 3 | // This comment should not be used 4 | 5 | /* 6 | * This is the preferred style for multi-line 7 | * comments in the Linux kernel source code. 8 | * Please use it consistently. 9 | * 10 | * Description: A column of asterisks on the left side, 11 | * with beginning and ending almost-blank lines. 12 | */ 13 | 14 | /* Bad 15 | * multi-line 16 | * comment */ 17 | 18 | /** Also 19 | very bad 20 | comment*/ 21 | -------------------------------------------------------------------------------- /Betty-master/tests/style/comments/comments0.expected: -------------------------------------------------------------------------------- 1 | tests/style/comments/comments0.c:3: ERROR: do not use C99 // comments 2 | tests/style/comments/comments0.c:14: WARNING: Block comments use a leading /* on a separate line 3 | tests/style/comments/comments0.c:16: WARNING: Block comments use a trailing */ on a separate line 4 | tests/style/comments/comments0.c:18: WARNING: Block comments use a leading /* on a separate line 5 | tests/style/comments/comments0.c:19: WARNING: Block comments use * on subsequent lines 6 | tests/style/comments/comments0.c:20: WARNING: Block comments use a trailing */ on a separate line 7 | total: 1 errors, 5 warnings, 20 lines checked 8 | -------------------------------------------------------------------------------- /Betty-master/tests/style/comments/comments1.c: -------------------------------------------------------------------------------- 1 | int main(void) 2 | { 3 | int a; 4 | 5 | a = 0; /* Valid comment */ 6 | return (a); 7 | } 8 | -------------------------------------------------------------------------------- /Betty-master/tests/style/comments/comments1.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/comments/comments1.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions0.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | return (1); 4 | } 5 | 6 | int func1(void) 7 | { 8 | return (1); 9 | } 10 | 11 | int func2(void) 12 | { 13 | return (1); 14 | } 15 | 16 | int func3(void) 17 | { 18 | return (1); 19 | } 20 | 21 | int func4(void) 22 | { 23 | return (1); 24 | } 25 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions0.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/functions/functions0.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions1.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | return (1); 4 | } 5 | 6 | int func1(void) 7 | { 8 | return (1); 9 | } 10 | 11 | int func2(void) 12 | { 13 | return (1); 14 | } 15 | 16 | int func3(void) 17 | { 18 | return (1); 19 | } 20 | 21 | int func4(void) 22 | { 23 | return (1); 24 | } 25 | 26 | int func5(void) 27 | { 28 | return (1); 29 | } 30 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions1.expected: -------------------------------------------------------------------------------- 1 | tests/style/functions/functions1.c:26: ERROR: More than 5 functions in the file 2 | total: 1 errors, 0 warnings, 29 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions2.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | while (1) 4 | { 5 | while (1) 6 | { 7 | while (1) 8 | { 9 | while (1) 10 | { 11 | while (1) 12 | { 13 | return (1); 14 | } 15 | } 16 | } 17 | } 18 | } 19 | } 20 | 21 | int func1(void) 22 | { 23 | for (; 1;) 24 | { 25 | for (; 1;) 26 | { 27 | for (; 1;) 28 | { 29 | for (; 1;) 30 | { 31 | for (; 1;) 32 | { 33 | return (1); 34 | } 35 | } 36 | } 37 | } 38 | } 39 | } 40 | 41 | int func2(void) 42 | { 43 | { 44 | { 45 | { 46 | { 47 | { 48 | return (1); 49 | } 50 | } 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions2.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/functions/functions2.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions3.c: -------------------------------------------------------------------------------- 1 | int test[] = { 2 | 0, 1 3 | }; 4 | 5 | int func0(void) 6 | { 7 | return (1); 8 | } 9 | 10 | int func1(void) 11 | { 12 | return (1); 13 | } 14 | 15 | int func2(void) 16 | { 17 | return (1); 18 | } 19 | 20 | int func3(void) 21 | { 22 | return (1); 23 | } 24 | 25 | int func4(void) 26 | { 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions3.expected: -------------------------------------------------------------------------------- 1 | tests/style/functions/functions3.c:1: ERROR: global variables are not allowed 2 | total: 1 errors, 0 warnings, 28 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions4.expected: -------------------------------------------------------------------------------- 1 | tests/style/functions/functions4.c:87: WARNING: More than 40 lines in a function 2 | total: 0 errors, 1 warnings, 88 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions5.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/functions/functions5.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/functions/functions6.expected: -------------------------------------------------------------------------------- 1 | tests/style/functions/functions6.c:43: WARNING: More than 40 lines in a function 2 | tests/style/functions/functions6.c:44: WARNING: More than 40 lines in a function 3 | tests/style/functions/functions6.c:45: WARNING: More than 40 lines in a function 4 | tests/style/functions/functions6.c:46: WARNING: More than 40 lines in a function 5 | tests/style/functions/functions6.c:47: WARNING: More than 40 lines in a function 6 | tests/style/functions/functions6.c:48: WARNING: More than 40 lines in a function 7 | tests/style/functions/functions6.c:49: WARNING: More than 40 lines in a function 8 | tests/style/functions/functions6.c:50: WARNING: More than 40 lines in a function 9 | total: 0 errors, 8 warnings, 51 lines checked 10 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers0.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/headers/headers0.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers0.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERS0_H_ 2 | #define _HEADERS0_H_ 3 | 4 | #define SAMPLE 98 5 | #define SAMPLE1 (98 + 402) 6 | 7 | struct sample_s 8 | { 9 | char *str; 10 | int i; 11 | }; 12 | 13 | union sample_u 14 | { 15 | char rgba[4]; 16 | int value; 17 | }; 18 | 19 | enum sample_e 20 | { 21 | FIRST = 0, 22 | SECOND, 23 | THIRD 24 | }; 25 | 26 | /* ----- */ 27 | 28 | typedef struct sample_s sample_s; 29 | typedef union sample_u sample_u; 30 | typedef enum sample_e sample_e; 31 | 32 | /* ----- */ 33 | 34 | typedef struct sample1_s 35 | { 36 | char *str; 37 | int i; 38 | } sample1_s; 39 | 40 | typedef union sample1_u 41 | { 42 | char rgba[4]; 43 | int value; 44 | } sample1_u; 45 | 46 | typedef enum sample1_e 47 | { 48 | FIRST = 0, 49 | SECOND, 50 | THIRD 51 | } sample1_e; 52 | 53 | #endif /* _HEADERS0_H_ */ 54 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers1.expected: -------------------------------------------------------------------------------- 1 | tests/style/headers/headers1.h:5: ERROR: Macros with complex values should be enclosed in parentheses 2 | tests/style/headers/headers1.h:7: ERROR: open brace '{' following struct go on the next line 3 | tests/style/headers/headers1.h:12: ERROR: open brace '{' following union go on the next line 4 | tests/style/headers/headers1.h:17: ERROR: open brace '{' following enum go on the next line 5 | tests/style/headers/headers1.h:31: ERROR: open brace '{' following struct go on the next line 6 | tests/style/headers/headers1.h:36: ERROR: open brace '{' following union go on the next line 7 | tests/style/headers/headers1.h:41: ERROR: open brace '{' following enum go on the next line 8 | total: 7 errors, 0 warnings, 47 lines checked 9 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers1.h: -------------------------------------------------------------------------------- 1 | #ifndef _HEADERS1_H_ 2 | #define _HEADERS1_H_ 3 | 4 | #define sample 98 5 | #define sample1 98 + 402 6 | 7 | struct sample_s { 8 | char *str; 9 | int i; 10 | }; 11 | 12 | union sample_u { 13 | char rgba[4]; 14 | int value; 15 | }; 16 | 17 | enum sample_e { 18 | first = 0, 19 | second, 20 | third 21 | }; 22 | 23 | /* ----- */ 24 | 25 | typedef struct sample_s sample_s; 26 | typedef union sample_u sample_u; 27 | typedef enum sample_e sample_e; 28 | 29 | /* ----- */ 30 | 31 | typedef struct sample1_s { 32 | char *str; 33 | int i; 34 | } sample1_s; 35 | 36 | typedef union sample1_u { 37 | char rgba[4]; 38 | int value; 39 | } sample1_u; 40 | 41 | typedef enum sample1_e { 42 | first = 0, 43 | second, 44 | third 45 | } sample1_e; 46 | 47 | #endif /* _HEADERS1_H_ */ 48 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers2.c: -------------------------------------------------------------------------------- 1 | typedef unsigned int sample; 2 | 3 | struct sample_s 4 | { 5 | int data; 6 | }; 7 | 8 | enum sample_e 9 | { 10 | FIRST = 0, 11 | SECOND 12 | }; 13 | 14 | union sample_u 15 | { 16 | char rgba[4]; 17 | int value; 18 | }; 19 | 20 | int main(void) 21 | { 22 | struct dog my_dog; 23 | 24 | my_dog.name = "Django"; 25 | my_dog.age = 3.5; 26 | my_dog.owner = "Jay"; 27 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers2.expected: -------------------------------------------------------------------------------- 1 | tests/style/headers/headers2.c:1: WARNING: typedefs should be avoided in .c files 2 | tests/style/headers/headers2.c:3: WARNING: struct definition should be avoided in .c files 3 | tests/style/headers/headers2.c:8: WARNING: enum definition should be avoided in .c files 4 | tests/style/headers/headers2.c:14: WARNING: union definition should be avoided in .c files 5 | total: 0 errors, 4 warnings, 29 lines checked 6 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers3.h: -------------------------------------------------------------------------------- 1 | #ifndef _PROTECTION_H_ 2 | #define TEST 5 3 | 4 | struct sample_s 5 | { 6 | char *str; 7 | int i; 8 | }; 9 | 10 | #endif 11 | #ifndef _TEST_H_ 12 | #define _TEST_H_ 13 | union sample_u 14 | { 15 | char rgba[4]; 16 | int value; 17 | }; 18 | 19 | enum sample_e 20 | { 21 | FIRST = 0, 22 | SECOND, 23 | THIRD 24 | }; 25 | #endif 26 | /* ----- */ 27 | 28 | typedef struct sample_s sample_s; 29 | typedef union sample_u sample_u; 30 | typedef enum sample_e sample_e; 31 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers4.c: -------------------------------------------------------------------------------- 1 | int func0(void); 2 | char *_strchr(char *, char); 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/headers/headers4.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/headers/headers4.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/indentation/indentation0.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | return (0); 4 | } 5 | 6 | int func1(void) 7 | { 8 | return (0); 9 | } 10 | -------------------------------------------------------------------------------- /Betty-master/tests/style/indentation/indentation0.expected: -------------------------------------------------------------------------------- 1 | tests/style/indentation/indentation0.c:3: WARNING: please, no spaces at the start of a line 2 | total: 0 errors, 1 warnings, 9 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break0.c: -------------------------------------------------------------------------------- 1 | int func0(char very_very_very_very_very_long_variable_name_just_to_test_length) 2 | { 3 | return (1); 4 | } 5 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break0.expected: -------------------------------------------------------------------------------- 1 | tests/style/line_break/line_break0.c:3: WARNING: line over 80 characters (81) 2 | total: 0 errors, 1 warnings, 4 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break1.c: -------------------------------------------------------------------------------- 1 | int func0(void) 2 | { 3 | return (1); 4 | } 5 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break1.expected: -------------------------------------------------------------------------------- 1 | tests/style/line_break/line_break1.c:3: ERROR: trailing whitespace 2 | total: 1 errors, 0 warnings, 4 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | printf("hello"); /* a = 11 | 12; return a; */ 12 | printf("hello"); /* a = 12; return a;*/ 13 | printf("hello"); a = 12; return a; 14 | } 15 | 16 | int func(void) 17 | { 18 | int i = 0; 19 | 20 | if (i != 3) 21 | { 22 | _putchar('E'); _putchar('r'); _putchar('r'); _putchar('o'); 23 | _putchar('r'); _putchar('\n'); exit(98); 24 | } 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break2.expected: -------------------------------------------------------------------------------- 1 | tests/style/line_break/line_break2.c:11: WARNING: Block comments use * on subsequent lines 2 | tests/style/line_break/line_break2.c:11: WARNING: Block comments use a trailing */ on a separate line 3 | tests/style/line_break/line_break2.c:13: WARNING: Multiple instructions on a single line is forbidden 4 | tests/style/line_break/line_break2.c:22: WARNING: Multiple instructions on a single line is forbidden 5 | tests/style/line_break/line_break2.c:23: WARNING: Multiple instructions on a single line is forbidden 6 | total: 0 errors, 5 warnings, 27 lines checked 7 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break3.c: -------------------------------------------------------------------------------- 1 | int (*get_op_func(char *s))(int, int) 2 | { 3 | char key[] = {'+', '-', '*', '/', '%'}; 4 | int i = 0; 5 | int (*f[])(int, int) = {op_add, op_sub, op_mul, op_div, op_mod}; 6 | 7 | while (i < 5) 8 | { 9 | return (0); 10 | } 11 | return (0); 12 | } 13 | 14 | int (*get_op_func(char *s))(int, int) 15 | { 16 | char key[] = {'+', '-', '*', '/', '%'}; 17 | int i = 0; 18 | int (*f[5])(int, int); 19 | 20 | while (i < 5) 21 | { 22 | return (0); 23 | } 24 | return (0); 25 | } 26 | 27 | int (*get_op_func(char *s))(int, int) 28 | { 29 | char key[] = {'+', '-', '*', '/', '%'}; 30 | int i = 0; 31 | int (*f[5])(int, int) = {op_add, op_sub, op_mul, op_div, op_mod}; 32 | 33 | while (i < 5) 34 | { 35 | return (0); 36 | } 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break3.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/line_break/line_break3.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break4.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | char const *str = "Hello;World;!"; 6 | char *s; 7 | 8 | s = _strtok(str, ";", NULL); 9 | 10 | return (EXIT_SUCCESS); 11 | } 12 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break4.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/line_break/line_break4.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break5.c: -------------------------------------------------------------------------------- 1 | EC_KEY *ec_from_pub(uint8_t const pub[EC_PUB_LEN]) 2 | { 3 | EC_KEY *key = NULL; 4 | EC_POINT *point = NULL; 5 | EC_GROUP const *group = NULL; 6 | int test_int = 0; 7 | 8 | return (key); 9 | } 10 | -------------------------------------------------------------------------------- /Betty-master/tests/style/line_break/line_break5.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/line_break/line_break5.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces0.c: -------------------------------------------------------------------------------- 1 | int func0(int var) 2 | { 3 | if (1) 4 | return (1); 5 | else if (1) 6 | return (1); 7 | switch (var) 8 | { 9 | case 0: 10 | default: 11 | break; 12 | } 13 | for (; 1;) 14 | return (1); 15 | while (1) 16 | return (1); 17 | do { 18 | return (1); 19 | } while (1); 20 | } 21 | 22 | int func1(int var, __attribute__((unused))int test) 23 | { 24 | int t; 25 | 26 | t = sizeof(var); 27 | return (t); 28 | } 29 | -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces0.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/spaces/spaces0.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces1.c: -------------------------------------------------------------------------------- 1 | int func0 ( int var ) 2 | { 3 | if( 1 ) 4 | return( 1 ) ; 5 | else if( 1 ) 6 | return( 1 ) ; 7 | switch(var) 8 | { 9 | case 0 : 10 | default : 11 | break ; 12 | } 13 | for( ;1; ) 14 | return( 1 ) ; 15 | while( 1 ) 16 | return( 1 ) ; 17 | do{ 18 | return( 1 ) ; 19 | }while( 1 ) ; 20 | } 21 | 22 | int func1 ( int var ,__attribute__ ((unused)) int test ) 23 | { 24 | int t ; 25 | 26 | t=sizeof ( var ) ; 27 | return( t ) ; 28 | } 29 | -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces2.c: -------------------------------------------------------------------------------- 1 | char *func0(char *var) 2 | { 3 | char *str; 4 | Struct_s *ptr; 5 | 6 | str = var; 7 | str = ptr->str; 8 | return (str); 9 | } 10 | 11 | char* func2(char* var) 12 | { 13 | char* str; 14 | Struct_s* ptr; 15 | 16 | str = var; 17 | str = ptr-> str; 18 | str = ptr ->str; 19 | str = ptr -> str; 20 | return (str); 21 | } 22 | -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces2.expected: -------------------------------------------------------------------------------- 1 | tests/style/spaces/spaces2.c:11: ERROR: "foo* bar" should be "foo *bar" 2 | tests/style/spaces/spaces2.c:11: ERROR: "foo* bar" should be "foo *bar" 3 | tests/style/spaces/spaces2.c:13: ERROR: "foo* bar" should be "foo *bar" 4 | tests/style/spaces/spaces2.c:14: ERROR: "foo* bar" should be "foo *bar" 5 | tests/style/spaces/spaces2.c:17: ERROR: spaces prohibited around that '->' (ctx:VxW) 6 | tests/style/spaces/spaces2.c:18: ERROR: spaces prohibited around that '->' (ctx:WxV) 7 | tests/style/spaces/spaces2.c:19: ERROR: spaces prohibited around that '->' (ctx:WxW) 8 | total: 7 errors, 0 warnings, 21 lines checked 9 | -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces4.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/spaces/spaces4.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces5.c: -------------------------------------------------------------------------------- 1 | void func0(int var1, int var2) 2 | { 3 | int *addr; 4 | 5 | addr = &var1; 6 | var2 = *addr; 7 | var1 = +var2; 8 | var1 = -var2; 9 | var1 = ~var2; 10 | var1 = !var2; 11 | } 12 | 13 | void func1(int var1) 14 | { 15 | var1++; 16 | var1--; 17 | ++var1; 18 | --var1; 19 | } 20 | -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces5.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/spaces/spaces5.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/spaces/spaces6.c: -------------------------------------------------------------------------------- 1 | void func0(int var1, int var2) 2 | { 3 | int *addr; 4 | 5 | addr = & var1; 6 | var2 = * addr; 7 | var1 = + var2; 8 | var1 = - var2; 9 | var1 = ~ var2; 10 | var1 = ! var2; 11 | } 12 | 13 | void func1(int var1) 14 | { 15 | var1 ++; 16 | var1 --; 17 | ++ var1; 18 | -- var1; 19 | } 20 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables0.c: -------------------------------------------------------------------------------- 1 | int i; 2 | int global_var; 3 | int indented_global = 98; 4 | unsigned int another = 12; 5 | void (*global_func_ptr)(int, int); 6 | 7 | int test_func(int some_var, 8 | int (*func)(int), 9 | test_t *some_other) 10 | { 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables0.expected: -------------------------------------------------------------------------------- 1 | tests/style/variables/variables0.c:1: ERROR: global variables are not allowed 2 | tests/style/variables/variables0.c:2: ERROR: global variables are not allowed 3 | tests/style/variables/variables0.c:3: ERROR: global variables are not allowed 4 | tests/style/variables/variables0.c:4: ERROR: global variables are not allowed 5 | tests/style/variables/variables0.c:5: ERROR: global variables are not allowed 6 | total: 5 errors, 0 warnings, 12 lines checked 7 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int test; 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | int main(void) 11 | { 12 | int i; 13 | int j; 14 | int arr = {1, 2, 3}; 15 | int k; 16 | 17 | putchar('\n'); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables1.expected: -------------------------------------------------------------------------------- 1 | tests/style/variables/variables1.c:3: ERROR: global variables are not allowed 2 | total: 1 errors, 0 warnings, 19 lines checked 3 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables2.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Fixed: token_t *token was detected as a global variable 3 | */ 4 | 5 | static const char *process_token(command_chain_t *chain, command_t **cmd, 6 | token_t *token, const char *start) 7 | { 8 | return (NULL); 9 | } 10 | 11 | static command_t **alias_expand_command(shell_t *shell, 12 | command_t *command, char *used) 13 | { 14 | return (NULL); 15 | } 16 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables2.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/variables/variables2.expected -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables3.c: -------------------------------------------------------------------------------- 1 | struct test1_s *_getline(const int fd, 2 | struct test_s *test, 3 | enum test_e test2) 4 | { 5 | return (test); 6 | } 7 | 8 | typedef unsigned int sample; 9 | 10 | struct sample_s 11 | { 12 | int data; 13 | }; 14 | 15 | enum sample_e 16 | { 17 | FIRST = 0, 18 | SECOND 19 | }; 20 | 21 | union sample_u 22 | { 23 | char rgba[4]; 24 | int value; 25 | }; 26 | 27 | int main(void) 28 | { 29 | struct dog my_dog; 30 | 31 | my_dog.name = "Django"; 32 | my_dog.age = 3.5; 33 | my_dog.owner = "Jay"; 34 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables3.expected: -------------------------------------------------------------------------------- 1 | tests/style/variables/variables3.c:8: WARNING: typedefs should be avoided in .c files 2 | tests/style/variables/variables3.c:10: WARNING: struct definition should be avoided in .c files 3 | tests/style/variables/variables3.c:15: WARNING: enum definition should be avoided in .c files 4 | tests/style/variables/variables3.c:21: WARNING: union definition should be avoided in .c files 5 | total: 0 errors, 4 warnings, 36 lines checked 6 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables4.c: -------------------------------------------------------------------------------- 1 | static const char *test( 2 | test_chain_t (*chain)(int), 3 | test_t **cmd, 4 | token_t *token, 5 | const char *start) 6 | { 7 | return (start); 8 | } 9 | -------------------------------------------------------------------------------- /Betty-master/tests/style/variables/variables4.expected: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/underscoDe/alx-low_level_programming/95e1e9d67bd9824cb36b3da4998a5e244fa87139/Betty-master/tests/style/variables/variables4.expected --------------------------------------------------------------------------------