├── 0x00-hello_world ├── 0-preprocessor ├── 1-compiler ├── 100-intel ├── 101-quote.c ├── 2-assembler ├── 3-name ├── 4-puts.c ├── 5-printf.c ├── 6-size.c ├── README.md └── mains │ ├── main.c │ └── main.s ├── 0x01-variables_if_else_while ├── 0-positive_or_negative.c ├── 1-last_digit.c ├── 10-print_comb2.c ├── 100-print_comb3.c ├── 101-print_comb4.c ├── 102-print_comb5.c ├── 2-print_alphabet.c ├── 3-print_alphabets.c ├── 4-print_alphabt.c ├── 5-print_numbers.c ├── 6-print_numberz.c ├── 7-print_tebahpla.c ├── 8-print_base16.c ├── 9-print_comb.c └── README.md ├── 0x02-functions_nested_loops ├── 0-holberton.c ├── 1-alphabet.c ├── 10-add.c ├── 100-times_table.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 ├── _putchar.c ├── holberton.h └── mains │ ├── 1-main.c │ ├── 10-main.c │ ├── 100-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ ├── 7-main.c │ ├── 8-main.c │ ├── 9-main.c │ ├── holberton.h │ └── main.c ├── 0x03-debugging ├── 1-main.c ├── 2-largest_number.c ├── 3-convert_day.c ├── 3-print_remaining_days.c ├── README.md ├── holberton.h └── mains │ ├── 0-main.c │ ├── 2-main.c │ └── 3-main_a.c ├── 0x04-more_functions_nested_loops ├── 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 ├── _putchar.c ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 101-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ ├── 7-main.c │ ├── 8-main.c │ └── holberton.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 ├── _putchar.c ├── holberton.h └── mains │ ├── 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 │ └── 9-main.c ├── 0x06-pointers_arrays_strings ├── 0-strcat.c ├── 1-strncat.c ├── 101-magic.c ├── 2-strncpy.c ├── 3-strcmp.c ├── 4-rev_array.c ├── 5-string_toupper.c ├── 6-cap_string.c ├── 7-leet.c ├── 8-rot13.c ├── README.md ├── _putchar.c ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 100-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ ├── 7-main.c │ └── 8-main.c ├── 0x07-pointers_arrays_strings ├── 0-memset.c ├── 1-memcpy.c ├── 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 ├── _putchar.c ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 7-main.c │ ├── 8-main.c │ └── 9-main.c ├── 0x08-recursion ├── 0-puts_recursion.c ├── 1-print_rev_recursion.c ├── 2-strlen_recursion.c ├── 3-factorial.c ├── 4-pow_recursion.c ├── 5-sqrt ├── 5-sqrt_recursion.c ├── 6-is_prime_number.c ├── 7-is_palindrome.c ├── 7-palindrome ├── README.md ├── _putchar.c ├── holberton.h └── mains │ ├── 0-main.c │ ├── 2-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ └── 7-main.c ├── 0x09-static_libraries ├── README.md ├── _putchar.c ├── create_static_lib.sh ├── files_c │ ├── 0-isupper.c │ ├── 0-memset.c │ ├── 0-strcat.c │ ├── 1-isdigit.c │ ├── 1-memcpy.c │ ├── 1-strncat.c │ ├── 100-atoi.c │ ├── 2-args.c │ ├── 2-strchr.c │ ├── 2-strlen.c │ ├── 2-strncpy.c │ ├── 3-islower.c │ ├── 3-puts.c │ ├── 3-strcmp.c │ ├── 3-strspn.c │ ├── 4-isalpha.c │ ├── 4-strpbrk.c │ ├── 5-strstr.c │ ├── 6-abs.c │ └── 9-strcpy.c ├── holberton.h └── libholberton.a ├── 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 ├── 2-str_concat.c ├── 3-alloc_grid.c ├── 4-free_grid.c ├── 5-argstostr.c ├── README.md ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ └── 5-main.c ├── 0x0C-more_malloc_free ├── .2-calloc.c.swp ├── 0-malloc_checked.c ├── 1-string_nconcat.c ├── 2-calloc.c ├── 3-array_range.c ├── README.md ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ └── 3-main.c ├── 0x0D-preprocessor ├── 0-object_like_macro.h ├── 1-init_dog.c ├── 1-pi.h ├── 101-preprocessor_abuse.c ├── 3-function_like_macro.h ├── 4-sum.h ├── README.md ├── dog.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ ├── 3-main.c │ └── 4-main.c ├── 0x0E-structures_typedef ├── 1-init_dog.c ├── 2-print_dog ├── 2-print_dog.c ├── 4-new_dog.c ├── 5-free_dog.c ├── README.md ├── dog.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ └── 5-main.c ├── 0x0F-function_pointers ├── .3-get_op_func.c.swp ├── 0-print_name.c ├── 1-array_iterator.c ├── 2-int_index.c ├── 3-calc.h ├── 3-get_op_func.c ├── 3-op_functions.c ├── README.md ├── function_pointers.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ └── 3-main.c ├── 0x10-variadic_functions ├── 0-sum_them_all.c ├── 1-print_numbers.c ├── 100-hello_holberton.asm ├── 100-hello_holberton.o ├── 2-print_strings.c ├── 3-print_all.c ├── README.md ├── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ └── 3-main.c └── variadic_functions.h ├── 0x12-singly_linked_lists ├── 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 ├── _putchar.c ├── lists.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 100-main.c │ ├── 2-main.c │ ├── 3-main.c │ └── 4-main.c ├── 0x13-more_singly_linked_lists ├── 0-print_listint.c ├── 1-listint_len.c ├── 10-delete_nodeint.c ├── 100-reverse_listint.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 └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 100-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ ├── 6-main.c │ ├── 7-main.c │ ├── 8-main.c │ └── 9-main.c ├── 0x14-bit_manipulation ├── 0-binary_to_uint.c ├── 1-print_binary.c ├── 2-get_bit.c ├── 3-set_bit.c ├── 4-clear_bit.c ├── 5-flip_bits.c ├── README.md ├── _putchar.c ├── holberton.h └── mains │ ├── 0-main.c │ └── 1-main.c ├── 0x15-file_io ├── 0-read_textfile.c ├── 1-create_file.c ├── 2-append_text_to_file.c ├── README.md ├── holberton.h └── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 2-main.c │ └── Requiescat ├── 0x17-doubly_linked_lists ├── 0-print_dlistint.c ├── 1-dlistint_len.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 └── mains │ ├── 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 │ └── lists.h ├── 0x18-dynamic_libraries ├── 1-create_dynamic_lib.sh ├── 100-operations.so ├── README.md ├── holberton.h ├── liball.so ├── libholberton.so └── mains │ ├── 0-isupper.c │ ├── 0-isupper.o │ ├── 0-main.c │ ├── 0-main.o │ ├── 0-memset.c │ ├── 0-memset.o │ ├── 0-strcat.c │ ├── 0-strcat.o │ ├── 1-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 │ ├── _putchar.c │ ├── _putchar.o │ ├── functiones.c │ └── main ├── 0x1A-hash_tables ├── 0-hash_table_create.c ├── 1-djb2.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 └── mains │ ├── 0-main.c │ ├── 2-main.c │ ├── 3-main.c │ ├── 4-main.c │ ├── 5-main.c │ └── 6-main.c ├── 0x1C-makefiles ├── 0-Makefile ├── 1-Makefile ├── 2-Makefile ├── 3-Makefile ├── 4-Makefile ├── 5-island_perimeter.py ├── README.md ├── holberton ├── holberton.c ├── m.h └── main.c ├── 0x1E-search_algorithms ├── 0-linear.c ├── 1-binary ├── 1-binary.c ├── 100-jump.c ├── 101-O ├── 102-interpolation.c ├── 103-exponential.c ├── 104-advanced_binary ├── 104-advanced_binary.c ├── 105-jump ├── 105-jump_list.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 ├── mains │ ├── 0-main.c │ ├── 1-main.c │ ├── 100-main.c │ ├── 102-main.c │ ├── 103-main.c │ ├── 104-advanced_binary.c │ └── 104-main.c ├── search_algos.h └── testing └── README.md /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 | #include 4 | #include 5 | #include 6 | /** 7 | * main - Prints quote 8 | * 9 | * Return: zero on success 10 | * 11 | */ 12 | int main(void) 13 | { 14 | write(2, "and that piece of art is useful\" - Dora Korpar, 2015-10-19\n", 59); 15 | return (1); 16 | } 17 | -------------------------------------------------------------------------------- /0x00-hello_world/2-assembler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/3-name: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc $CFILE -o cisfun 3 | -------------------------------------------------------------------------------- /0x00-hello_world/4-puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Prints quote 5 | * 6 | * Return: zero on success 7 | * 8 | */ 9 | int main(void) 10 | { 11 | puts("\"Programming is like building a multilingual puzzle"); 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x00-hello_world/5-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Prints quote 5 | * 6 | * Return: zero on success 7 | * 8 | */ 9 | int main(void) 10 | { 11 | printf("with proper grammar, but the outcome is a piece of art,\n"); 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x00-hello_world/6-size.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Prints quote 5 | * 6 | * Return: zero on success 7 | * 8 | */ 9 | int main(void) 10 | { 11 | int charSize = sizeof(char); 12 | int intSize = sizeof(int); 13 | int longSize = sizeof(long int); 14 | int longlongSize = sizeof(long long int); 15 | int floatSize = sizeof(float); 16 | 17 | printf("Size of a char: %d byte(s)\n", charSize); 18 | printf("Size of an int: %d byte(s)\n", intSize); 19 | printf("Size of a long int: %d byte(s)\n", longSize); 20 | printf("Size of a long long int: %d byte(s)\n", longlongSize); 21 | printf("Size of a float: %d byte(s)\n", floatSize); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x00-hello_world/mains/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x00-hello_world/mains/main.s: -------------------------------------------------------------------------------- 1 | .file "main.c" 2 | .intel_syntax noprefix 3 | .text 4 | .globl main 5 | .type main, @function 6 | main: 7 | .LFB0: 8 | .cfi_startproc 9 | push rbp 10 | .cfi_def_cfa_offset 16 11 | .cfi_offset 6, -16 12 | mov rbp, rsp 13 | .cfi_def_cfa_register 6 14 | mov eax, 0 15 | pop rbp 16 | .cfi_def_cfa 7, 8 17 | ret 18 | .cfi_endproc 19 | .LFE0: 20 | .size main, .-main 21 | .ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4" 22 | .section .note.GNU-stack,"",@progbits 23 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Positive or negative random 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | // srand(time(0)); 14 | n = rand() - RAND_MAX / 2; 15 | 16 | if (n > 0) 17 | { 18 | printf("%d is positive\n", n); 19 | } 20 | if (n == 0) 21 | { 22 | printf("%d is zero\n", n); 23 | } 24 | if (n < 0) 25 | { 26 | printf("%d is negative\n", n); 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Greather and Less than 5 or 6, this is he last number of the "n" 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | int last_di; 13 | 14 | srand(time(0)); 15 | n = rand() - RAND_MAX / 2; 16 | last_di = n % 10; 17 | 18 | if (last_di > 5) 19 | { 20 | printf("Last digit of %d is %d and is greater than 5\n", n, last_di); 21 | } 22 | else if (last_di == 0) 23 | { 24 | printf("Last digit of %d is %d and is 0\n", n, last_di); 25 | } 26 | else 27 | { 28 | printf("Last digit of %d is %d and is less than 6 and not 0\n", n, last_di); 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/10-print_comb2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print numbers '00' to '99' separeted by a comma 7 | * 8 | * Return: 0 for success 9 | */ 10 | int main(void) 11 | { 12 | int digit; 13 | 14 | for (digit = 0; digit < 100; digit++) 15 | { 16 | putchar((digit / 10) + '0'); 17 | putchar((digit % 10) + '0'); 18 | if (digit != 99) 19 | { 20 | putchar(44); 21 | putchar(32); 22 | } 23 | } 24 | putchar('\n'); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print numbers from 00 to 99 without repeating 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | int digit; 12 | 13 | for (digit = 1; digit < 100; digit++) 14 | { 15 | int first, last, reversed; 16 | first = digit / 10; 17 | last = digit % 10; 18 | reversed = (last * 10) + first; 19 | if (digit < reversed) 20 | { 21 | putchar((digit / 10) + '0'); 22 | putchar((digit % 10) + '0'); 23 | 24 | if (digit != 89) 25 | { 26 | putchar(44); 27 | putchar(32); 28 | } 29 | } 30 | } 31 | putchar('\n'); 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - prints all possible different combinations of three digits 4 | * 5 | * Return: 0 if success 6 | **/ 7 | int main(void) 8 | { 9 | 10 | int count; 11 | 12 | for (count = 12; count < 1000; count++) 13 | { 14 | int number1, number2, number3; 15 | number1 = count / 100; 16 | number2 = (count / 10) % 10; 17 | number3 = x % 10; 18 | if (number3 > number2 && number2 > number1) 19 | { 20 | if (count > 12) 21 | { 22 | putchar (','); 23 | putchar (' '); 24 | } 25 | putchar (number1 + 48); 26 | putchar (number2 + 48); 27 | putchar (number3 + 48); 28 | } 29 | } 30 | putchar ('\n'); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/102-print_comb5.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - prints all possible different combinations of two two digit numbers 4 | * 5 | * Return: 0 if success 6 | **/ 7 | int main(void) 8 | { 9 | int count, y, number_first, number_last, y1, y2; 10 | 11 | for (count = 0; count < 100; count++) 12 | { 13 | for (y = 0; y < 100; y++) 14 | { 15 | number_first = count / 10; 16 | number_last = count % 10; 17 | y1 = y / 10; 18 | y2 = y % 10; 19 | if (y > count && count != y) 20 | { 21 | if (y > 1) 22 | { 23 | putchar (','); 24 | putchar (' '); 25 | } 26 | putchar (number_first + 48); 27 | putchar (number_last + 48); 28 | putchar (' '); 29 | putchar (y1 + 48); 30 | putchar (y2 + 48); 31 | } 32 | } 33 | } 34 | putchar ('\n'); 35 | return (0); 36 | } 37 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print alphabet with capital letters 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | char letter; 12 | 13 | for (letter = 'a'; letter <= 'z'; letter++) 14 | putchar(letter); 15 | putchar('\n'); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Letter from "a" to "z" and "z" to "a" 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | int letter; 12 | 13 | for (letter = 'a'; letter <= 'z'; letter++) 14 | { 15 | putchar(letter); 16 | } 17 | for (letter = 'A'; letter <= 'Z'; letter++) 18 | { 19 | putchar(letter); 20 | } 21 | putchar('\n'); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Alphabet between "a" and "z", except "q" and "e" 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | char letter; 12 | 13 | for (letter = 'a'; letter <= 'z'; letter++) 14 | { 15 | if ((letter != 'q') && (letter != 'e')) 16 | { 17 | putchar(letter); 18 | } 19 | } 20 | 21 | putchar('\n'); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print numbers from "0" to "9" 7 | * Return: 0 for success 8 | */ 9 | int main(void) 10 | { 11 | char digit; 12 | 13 | for (digit = '0'; digit <= '9'; digit++) 14 | putchar(digit); 15 | putchar('\n'); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print number from 0 to 9 without using char 7 | * 8 | * Return: 0 for success 9 | */ 10 | int main(void) 11 | { 12 | int digit; 13 | 14 | for (digit = 0; digit <= 9; digit++) 15 | putchar(digit + '0'); 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print alphabet backwards 7 | * 8 | * Return: 0 for success 9 | */ 10 | int main(void) 11 | { 12 | char letter; 13 | 14 | for (letter = 'z'; letter >= 'a'; letter--) 15 | putchar(letter); 16 | 17 | putchar('\n'); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print Numbers Hexadecimal 7 | * 8 | * Return: 0 for success 9 | * 10 | **/ 11 | 12 | int main(void) 13 | { 14 | char ch; 15 | 16 | for (ch = '0'; ch <= '9'; ch++) 17 | { 18 | putchar(ch); 19 | } 20 | for (ch = 'a'; ch <= 'f'; ch++) 21 | { 22 | putchar(ch); 23 | } 24 | putchar('\n'); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Print numbers 0 to 9 separated by a comma 7 | * 8 | * Return: 0 for success 9 | */ 10 | int main(void) 11 | { 12 | int digit; 13 | 14 | for (digit = 0; digit <= 9; digit++) 15 | { 16 | putchar(digit + '0'); 17 | if (digit != 9) 18 | { 19 | putchar(44); 20 | putchar(32); 21 | } 22 | } 23 | putchar('\n'); 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - Write a program that prints Holberton, followed by a new line. 5 | * 6 | * Return: Always 0. 7 | */ 8 | 9 | int main(void) 10 | { 11 | _putchar('H'); 12 | _putchar('o'); 13 | _putchar('l'); 14 | _putchar('b'); 15 | _putchar('e'); 16 | _putchar('r'); 17 | _putchar('t'); 18 | _putchar('o'); 19 | _putchar('n'); 20 | _putchar('\n'); 21 | 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_alphabet - Write a function that prints the alphabet, in lowercase, 5 | * followed by a new 6 | * Return: Always 0. 7 | */ 8 | 9 | void print_alphabet(void) 10 | { 11 | 12 | char letter; 13 | 14 | for (letter = 'a'; letter <= 'z'; letter++) 15 | { 16 | _putchar(letter); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * add - sum between two numbers 5 | * 6 | * @a : number one 7 | * 8 | * @b : number two 9 | * Return : sum 10 | **/ 11 | 12 | int add(int a, int b) 13 | { 14 | return (a + b); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * Description: Calculates the first 50 Fibonacci numbers 6 | * Return: Always Zero 7 | */ 8 | 9 | int main(void) 10 | { 11 | long before, after; 12 | int count = 0; 13 | 14 | before = 1; 15 | after = 2; 16 | printf("%ld, ", before); 17 | printf("%ld, ", after); 18 | while (count <= 47) 19 | { 20 | long fibonnaci; 21 | fibonnaci = before + after; 22 | printf("%ld", fibonnaci); 23 | if (count != 47) 24 | printf(", "); 25 | before = after; 26 | after = fibonnaci; 27 | count++; 28 | } 29 | printf("\n"); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - Entry point 4 | * Description: Calculates the sum of even fib numbers lower than 4,000,000 5 | * Return: Always Zero 6 | */ 7 | int main(void) 8 | { 9 | long before, after, sum; 10 | int count = 0; 11 | 12 | before = 1; 13 | after = 2; 14 | sum = 2; 15 | while (count <= 29) 16 | { 17 | long fibonnaci; 18 | fibonnaci = before + after; 19 | if ((fibonnaci % 2) == 0) 20 | sum += fibonnaci; 21 | before = after; 22 | after = fibonnaci; 23 | count++; 24 | } 25 | printf("%ld\n", sum); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/104-fibonacci.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x02-functions_nested_loops/104-fibonacci.c -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-print_to_98.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * print_to_98 - check the the entry to deteminate if is lower or upper 6 | * 7 | * @n: This is the entry 8 | * Return: Always 0. 9 | */ 10 | 11 | void print_to_98(int n) 12 | { 13 | if (n <= 98) 14 | for (; n <= 97; n++) 15 | printf("%d, ", n); 16 | else 17 | for (; n > 98; n--) 18 | printf("%d, ", n); 19 | printf("98\n"); 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_alphabet_x10 - Print alphabet x10, in lowercase followed by a new line 5 | * 6 | * Return: Always 0. 7 | */ 8 | 9 | void print_alphabet_x10(void) 10 | { 11 | int count; 12 | char letter; 13 | 14 | for (count = 0; count <= 9 ; count++) 15 | { 16 | for (letter = 'a'; letter <= 'z'; letter++) 17 | { 18 | _putchar(letter); 19 | } 20 | _putchar('\n'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check if the entry is in lower. 5 | * @c: This is the entry 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | int _islower(int c) 11 | { 12 | if (c >= 'a' && c <= 'z') 13 | { 14 | return (1); 15 | } 16 | else 17 | { 18 | return (0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isalpha - check the the entry to deteminate if is lower or upper 5 | * 6 | * @c: This is the entry 7 | * Return: Always 0. 8 | */ 9 | 10 | int _isalpha(int c) 11 | { 12 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 13 | { 14 | return (1); 15 | } 16 | else 17 | { 18 | return (0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_sign - Compare the variable N 5 | * @n: If is mayor than 0 show return 1 else 0 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | int print_sign(int n) 11 | { 12 | 13 | if (n > 0) 14 | { 15 | _putchar('+'); 16 | return (1); 17 | } 18 | else if (n == 0) 19 | { 20 | _putchar('0'); 21 | return (0); 22 | } 23 | else 24 | { 25 | _putchar('-'); 26 | return (-1); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _abs - This is a absolute value 5 | * 6 | * @a: This is the entry 7 | * 8 | * Return: Always 0. 9 | */ 10 | 11 | int _abs(int a) 12 | { 13 | if (a < 0) 14 | { 15 | return (a * -1); 16 | } 17 | else 18 | { 19 | return (a); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-print_last_digit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_last_digit - ultimo digito de un numero 5 | * 6 | * @n: entry point 7 | * 8 | * Return: return las digit 9 | **/ 10 | 11 | int print_last_digit(int n) 12 | { 13 | n = n % 10; 14 | 15 | if (n < 0) 16 | { 17 | n = -n; 18 | } 19 | else 20 | { 21 | _putchar(n + '0'); 22 | } 23 | return (n); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24_hours.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * jack_bauer - Count from 00:00 to 23:59 5 | * 6 | * @void: This is the entry 7 | * 8 | * Return: Always 0. 9 | */ 10 | 11 | void jack_bauer(void) 12 | { 13 | int a, b; 14 | 15 | for (a = 0; a <= 23; a++) 16 | { 17 | for (b = 0; b <= 59; b++) 18 | { 19 | _putchar((a / 10) + '0'); 20 | _putchar((a % 10) + '0'); 21 | _putchar(':'); 22 | _putchar((b / 10) + '0'); 23 | _putchar((b % 10) + '0'); 24 | _putchar('\n'); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-times_table.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * times_table - It is a table multiplication 5 | * 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | void times_table(void) 11 | { 12 | int a, b, c; 13 | 14 | for (a = 0; a <= 9; a++) 15 | { 16 | for (b = 0; b <= 9; b++) 17 | { 18 | c = a * b; 19 | 20 | if (b == 0) 21 | { 22 | _putchar(c + '0'); 23 | } 24 | else if (c <= 9) 25 | { 26 | _putchar(32); 27 | _putchar(c + '0'); 28 | } 29 | else 30 | { 31 | _putchar((c / 10) + '0'); 32 | _putchar((c % 10) + '0'); 33 | } 34 | if (b != 9) 35 | { 36 | _putchar(','); 37 | _putchar(32); 38 | } 39 | } 40 | _putchar('\n'); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | /** 5 | * _putchar - writes the character c to stdout 6 | * @c: The character to print 7 | * 8 | * Return: On success 1. 9 | * On error, -1 is returned, and errno is set appropriately. 10 | */ 11 | int _putchar(char c) 12 | { 13 | return (write(1, &c, 1)); 14 | } 15 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _putchar(char c); 5 | void print_alphabet(void); 6 | void print_alphabet_x10(void); 7 | int _islower(int c); 8 | int _isalpha(int c); 9 | int print_sign(int n); 10 | int _abs(int); 11 | int print_last_digit(int); 12 | void jack_bauer(void); 13 | void times_table(void); 14 | void print_to_98(int n); 15 | void print_times_table(int n); 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_alphabet(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/10-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = add(89, 9); 14 | printf("%d\n", n); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/100-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | print_times_table(3); 12 | _putchar('\n'); 13 | print_times_table(5); 14 | _putchar('\n'); 15 | print_times_table(98); 16 | _putchar('\n'); 17 | print_times_table(12); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * * main - check the code for Holberton School students. 5 | * * 6 | * * Return: Always 0. 7 | * */ 8 | int main(void) 9 | { 10 | print_alphabet_x10(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = _islower('H'); 13 | _putchar(r + '0'); 14 | r = _islower('o'); 15 | _putchar(r + '0'); 16 | r = _islower(108); 17 | _putchar(r + '0'); 18 | _putchar('\n'); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = _isalpha('H'); 13 | _putchar(r + '0'); 14 | r = _isalpha('o'); 15 | _putchar(r + '0'); 16 | r = _isalpha(108); 17 | _putchar(r + '0'); 18 | r = _isalpha(';'); 19 | _putchar(r + '0'); 20 | _putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int r; 11 | 12 | r = print_sign(98); 13 | _putchar(','); 14 | _putchar(' '); 15 | _putchar(r + '0'); 16 | _putchar('\n'); 17 | r = print_sign(0); 18 | _putchar(','); 19 | _putchar(' '); 20 | _putchar(r + '0'); 21 | _putchar('\n'); 22 | r = print_sign(0xff); 23 | _putchar(','); 24 | _putchar(' '); 25 | _putchar(r + '0'); 26 | _putchar('\n'); 27 | r = print_sign(-1); 28 | _putchar(','); 29 | _putchar(' '); 30 | _putchar(r + '0'); 31 | _putchar('\n'); 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | int main(void) 11 | { 12 | int r; 13 | 14 | r = _abs(-1); 15 | printf("%d\n", r); 16 | r = _abs(0); 17 | printf("%d\n", r); 18 | r = _abs(1); 19 | printf("%d\n", r); 20 | r = _abs(-98); 21 | printf("%d\n", r); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | jack_bauer(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/8-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | jack_bauer(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/9-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | times_table(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _putchar(char c); 5 | void print_alphabet(void); 6 | void print_alphabet_x10(void); 7 | int _islower(int c); 8 | int _isalpha(int c); 9 | int print_sign(int n); 10 | int _abs(int); 11 | int print_last_digit(int); 12 | void jack_bauer(void); 13 | void times_table(void); 14 | void print_to_98(int n); 15 | void print_times_table(int n); 16 | 17 | #endif 18 | 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/mains/main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_alphabet(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /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 | i++; /* 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 "holberton.h" 2 | 3 | /** 4 | * largest_number - returns the largest of 3 numbers 5 | * @a: first integer 6 | * @b: second integer 7 | * @c: third integer 8 | * Return: largest number 9 | */ 10 | 11 | int largest_number(int a, int b, int c) 12 | { 13 | int largest; 14 | 15 | if (a >= b && a >= c) 16 | { 17 | largest = a; 18 | } 19 | else if (b >= a && b >= c) 20 | { 21 | largest = b; 22 | } 23 | else 24 | { 25 | largest = c; 26 | } 27 | 28 | return (largest); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /0x03-debugging/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H 2 | #define HOLBERTON_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 month, int day, int year); 9 | int convert_day(int month, int day); 10 | #endif /* HOLBERTON_H */ 11 | -------------------------------------------------------------------------------- /0x03-debugging/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.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 | 14 | positive_or_negative(i); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x03-debugging/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - prints the largest of 3 integers 6 | * Return: 0 7 | */ 8 | 9 | int main(void) 10 | { 11 | int a, b, c; 12 | int largest; 13 | 14 | a = 972; 15 | b = -98; 16 | c = 0; 17 | 18 | largest = largest_number(a, b, c); 19 | 20 | printf("%d is the largest number\n", largest); 21 | 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x03-debugging/mains/3-main_a.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - takes a date and prints how many days are left in the year, taking 6 | * leap years into account 7 | * Return: 0 8 | */ 9 | 10 | int main(void) 11 | { 12 | int month; 13 | int day; 14 | int year; 15 | 16 | month = 4; 17 | day = 01; 18 | year = 1997; 19 | 20 | printf("Date: %02d/%02d/%04d\n", month, day, year); 21 | 22 | day = convert_day(month, day); 23 | 24 | print_remaining_days(month, day, year); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - If is uppercase return 1, if not return 0 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isupper(int c) 12 | { 13 | if (c >= 'A' && c <= 'Z') 14 | { 15 | return (1); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - If is 0 to 9 return 1, if not return 0, function check a digit 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isdigit(int c) 12 | { 13 | if (c >= '0' && c <= '9') 14 | { 15 | return (1); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-print_triangle.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_triangle - Write a function that prints a triangle, followed by a new 5 | * line. 6 | * @size: demensions of triangle 7 | * Return: nothing 8 | **/ 9 | 10 | void print_triangle(int size) 11 | { 12 | int replay, count; 13 | 14 | if (size < 1) 15 | { 16 | _putchar('\n'); 17 | return; 18 | } 19 | for (replay = 1; replay <= size; replay++) 20 | { 21 | for (count = size - replay; count > 0; count--) 22 | _putchar(' '); 23 | for (count = replay; count > 0; count--) 24 | _putchar('#'); 25 | _putchar('\n'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - Write a program that finds and prints the largest prime factor 6 | * 7 | * number 612852475143, followed by a new line. 8 | * 9 | * Return: 0 10 | * 11 | **/ 12 | int main(void) 13 | { 14 | int newValue, count; 15 | long int number = 612852475143; 16 | 17 | for (count = 2; count <= number; count++) 18 | { 19 | if (number % count == 0) 20 | { 21 | number = number / count; 22 | newValue = count; 23 | } 24 | } 25 | printf("%d\n", newValue); 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_number.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_number - Write a function that prints an integer with putchar 5 | * @n: This is my number to print 6 | * 7 | */ 8 | void print_number(int n) 9 | { 10 | unsigned int num2, num1 = n; 11 | int div = 1; 12 | 13 | if (n < 0) 14 | { 15 | _putchar('-'); 16 | num1 = n * -1; 17 | } 18 | num2 = num1; 19 | while (num2 > 9) 20 | { 21 | div *= 10; 22 | num2 = num2 / 10; 23 | } 24 | while (div >= 1) 25 | { 26 | num2 = num1 % div; 27 | num1 /= div; 28 | _putchar(num1 + '0'); 29 | num1 = num2; 30 | div /= 10; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * mul - Multiplicacion of two numbers 5 | * 6 | * @a: Number 1 7 | * @b: Number 2 8 | * 9 | * Return: Result between a * b 10 | **/ 11 | 12 | int mul(int a, int b) 13 | { 14 | return (a * b); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_numbers - Prints the numbers, from 0 to 9, followed by a new line 5 | * 6 | * 7 | * Return: is zero 8 | */ 9 | void print_numbers(void) 10 | { 11 | char digits; 12 | 13 | for (digits = '0'; digits <= '9'; digits++) 14 | { 15 | _putchar(digits); 16 | } 17 | _putchar('\n'); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_most_numbers - Prints numbers "0" to "9", except 2 and 4 5 | * 6 | * 7 | * Return: is zero 8 | */ 9 | void print_most_numbers(void) 10 | { 11 | char digits; 12 | 13 | for (digits = '0'; digits <= '9'; digits++) 14 | { 15 | if (digits != '9' && digits != '4') 16 | { 17 | _putchar(digits); 18 | } 19 | } 20 | _putchar('\n'); 21 | } 22 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * more_numbers - prints 10 times the numbers, from 0 to 14 5 | * 6 | */ 7 | 8 | void more_numbers(void) 9 | { 10 | int replay, count; 11 | 12 | for (replay = 0; replay <= 9; replay++) 13 | { 14 | for (count = 0; count <= 14; count++) 15 | { 16 | 17 | if (count >= 10 && count <= 14) 18 | { 19 | _putchar((count / 10) + '0'); 20 | } 21 | _putchar((count % 10) + '0'); 22 | } 23 | _putchar('\n'); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_line - Write a function that draws a straight line in the terminal 5 | * 6 | * @n: this is the entry 7 | * 8 | * 9 | */ 10 | 11 | void print_line(int n) 12 | { 13 | int count; 14 | 15 | for (count = 1; n >= 1 && count <= n; count++) 16 | { 17 | _putchar(95); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_diagonal - function that draws a diagonal line on the terminal 5 | * 6 | * @n: this is the size of the diagonal 7 | * 8 | * Return: There is no error 9 | **/ 10 | 11 | void print_diagonal(int n) 12 | { 13 | int replay, count; 14 | 15 | for (replay = 1; n > 0 && replay <= n; replay++) 16 | { 17 | for (count = 1; count <= replay; count++) 18 | { 19 | if (count == replay) 20 | { 21 | _putchar(92); 22 | } 23 | else 24 | { 25 | _putchar(32); 26 | } 27 | } 28 | _putchar('\n'); 29 | } 30 | if (n <= 0) 31 | _putchar('\n'); 32 | } 33 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_square - Function that prints a square, followed by a new line. 5 | * 6 | * @n: Entry 7 | * 8 | * 9 | */ 10 | 11 | void print_square(int n) 12 | { 13 | 14 | if (n > 0) 15 | { 16 | int replay; 17 | for (replay = 1; replay <= n; replay++) 18 | { 19 | int count; 20 | for (count = 1; count <= n; count++) 21 | { 22 | _putchar(35); 23 | } 24 | _putchar('\n'); 25 | } 26 | } 27 | else 28 | { 29 | _putchar('\n'); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * _putchar - writes the character c to stdout 6 | * @c: The character to print 7 | * 8 | * Return: On success 1. 9 | * On error, -1 is returned, and errno is set appropriately. 10 | */ 11 | int _putchar(char c) 12 | { 13 | return (write(1, &c, 1)); 14 | } 15 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _isupper(int c); 5 | int _isdigit(int c); 6 | int mul(int a, int b); 7 | int _putchar(char c); 8 | void print_numbers(void); 9 | void print_most_numbers(void); 10 | void more_numbers(void); 11 | void print_line(int n); 12 | void print_diagonal(int n); 13 | void print_square(int size); 14 | void print_triangle(int size); 15 | void print_number(int n); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | 13 | c = 'A'; 14 | printf("%c: %d\n", c, _isupper(c)); 15 | c = 'a'; 16 | printf("%c: %d\n", c, _isupper(c)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | 13 | c = '0'; 14 | printf("%c: %d\n", c, _isdigit(c)); 15 | c = 'a'; 16 | printf("%c: %d\n", c, _isdigit(c)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/101-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_number(98); 11 | _putchar('\n'); 12 | print_number(402); 13 | _putchar('\n'); 14 | print_number(1024); 15 | _putchar('\n'); 16 | print_number(0); 17 | _putchar('\n'); 18 | print_number(-98); 19 | _putchar('\n'); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | printf("%d\n", mul(98, 1024)); 12 | printf("%d\n", mul(-402, 4096)); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_numbers(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_most_numbers(); 11 | return (0); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | more_numbers(); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_line(0); 11 | print_line(2); 12 | print_line(10); 13 | print_line(-4); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_diagonal(0); 11 | print_diagonal(2); 12 | print_diagonal(10); 13 | print_diagonal(-4); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/8-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_square(2); 11 | print_square(10); 12 | print_square(0); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/mains/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _isupper(int c); 5 | int _isdigit(int c); 6 | int mul(int a, int b); 7 | int _putchar(char c); 8 | void print_numbers(void); 9 | void print_most_numbers(void); 10 | void more_numbers(void); 11 | void print_line(int n); 12 | void print_diagonal(int n); 13 | void print_square(int size); 14 | void print_triangle(int size); 15 | void print_number(int n); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * reset_to_98 - function that takes a pointer to an int as parameter and 5 | * updates the value it points to to 98. 6 | * 7 | * @n: This is the entry 8 | * 9 | */ 10 | 11 | void reset_to_98(int *n) 12 | { 13 | *n = 98; 14 | } 15 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * swap_int - function that swaps the values of two integers. 5 | * @a: this is the first entry 6 | * @b: this is the second entry 7 | * 8 | * 9 | */ 10 | void swap_int(int *a, int *b) 11 | { 12 | int changed; 13 | 14 | changed = *a; 15 | *a = *b; 16 | *b = changed; 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/100-atoi.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _atoi - Convert string to an integer. 3 | * @s: Pointer to a character string. 4 | * 5 | * Return: void. 6 | */ 7 | 8 | int _atoi(char *s) 9 | { 10 | int sign; 11 | unsigned int num; 12 | char *temp; 13 | 14 | temp = s; 15 | num = 0; 16 | sign = 1; 17 | while (*temp != '\0' && (*temp < '0' || *temp > '9')) 18 | { 19 | if (*temp == '-') 20 | sign *= -1; 21 | temp++; 22 | } 23 | if (*temp != '\0') 24 | { 25 | do { 26 | num = num * 10 + (*temp - '0'); 27 | temp++; 28 | } while (*temp >= '0' && *temp <= '9'); 29 | } 30 | return (num * sign); 31 | } 32 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/101-keygen.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x05-pointers_arrays_strings/101-keygen.c -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - Function that returns the length of a string 5 | * 6 | * @s: this is the input string 7 | * 8 | * Return: Lenngth of the string 9 | */ 10 | int _strlen(char *s) 11 | { 12 | int index; 13 | 14 | for (index = 0; s[index] != '\0' ; index++) 15 | ; 16 | return (index); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed by a new line, to 5 | * stdout. 6 | * 7 | * @str: This is my input string 8 | * 9 | */ 10 | 11 | void _puts(char *str) 12 | { 13 | int index; 14 | 15 | for (index = 0; str[index] != '\0'; index++) 16 | { 17 | _putchar(str[index]); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_rev - This function prints a reverse string 5 | * 6 | * @s: This is the input string 7 | */ 8 | void print_rev(char *s) 9 | { 10 | int index; 11 | 12 | for (index = 0; s[index] != '\0'; index++) 13 | ; 14 | for (index = index - 1; s[index] != '\0'; index--) 15 | { 16 | _putchar(s[index]); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * rev_string - This fuction print a string reverser 5 | * 6 | *@s: this is the pointer that point to a string 7 | */ 8 | 9 | void rev_string(char *s) 10 | { 11 | int a, len; 12 | 13 | char *begin, *end = s; 14 | 15 | for (a = 0; s[a] != '\0' && s[a + 1] != '\0'; a++) 16 | { 17 | end++; 18 | } 19 | len = a + 1; 20 | begin = s; 21 | for (a = 0; a < len / 2; a++) 22 | { 23 | char x; 24 | x = *end; 25 | *end = *begin; 26 | *begin = x; 27 | begin++; 28 | end--; 29 | } 30 | end[len + 1] = '\0'; 31 | } 32 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * puts2 - Write a function that prints every other character of a string, 5 | * starting with the first character, followed by a new line. 6 | * 7 | * @s: This pointer point to a char or string 8 | * 9 | * 10 | */ 11 | 12 | void puts2(char *s) 13 | { 14 | int a; 15 | 16 | for (a = 0; s[a] != '\0'; a++) 17 | { 18 | if (a % 2 == 0) 19 | { 20 | _putchar(s[a]); 21 | } 22 | } 23 | _putchar('\n'); 24 | } 25 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | *puts_half - function that prints half of a string, followed by a new line. 4 | * 5 | *@str: This is the input string 6 | */ 7 | void puts_half(char *str) 8 | { 9 | int index, half; 10 | 11 | index = 0; 12 | while (str[index] != '\0') 13 | index++; 14 | 15 | half = index / 2; 16 | 17 | if (index % 2 == 1) 18 | half++; 19 | 20 | while (half < index) 21 | { 22 | _putchar(str[half]); 23 | half++; 24 | } 25 | _putchar('\n'); 26 | } 27 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * print_array - function that prints n elements of an array of integers, 5 | * followed by a new line. 6 | * @a: This is the input array 7 | * @n: This is the lenght of the array 8 | * 9 | * 10 | */ 11 | 12 | void print_array(int *a, int n) 13 | { 14 | int index; 15 | 16 | for (index = 0; index < n; index++) 17 | { 18 | printf("%d", a[index]); 19 | if (index != (n - 1)) 20 | { 21 | printf(", "); 22 | } 23 | } 24 | putchar('\n'); 25 | } 26 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcpy - Copiar el contenido de uno a otra variable 5 | * @dest: This is destiny 6 | * @src: This is the copia 7 | * 8 | * Return: This return copy 9 | */ 10 | char *_strcpy(char *dest, char *src) 11 | { 12 | char *start = dest; 13 | 14 | while (*src != '\0') 15 | { 16 | *dest = *src; 17 | dest++; 18 | src++; 19 | } 20 | *dest = '\0'; 21 | return (start); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | void reset_to_98(int *n); 5 | void swap_int(int *a, int *b); 6 | int _strlen(char *s); 7 | void _puts(char *str); 8 | int _putchar(char c); 9 | void print_rev(char *s); 10 | void puts2(char *str); 11 | void puts_half(char *str); 12 | void print_array(int *a, int n); 13 | char *_strcpy(char *dest, char *src); 14 | void rev_string(char *s); 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = 402; 14 | printf("n=%d\n", n); 15 | reset_to_98(&n); 16 | printf("n=%d\n", n); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int a; 12 | int b; 13 | 14 | a = 98; 15 | b = 42; 16 | printf("a=%d, b=%d\n", a, b); 17 | swap_int(&a, &b); 18 | printf("a=%d, b=%d\n", a, b); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *str; 12 | int len; 13 | 14 | str = "Holberton!"; 15 | len = _strlen(str); 16 | printf("%d\n", len); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; 13 | _puts(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "I do not fear computers. I fear the lack of them - Isaac Asimov"; 13 | print_rev(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s[10] = "Holberton"; 12 | 13 | printf("%s\n", s); 14 | rev_string(s); 15 | printf("%s\n", s); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "0123456789"; 13 | puts2(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | char *str; 11 | 12 | str = "0123456789"; 13 | puts_half(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/8-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | int array[5]; 11 | 12 | array[0] = 98; 13 | array[1] = 402; 14 | array[2] = -198; 15 | array[3] = 298; 16 | array[4] = -1024; 17 | print_array(array, 5); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/mains/9-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98]; 12 | char *p; 13 | 14 | p = _strcpy(s1, "First, solve the problem. Then, write the code\n"); 15 | printf("%s", s1); 16 | printf("%s", p); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_strcat - Write a function that concatenates two strings. 5 | * 6 | *@dest: This is the output dest 7 | *@src: This is the input source 8 | * 9 | * Return: This return to dest, that concatenates two strings 10 | */ 11 | 12 | char *_strcat(char *dest, char *src) 13 | { 14 | int i, j; 15 | 16 | for (i = 0; dest[i] != '\0'; i++) 17 | ; 18 | for (j = 0; src[j] != '\0'; j++) 19 | { 20 | dest[i] = src[j]; 21 | i++; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strncat - Write a function that concatenates two strings. it will use at 5 | * most n bytes from src 6 | * 7 | * @dest: This is the output dest 8 | * @src: This is the input src 9 | * @n: This is the number bytes fro src 10 | * 11 | * Return: This is my return 12 | */ 13 | char *_strncat(char *dest, char *src, int n) 14 | { 15 | int index, count; 16 | 17 | for (index = 0; dest[index] != '\0'; index++) 18 | ; 19 | for (count = 0; count < n && src[count] != '\0'; count++) 20 | { 21 | dest[index] = src[count]; 22 | index++; 23 | } 24 | if (count < n) 25 | { 26 | dest[index] = '\0'; 27 | } 28 | return (dest); 29 | } 30 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-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 "holberton.h" 2 | /** 3 | * _strncpy - Write a function that copies a string, with number of bytes 4 | * @dest: This is the output dest 5 | * @src: This is the input source 6 | * @n: This is the number of bytes to copy 7 | * 8 | *Return: Copied string with the number of bytes 9 | */ 10 | 11 | char *_strncpy(char *dest, char *src, int n) 12 | { 13 | int index; 14 | 15 | for (index = 0; index < n && src[index] != '\0' ; index++) 16 | { 17 | dest[index] = src[index]; 18 | } 19 | for (; index < n; index++) 20 | { 21 | dest[index] = '\0'; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcmp - Write a function that compares two strings. 4 | * 5 | * @s1: This is the input string 6 | * @s2: This is the input string 7 | * 8 | * Return: If the strings are equals return "0", if not return other number 9 | */ 10 | 11 | int _strcmp(char *s1, char *s2) 12 | { 13 | for (; (*s1 != '\0' && *s2 != '\0') && (*s1 == *s2); s1++, s2++) 14 | ; 15 | if (*s1 == *s2) 16 | { 17 | return (0); 18 | } 19 | return (*s1 - *s2); 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * reverse_array - Write a function that reverses the content of an array of 5 | * integers. 6 | * 7 | * @a: This is the input array 8 | * @n: This is the positions have the array 9 | * 10 | */ 11 | void reverse_array(int *a, int n) 12 | { 13 | int i, last; 14 | 15 | last = n - 1; 16 | for (i = 0; i < n / 2; i++) 17 | { 18 | int start, end; 19 | 20 | start = a[i]; 21 | end = a[last]; 22 | a[i] = end; 23 | a[last] = start; 24 | last--; 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * string_toupper - Write a function that changes all lowercase letters of a 4 | * string to uppercase. 5 | * 6 | * @hi: This is the input string 7 | * 8 | * Return: Lowercase changed to uppercase of the string 9 | */ 10 | char *string_toupper(char *hi) 11 | { 12 | int index = 0; 13 | int desp = 'a' - 'A'; 14 | 15 | for (index = 0; hi[index] != '\0'; ++index) 16 | { 17 | if (hi[index] >= 'a' && hi[index] <= 'z') 18 | { 19 | hi[index] = hi[index] - desp; 20 | } 21 | } 22 | return (hi); 23 | } 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-leet.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * leet - Write a function that encodes a string into 1337 5 | * 6 | * @changed: This is the input string 7 | * 8 | * Return: String converted to 1337 9 | */ 10 | 11 | char *leet(char *changed) 12 | { 13 | int index, j; 14 | char minus[] = {'a', 'e', 'o', 't', 'l', '\0'}; 15 | char mayus[] = {'A', 'E', 'O', 'T', 'L', '\0'}; 16 | char numbers[] = {'4', '3', '0', '7', '1', '\0'}; 17 | 18 | for (index = 0; changed[index] != '\0'; ++index) 19 | { 20 | for (j = 0; j < 5; j++) 21 | { 22 | if (changed[index] == minus[j] || changed[index] == mayus[j]) 23 | { 24 | changed[index] = numbers[j]; 25 | } 26 | } 27 | } 28 | return (changed); 29 | } 30 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/8-rot13.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * rot13 - Write a function that encodes a string using rot13 4 | * 5 | * @hi: This is my input string 6 | * 7 | * Return: String converted to rot13 8 | * 9 | */ 10 | 11 | char *rot13(char *hi) 12 | { 13 | int index, count; 14 | 15 | char minus[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 16 | char mayus[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"; 17 | 18 | for (index = 0; hi[index] != '\0'; ++index) 19 | { 20 | for (count = 0; minus[count] != '\0' ; count++) 21 | { 22 | if (hi[index] == minus[count]) 23 | { 24 | hi[index] = mayus[count]; 25 | break; 26 | } 27 | } 28 | } 29 | hi[index] = '\0'; 30 | return (hi); 31 | } 32 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _putchar(char c); 5 | char *_strcat(char *dest, char *src); 6 | char *_strncat(char *dest, char *src, int n); 7 | char *_strncpy(char *dest, char *src, int n); 8 | int _strcmp(char *s1, char *s2); 9 | void reverse_array(int *a, int n); 10 | char *string_toupper(char *); 11 | char *cap_string(char *); 12 | char *leet(char *); 13 | char *rot13(char *); 14 | char *_strstr(char *haystack, char *needle); 15 | void print_number(int n); 16 | #endif 17 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98] = "Hello "; 12 | char s2[] = "World!\n"; 13 | char *p; 14 | 15 | printf("%s\n", s1); 16 | printf("%s", s2); 17 | p = _strcat(s1, s2); 18 | printf("%s", s1); 19 | printf("%s", s2); 20 | printf("%s", p); 21 | return (0); 22 | } 23 | 24 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[98] = "Hello "; 12 | char s2[] = "World!\n"; 13 | char *p; 14 | 15 | printf("%s\n", s1); 16 | printf("%s", s2); 17 | p = _strncat(s1, s2, 1); 18 | printf("%s\n", s1); 19 | printf("%s", s2); 20 | printf("%s\n", p); 21 | p = _strncat(s1, s2, 1024); 22 | printf("%s", s1); 23 | printf("%s", s2); 24 | printf("%s", p); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/100-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_number(98); 11 | _putchar('\n'); 12 | print_number(402); 13 | _putchar('\n'); 14 | print_number(1024); 15 | _putchar('\n'); 16 | print_number(0); 17 | _putchar('\n'); 18 | print_number(-98); 19 | _putchar('\n'); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s1[] = "Hello"; 12 | char s2[] = "World!"; 13 | 14 | printf("%d\n", _strcmp(s1, s2)); 15 | printf("%d\n", _strcmp(s2, s1)); 16 | printf("%d\n", _strcmp(s1, s1)); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "world"; 13 | char *t; 14 | 15 | t = _strstr(s, f); 16 | printf("%s\n", t); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s[] = "Expect the best. Prepare for the worst. Capitalize on what comes.\nhello world! hello-world 0123456hello world\thello world.hello world\n"; 12 | char *p; 13 | 14 | p = cap_string(s); 15 | printf("%s", p); 16 | printf("%s", s); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char s[] = "Expect the best. Prepare for the worst. Capitalize on what comes.\n"; 12 | char *p; 13 | 14 | p = leet(s); 15 | printf("%s", p); 16 | printf("%s", s); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - Write a function that fills memory with a constant byte 5 | * The _memset() function fills the first n bytes of the memory area pointed to 6 | * by s with the constant byte b 7 | * 8 | * @s: This is the output and the return 9 | * @b: This is the this is the input string 10 | * @n: This is the number of bytes 11 | * 12 | * Return: A pointer to the memory area s 13 | */ 14 | char *_memset(char *s, char b, unsigned int n) 15 | { 16 | unsigned int count; 17 | 18 | for (count = 0; count < n ; count++) 19 | { 20 | s[count] = b; 21 | } 22 | return (s); 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - Write a function that copies memory area. 5 | * The _memcpy() function copies n bytes from memory area src to memory area 6 | * dest 7 | * 8 | * @dest: This is the output string 9 | * @src: This is my input string 10 | * @n: This is the number bytes to copy 11 | * 12 | * Return: This is the string copied 13 | */ 14 | 15 | char *_memcpy(char *dest, char *src, unsigned int n) 16 | { 17 | unsigned int count; 18 | char *pDst = dest; 19 | char const *pSrc = src; 20 | 21 | for (count = 0; count < n; count++) 22 | { 23 | *pDst++ = *pSrc++; 24 | } 25 | return (dest); 26 | } 27 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strchr - Function that locates a character in a string 5 | * @s: This is the input string 6 | * @c: This is the character 7 | * Return: Return to the character found, if not return a NULL 8 | */ 9 | char *_strchr(char *s, char c) 10 | { 11 | for (; ; s++) 12 | { 13 | if (*s == c) 14 | return (s); 15 | if (*s == 0) 16 | return (NULL); 17 | } 18 | return (NULL); 19 | } 20 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strspn - Function that gets the length of a prefix substring 4 | * @s: This is the string literal 5 | * @accept: This is the second string 6 | * 7 | * Return: number of bytes in the initial segment of s which consist only of 8 | * bytes from accept 9 | */ 10 | 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int index, j, counter; 14 | 15 | counter = 0; 16 | for (index = 0; s[index] != '\0'; index++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (accept[j] == s[index]) 21 | { 22 | counter++; 23 | break; 24 | } 25 | } 26 | if (accept[j] != s[index]) 27 | { 28 | break; 29 | } 30 | } 31 | return (counter); 32 | } 33 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strpbrk - Searches a string for any of a set of bytes. 6 | * The _strpbrk() function locates the first occurrence in the string s of any 7 | * of the bytes in the string accept 8 | * 9 | * @s: This is the input string 10 | * @accept: This is the string to locate 11 | * 12 | * Return: Returns a pointer to the byte in s that matches one of the bytes in 13 | * accept, or NULL if no such byte is found 14 | */ 15 | char *_strpbrk(char *s, char *accept) 16 | { 17 | unsigned int index, count; 18 | 19 | for (index = 0; s[index] != '\0'; index++) 20 | { 21 | for (count = 0; accept[count] != '\0'; count++) 22 | { 23 | if (accept[count] == s[index]) 24 | { 25 | return (&s[index]); 26 | } 27 | } 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _strstr - Write a function that locates a substring. 5 | * 6 | * @haystack: This is the input string 7 | * @needle: This is a find to locate in the string 8 | * 9 | * Return: a pointer to the beginning of the located substring, or NULL if the 10 | * substring is not found. 11 | */ 12 | 13 | char *_strstr(char *haystack, char *needle) 14 | { 15 | while (*haystack) 16 | { 17 | char *temp; 18 | 19 | temp = haystack; 20 | while (*needle == *haystack) 21 | { 22 | haystack++, needle++; 23 | } 24 | if (*needle == '\0') 25 | return (temp); 26 | haystack++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * print_chessboard - Write a function that prints the chessboard. 5 | * 6 | * @a: This is my variable 7 | * 8 | */ 9 | 10 | void print_chessboard(char (*a)[8]) 11 | { 12 | int count, index; 13 | 14 | for (count = 0; count < 8; count++) 15 | { 16 | for (index = 0; index < 8; index++) 17 | { 18 | _putchar(a[count][index]); 19 | } 20 | _putchar('\n'); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_diagsums - print the sum the diognals of a square matrix of integer 5 | * 6 | * @a: This is the array to sum 7 | * @size: This is the length of the array 8 | */ 9 | 10 | void print_diagsums(int *a, int size) 11 | { 12 | int ascedent, descendet, i, sumAscedent, sumDescedent; 13 | 14 | sumAscedent = sumDescedent = 0; 15 | ascedent = 0; 16 | descendet = size - 1; 17 | for (i = 0; i < size; i++) 18 | { 19 | sumAscedent += *(a + i * size + ascedent); 20 | sumDescedent += *(a + i * size + descendet); 21 | ascedent += 1; 22 | descendet -= 1; 23 | } 24 | printf("%d, %d\n", sumAscedent, sumDescedent); 25 | } 26 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/9-set_string.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * set_string - set value of pointer a char 4 | * 5 | * @s: This is my entry to set 6 | * @to: This is my entry to copy 7 | */ 8 | void set_string(char **s, char *to) 9 | { 10 | *s = to; 11 | } 12 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | char *_memset(char *s, char b, unsigned int n); 5 | char *_memcpy(char *dest, char *src, unsigned int n); 6 | unsigned int _strspn(char *s, char *accept); 7 | char *_strpbrk(char *s, char *accept); 8 | int _putchar(char c); 9 | void print_chessboard(char (*a)[8]); 10 | char *_strchr(char *s, char c); 11 | char *_strstr(char *haystack, char *needle); 12 | void set_string(char **s, char *to); 13 | void print_diagsums(int *a, int size); 14 | #endif 15 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello"; 12 | char *f; 13 | 14 | f = _strchr(s, 'l'); 15 | 16 | if (f != NULL) 17 | { 18 | printf("%s\n", f); 19 | } 20 | return (0); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "oleh"; 13 | unsigned int n, i; 14 | char *strtext = "129th"; 15 | char *cset = "1234567890"; 16 | n = _strspn(s, f); 17 | printf("%u\n", n); 18 | 19 | i = _strspn (strtext,cset); 20 | printf("%u",i); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "world"; 13 | char *t; 14 | 15 | t = _strpbrk(s, f); 16 | printf("%s\n", t); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s = "hello, world"; 12 | char *f = "world"; 13 | char *t; 14 | 15 | t = _strstr(s, f); 16 | printf("%s\n", t); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char board[8][8] = { 12 | {'r', 'k', 'b', 'q', 'k', 'b', 'k', 'r'}, 13 | {'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'}, 14 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 15 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 16 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 17 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 18 | {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'}, 19 | {'R', 'K', 'B', 'Q', 'K', 'B', 'K', 'R'}, 20 | }; 21 | print_chessboard(board); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/8-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int c3[3][3] = { 12 | {0, 1, 5}, 13 | {10, 11, 12}, 14 | {1000, 101, 102}, 15 | }; 16 | int c5[5][5] = { 17 | {0, 1, 5, 12124, 1234}, 18 | {10, 11, 12, 123521, 12512}, 19 | {1000, 101, 102, 12545, 214543435}, 20 | {100, 1012451, 11102, 12545, 214543435}, 21 | {10, 12401, 10452, 11542545, 1214543435}, 22 | }; 23 | print_diagsums((int *)c3, 3); 24 | print_diagsums((int *)c5, 5); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/mains/9-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *s0 = "Bob Dylan"; 12 | char *s1 = "Robert Allen"; 13 | 14 | printf("%s, %s\n", s0, s1); 15 | set_string(&s1, s0); 16 | printf("%s, %s\n", s0, s1); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _puts_recursion - Write a function that prints a string, followed by a new 4 | * line. 5 | * 6 | * @s: This is the input string 7 | */ 8 | 9 | void _puts_recursion(char *s) 10 | { 11 | if (*s == '\0') 12 | { 13 | _putchar('\n'); 14 | return; 15 | } 16 | _putchar(*s); 17 | s++; 18 | _puts_recursion(s); 19 | } 20 | -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _print_rev_recursion - Write a function that prints a string in reverse. 4 | * @s: This is my entry 5 | * 6 | */ 7 | void _print_rev_recursion(char *s) 8 | { 9 | if (*s) 10 | { 11 | _print_rev_recursion(s + 1); 12 | _putchar(*s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strlen_recursion - Write a function that returns the length of a string. 4 | * @s: This is the input string 5 | * 6 | * Return: Result is the length of the string 7 | */ 8 | int _strlen_recursion(char *s) 9 | { 10 | if (*s == '\0') 11 | return (0); 12 | return (_strlen_recursion(s + 1) + 1); 13 | } 14 | -------------------------------------------------------------------------------- /0x08-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * factorial - Write a function that returns the factorial of a given number. 5 | * 6 | * @n: This is the input number 7 | * 8 | * Return: The factorial of a given number 9 | */ 10 | int factorial(int n) 11 | { 12 | if (n == 0) 13 | { 14 | return (1); 15 | } 16 | else if (n < 0) 17 | { 18 | return (-1); 19 | } 20 | return (n * factorial(n - 1)); 21 | } 22 | -------------------------------------------------------------------------------- /0x08-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _pow_recursion - Write a function that returns the value of x raised to the 4 | * power of y. 5 | * 6 | * @x: This is the input number 7 | * @y: This is the power number 8 | * 9 | * Return: if "y" is bigger than zero raised to the power of "y", 10 | * return -1 if "y" is lower than zero, return 1 if "y" is equal to 1, 11 | */ 12 | int _pow_recursion(int x, int y) 13 | { 14 | if (y == 0) 15 | { 16 | return (1); 17 | } 18 | if (y < 0) 19 | { 20 | return (-1); 21 | } 22 | return (x * _pow_recursion(x, y - 1)); 23 | } 24 | -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x08-recursion/5-sqrt -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * my_sqrt_recursion - This is my my_sqrt_recursion 5 | * function about the square root 6 | * @a: The entry is equal to n, of the before function 7 | * @b: This is the sum 8 | * 9 | * Return: This is the result 10 | */ 11 | int my_sqrt_recursion(int a, int b) 12 | { 13 | if (a == (b * b)) 14 | return (b); 15 | else if ((b * b) >= a) 16 | return (-1); 17 | else 18 | return (my_sqrt_recursion(a, b + 1)); 19 | } 20 | 21 | /** 22 | * _sqrt_recursion - This is my first function 23 | * @n: This is my value 24 | * 25 | * Return: This is my result of the function my_sqrt_recursion 26 | */ 27 | int _sqrt_recursion(int n) 28 | { 29 | if (n <= 0) 30 | return (-1); 31 | return (my_sqrt_recursion(n, 0)); 32 | } 33 | -------------------------------------------------------------------------------- /0x08-recursion/6-is_prime_number.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * is_prime_number - Write a function that returns 1 if the input integer is a 4 | * prime number, otherwise return 0. 5 | * 6 | * @prime: Is my number prime 7 | * 8 | * Return: 1 if the input integer is a prime number, otherwise return 0 9 | */ 10 | 11 | int is_prime_number(int prime) 12 | { 13 | if (prime <= 1) 14 | return (0); 15 | if (prime == 2) 16 | return (1); 17 | if ((prime % 2 == 0) || (prime % 3 == 0) || (prime % 5 == 0)) 18 | return (0); 19 | else if (prime % 9 == 0 || prime % 7 == 0) 20 | return (0); 21 | else 22 | return (1); 23 | } 24 | -------------------------------------------------------------------------------- /0x08-recursion/7-palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x08-recursion/7-palindrome -------------------------------------------------------------------------------- /0x08-recursion/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /0x08-recursion/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _strlen_recursion(char *s); 5 | int factorial(int n); 6 | int _pow_recursion(int x, int y); 7 | int _putchar(char c); 8 | int is_prime_number(int prime); 9 | int _sqrt_recursion(int n); 10 | int is_palindrome(char *s); 11 | int another(int a, int b); 12 | void _puts_recursion(char *s); 13 | void _print_rev_recursion(char *s); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /0x08-recursion/mains/0-main.c: -------------------------------------------------------------------------------- 1 | 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | _puts_recursion("Betty Holberton"); 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x08-recursion/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int n; 12 | 13 | n = _strlen_recursion("Corbin Coleman"); 14 | printf("%d\n", n); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x08-recursion/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _pow_recursion(1, 10); 14 | printf("%d\n", r); 15 | r = _pow_recursion(1024, 0); 16 | printf("%d\n", r); 17 | r = _pow_recursion(2, 16); 18 | printf("%d\n", r); 19 | r = _pow_recursion(5, 2); 20 | printf("%d\n", r); 21 | r = _pow_recursion(5, -2); 22 | printf("%d\n", r); 23 | r = _pow_recursion(-5, 3); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x08-recursion/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _sqrt_recursion(1); 14 | printf("%d\n", r); 15 | r = _sqrt_recursion(1024); 16 | printf("%d\n", r); 17 | r = _sqrt_recursion(16); 18 | printf("%d\n", r); 19 | r = _sqrt_recursion(17); 20 | printf("%d\n", r); 21 | r = _sqrt_recursion(25); 22 | printf("%d\n", r); 23 | r = _sqrt_recursion(-1); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x08-recursion/mains/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = is_prime_number(1); 14 | printf("%d\n", r); 15 | r = is_prime_number(1024); 16 | printf("%d\n", r); 17 | r = is_prime_number(16); 18 | printf("%d\n", r); 19 | r = is_prime_number(17); 20 | printf("%d\n", r); 21 | r = is_prime_number(25); 22 | printf("%d\n", r); 23 | r = is_prime_number(-1); 24 | printf("%d\n", r); 25 | r = is_prime_number(113); 26 | printf("%d\n", r); 27 | r = is_prime_number(7919); 28 | printf("%d\n", r); 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x08-recursion/mains/7-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = is_palindrome("level"); 14 | printf("%d\n", r); 15 | r = is_palindrome("redder"); 16 | printf("%d\n", r); 17 | r = is_palindrome("holberton"); 18 | printf("%d\n", r); 19 | r = is_palindrome("step on no pets"); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x09-static_libraries/create_static_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c *.c 3 | ar rc liball.a *.o 4 | ranlib liball.a 5 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - If is uppercase return 1, if not return 0 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isupper(int c) 12 | { 13 | if (c >= 'A' && c <= 'Z') 14 | { 15 | return (1); 16 | } 17 | else 18 | { 19 | return (0); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - This is my function copy the number the character to S 5 | * @s: This is my entry and return 6 | * @b: This is the character to copy 7 | * @n: This is the number of Bytes 8 | * 9 | * Return: This is my result and Return S 10 | */ 11 | char *_memset(char *s, char b, unsigned int n) 12 | { 13 | unsigned int a; 14 | 15 | for (a = 0; a < n ; a++) 16 | { 17 | s[a] = b; 18 | } 19 | return (s); 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_strcat - This is the main copy 5 | *@dest: This is my dest 6 | *@src: This is my source 7 | * 8 | * Return: This return to the result 9 | */ 10 | 11 | char *_strcat(char *dest, char *src) 12 | { 13 | int a, b; 14 | 15 | for (a = 0; dest[a] != '\0'; a++) 16 | { 17 | } 18 | for (b = 0; src[b] != '\0'; b++) 19 | { 20 | dest[a] = src[b]; 21 | a++; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - If is 0 to 9 return 1, if not return 0 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isdigit(int c) 12 | { 13 | if (c >= '0' && c <= '9') 14 | { 15 | return (1); 16 | } 17 | else 18 | { 19 | return (0); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - This is my funcion copy Src to dest 5 | * @dest: This is my result 6 | * @src: This is my string 7 | * @n: This is n my number bytes to copy 8 | * 9 | * Return: This my my string copy 10 | */ 11 | 12 | char *_memcpy(char *dest, char *src, unsigned int n) 13 | { 14 | unsigned int a; 15 | char *pDst = dest; 16 | char const *pSrc = src; 17 | 18 | for (a = 0; a < n; a++) 19 | { 20 | *pDst++ = *pSrc++; 21 | } 22 | return (dest); 23 | } 24 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strncat - THis is the main 5 | * @dest: This is the dest 6 | * @src: This is the src 7 | * @n: Thi is n 8 | * Return: This is my return 9 | */ 10 | char *_strncat(char *dest, char *src, int n) 11 | { 12 | int a, b; 13 | 14 | for (a = 0; dest[a] != '\0'; a++) 15 | { 16 | } 17 | for (b = 0; b < n && src[b] != '\0'; b++) 18 | { 19 | dest[a] = src[b]; 20 | a++; 21 | } 22 | if (b < n) 23 | { 24 | dest[a] = '\0'; 25 | } 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/2-args.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x09-static_libraries/files_c/2-args.c -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strchr - This is my funcion 5 | * @s: This my string of char 6 | * @c: This is my character 7 | * Return: This is my resulti 8 | */ 9 | char *_strchr(char *s, char c) 10 | { 11 | for (; ; s++) 12 | { 13 | if (*s == c) 14 | return (s); 15 | if (*s == 0) 16 | return (NULL); 17 | } 18 | return (NULL); 19 | } 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - This function is equal to strlen 5 | * 6 | * @s: this is my entry 7 | * 8 | * Return: the las character 9 | */ 10 | int _strlen(char *s) 11 | { 12 | int a; 13 | 14 | for (a = 0; s[a] != '\0' ; a++) 15 | { 16 | } 17 | return (a); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strncpy - This is my main 4 | * @dest: This is my dest 5 | * @src: This is my source 6 | * @n: This is my N 7 | * 8 | *Return: THis is my return 9 | */ 10 | 11 | char *_strncpy(char *dest, char *src, int n) 12 | { 13 | int b; 14 | 15 | for (b = 0; b < n && src[b] != '\0' ; b++) 16 | { 17 | dest[b] = src[b]; 18 | } 19 | for (; b < n; b++) 20 | { 21 | dest[b] = '\0'; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check if the entry is in lower. 5 | * @c: This is the entry 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | int _islower(int c) 11 | { 12 | if (c >= 'a' && c <= 'z') 13 | { 14 | return (1); 15 | } 16 | else 17 | { 18 | return (0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Escribir un texto 5 | * 6 | * @str: This is my entry 7 | * 8 | */ 9 | 10 | void _puts(char *str) 11 | { 12 | int a; 13 | 14 | for (a = 0; str[a] != '\0'; a++) 15 | { 16 | _putchar(str[a]); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcmp - This is my function 4 | * @s1: This is my entry 5 | * @s2: This is my entry again 6 | * Return: This is my result 7 | */ 8 | 9 | int _strcmp(char *s1, char *s2) 10 | { 11 | for (; (*s1 != '\0' && *s2 != '\0') && *s1 == *s2; s1++, s2++) 12 | { 13 | } 14 | if (*s1 == *s2) 15 | { 16 | return (0); 17 | } 18 | else 19 | { 20 | return (*s1 - *s2); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strspn - This is my function 4 | * @s: This is the string literal 5 | * @accept: This is the second string 6 | * 7 | * Return: This is the equal string to S 8 | */ 9 | 10 | unsigned int _strspn(char *s, char *accept) 11 | { 12 | unsigned int a, b, c; 13 | 14 | c = 0; 15 | for (a = 0; s[a] != '\0'; a++) 16 | { 17 | for (b = 0; accept[b] != '\0'; b++) 18 | { 19 | if (accept[b] == s[a]) 20 | { 21 | c++; 22 | break; 23 | } 24 | } 25 | if (accept[b] != s[a]) 26 | { 27 | break; 28 | } 29 | } 30 | return (c); 31 | } 32 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isalpha - check the the entry to deteminate if is lower or upper 5 | * 6 | * @c: This is the entry 7 | * Return: Always 0. 8 | */ 9 | 10 | int _isalpha(int c) 11 | { 12 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 13 | { 14 | return (1); 15 | } 16 | else 17 | { 18 | return (0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strpbrk - This is my function 6 | * @s: This is my entry 7 | * @accept: This is my second entry 8 | * Return: This is my return 9 | */ 10 | char *_strpbrk(char *s, char *accept) 11 | { 12 | unsigned int a, b; 13 | 14 | for (a = 0; s[a] != '\0'; a++) 15 | { 16 | for (b = 0; accept[b] != '\0'; b++) 17 | { 18 | if (accept[b] == s[a]) 19 | { 20 | return (&s[a]); 21 | } 22 | } 23 | } 24 | return (NULL); 25 | } 26 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strstr - locates a substring inside a string 6 | * 7 | * @haystack: string to search 8 | * @needle: substring to search for 9 | * Return: returns pointer to location of substring inside haystack or NULL 10 | */ 11 | 12 | char *_strstr(char *haystack, char *needle) 13 | { 14 | int i; 15 | 16 | i = 0; 17 | while (haystack[i] != '\0') 18 | { 19 | int j, start; 20 | 21 | start = i; 22 | j = 0; 23 | while (haystack[i] == needle[j] && 24 | needle[j] != '\0' && haystack[i] != '\0') 25 | { 26 | i++; 27 | j++; 28 | } 29 | if (needle[j] == '\0') 30 | return (haystack + start); 31 | i = start + 1; 32 | } 33 | return (NULL); 34 | } 35 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _abs - This is a absolute value 5 | * 6 | * @a: This is the entry 7 | * 8 | * Return: Always 0. 9 | */ 10 | 11 | int _abs(int a) 12 | { 13 | if (a > 0) 14 | { 15 | return (a); 16 | } 17 | else if (a < 0) 18 | { 19 | a = a * -1; 20 | return (a); 21 | } 22 | else 23 | { 24 | return (a); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x09-static_libraries/files_c/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcpy - Copiar el contenido de uno a otra variable 5 | * @dest: This is destiny 6 | * @src: This is the copia 7 | * 8 | * Return: This return copy 9 | */ 10 | char *_strcpy(char *dest, char *src) 11 | { 12 | char *start = dest; 13 | 14 | while (*src != '\0') 15 | { 16 | *dest = *src; 17 | dest++; 18 | src++; 19 | } 20 | *dest = '\0'; 21 | return (start); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _putchar(char c); 5 | int _islower(int c); 6 | int _isalpha(int c); 7 | int _abs(int n); 8 | int _isupper(int c); 9 | int _isdigit(int c); 10 | int _strlen(char *s); 11 | void _puts(char *s); 12 | char *_strcpy(char *dest, char *src); 13 | int _atoi(char *s); 14 | char *_strcat(char *dest, char *src); 15 | char *_strncat(char *dest, char *src, int n); 16 | char *_strncpy(char *dest, char *src, int n); 17 | int _strcmp(char *s1, char *s2); 18 | char *_memset(char *s, char b, unsigned int n); 19 | char *_memcpy(char *dest, char *src, unsigned int n); 20 | char *_strchr(char *s, char c); 21 | unsigned int _strspn(char *s, char *accept); 22 | char *_strpbrk(char *s, char *accept); 23 | char *_strstr(char *haystack, char *needle); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /0x09-static_libraries/libholberton.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x09-static_libraries/libholberton.a -------------------------------------------------------------------------------- /0x0A-argc_argv/0-whatsmyname.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Write a program that prints its name, followed by a new line. 5 | * If you rename the program, it will print the new name, without having to 6 | * compile it again 7 | * You should not remove the path before the name of the program 8 | * 9 | * @argc: This is the argument count 10 | * @argv: This is the argument vector 11 | * 12 | * Return: This return to 0 13 | */ 14 | int main(int argc, char *argv[]) 15 | { 16 | printf("%s\n", argv[0]); 17 | (void)argc; 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0A-argc_argv/1-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - Write a program that prints the number of arguments passed into it 4 | * 5 | * @args: This is the argument count 6 | * @argv: This is the argument vector 7 | * 8 | * Return: This return to 0 9 | * 10 | */ 11 | int main(int args, char *argv[]) 12 | { 13 | printf("%d\n", args - 1); 14 | (void)argv; 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0A-argc_argv/100-change.c: -------------------------------------------------------------------------------- 1 | nclude 2 | #include 3 | 4 | /** 5 | * main - Prints coints left 6 | * @args: Paramater Entry 7 | * @argv: One number of argumets 8 | * Return: zero onOne number of argumetsr 9 | */ 10 | 11 | int main(int args, char *argv[]) 12 | { 13 | int c, coins = 0; 14 | 15 | if (args != 2) 16 | { 17 | printf("Error\n"); 18 | return (1); 19 | } 20 | c = atoi(argv[1]); 21 | if (c < 0) 22 | { 23 | printf("0\n"); 24 | return (0); 25 | } 26 | for (; c >= 0;) 27 | { 28 | if (c >= 25) 29 | c -= 25; 30 | 31 | else if (c >= 10) 32 | c -= 10; 33 | 34 | else if (c >= 5) 35 | c -= 5; 36 | 37 | else if (c >= 2) 38 | c -= 2; 39 | 40 | else if (c >= 1) 41 | c -= 1; 42 | else 43 | break; 44 | coins += 1; 45 | } 46 | printf("%d\n", coins); 47 | return (0); 48 | } 49 | -------------------------------------------------------------------------------- /0x0A-argc_argv/2-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - Write a program that prints all arguments it receives 4 | * All arguments should be printed, including the first on 5 | * 6 | * @argc: This is the argument count 7 | * @argv: This is the argument vector 8 | * 9 | * Return: 0; 10 | */ 11 | int main(int argc, char *argv[]) 12 | { 13 | int count; 14 | 15 | for (count = 0; count < argc; count++) 16 | { 17 | printf("%s\n", argv[count]); 18 | } 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x0A-argc_argv/3-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - Program that multiplies two numbers. 5 | * @argc: This is the argument count 6 | * @argv: This is the argument vector 7 | * 8 | * Return: 0; 9 | */ 10 | int main(int argc, char *argv[]) 11 | { 12 | int index, multiplication; 13 | 14 | multiplication = 1; 15 | if (argc < 3) 16 | { 17 | printf("Error\n"); 18 | return (1); 19 | } 20 | for (index = 1; index < argc; index++) 21 | { 22 | multiplication = multiplication * atoi(argv[index]); 23 | } 24 | printf("%d\n", multiplication); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x0A-argc_argv/4-add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * main - Program that adds positive numbers 8 | 9 | * @argc: This is the argument count 10 | * @argv: This is the argument vector 11 | * 12 | * Return: 0; 13 | */ 14 | int main(int argc, char *argv[]) 15 | { 16 | int sum = 0, i; 17 | 18 | if (argc > 1) 19 | { 20 | for (i = 1; i < argc; i++) 21 | { 22 | int b; 23 | char *str; 24 | 25 | str = argv[i]; 26 | for (b = 0; str[b] != '\0'; b++) 27 | { 28 | if (str[b] < 48 || str[b] > 57) 29 | { 30 | printf("Error\n"); 31 | return (1); 32 | } 33 | } 34 | } 35 | } 36 | for (i = 1; i < argc; i++) 37 | { 38 | sum += atoi(argv[i]); 39 | } 40 | printf("%d\n", sum); 41 | return (0); 42 | } 43 | -------------------------------------------------------------------------------- /0x0B-malloc_free/0-create_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "holberton.h" 4 | 5 | /** 6 | * create_array - function that creates an array of chars, and initializes it 7 | * with a specific char. 8 | * 9 | * @size: This is the length of the array 10 | * @c: This is the input character 11 | * 12 | * Return: An Array Initialized with the specific char 13 | */ 14 | 15 | char *create_array(unsigned int size, char c) 16 | { 17 | unsigned int a; 18 | char *s; 19 | 20 | s = (char *) malloc(size * sizeof(char)); 21 | if (s == NULL) 22 | return (NULL); 23 | for (a = 0; a < size; a++) 24 | { 25 | s[a] = c; 26 | } 27 | return (s); 28 | } 29 | -------------------------------------------------------------------------------- /0x0B-malloc_free/1-strdup.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | /** 5 | * _strdup - function that returns a pointer to a newly allocated space in 6 | * memory, which contains a copy of the string given as a parameter. 7 | * 8 | * @str: This is the input string 9 | * 10 | * Return: function returns a pointer to the duplicated string. It returns 11 | * NULL if insufficient memory was available 12 | */ 13 | char *_strdup(char *str) 14 | { 15 | char *s; 16 | int a, b; 17 | 18 | if (str == NULL) 19 | return (NULL); 20 | 21 | for (a = 0; str[a] != '\0'; a++) 22 | ; 23 | s = (char *) malloc((a + 1) * sizeof(char)); 24 | 25 | if (s == NULL) 26 | return (NULL); 27 | 28 | for (b = 0; b < a ; b++) 29 | s[b] = str[b]; 30 | 31 | s[a + 1] = '\0'; 32 | return (s); 33 | } 34 | -------------------------------------------------------------------------------- /0x0B-malloc_free/4-free_grid.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * free_grid - function that frees a 2 dimensional grid previously created by 7 | * your alloc_grid function. 8 | * 9 | * @grid: This is a dimesional array 10 | * @height: This is the numbers of rows has the array 11 | * 12 | */ 13 | 14 | void free_grid(int **grid, int height) 15 | { 16 | int i; 17 | 18 | for (i = 0; i < height; i++) 19 | { 20 | free(grid[i]); 21 | } 22 | free(grid); 23 | } 24 | -------------------------------------------------------------------------------- /0x0B-malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | #include 5 | void free_grid(int **grid, int height); 6 | char *str_concat(char *s1, char *s2); 7 | char *_strdup(char *str); 8 | int _putchar(char c); 9 | char *create_array(unsigned int size, char c); 10 | int **alloc_grid(int width, int height); 11 | char *argstostr(int ac, char **av); 12 | #endif 13 | -------------------------------------------------------------------------------- /0x0B-malloc_free/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *s; 13 | 14 | s = _strdup("Holberton"); 15 | if (s == NULL) 16 | { 17 | printf("failed to allocate memory\n"); 18 | return (1); 19 | } 20 | printf("%s\n", s); 21 | free(s); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x0B-malloc_free/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *s; 13 | 14 | s = str_concat(NULL, "Holberton"); 15 | if (s == NULL) 16 | { 17 | printf("failed\n"); 18 | return (1); 19 | } 20 | printf("%s\n", s); 21 | free(s); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x0B-malloc_free/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char *av[]) 11 | { 12 | char *s; 13 | 14 | s = argstostr(ac, av); 15 | if (s == NULL) 16 | { 17 | return (1); 18 | } 19 | printf("%s", s); 20 | free(s); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/.2-calloc.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x0C-more_malloc_free/.2-calloc.c.swp -------------------------------------------------------------------------------- /0x0C-more_malloc_free/0-malloc_checked.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * malloc_checked - function that allocates memory using malloc. 7 | * 8 | * @b: This is the length to allocate in the memory 9 | * 10 | * Return: Returns a pointer to the allocated memory 11 | * if malloc fails, the malloc_checked function should cause normal 12 | * process 13 | * termination with a status value of 98 14 | * 15 | */ 16 | void *malloc_checked(unsigned int b) 17 | { 18 | void *p; 19 | 20 | p = malloc(b); 21 | if (p == NULL) 22 | exit(98); 23 | return (p); 24 | } 25 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | int *array_range(int min, int max); 4 | void *_calloc(unsigned int nmemb, unsigned int size); 5 | char *string_nconcat(char *s1, char *s2, unsigned int n); 6 | int _putchar(char c); 7 | void *malloc_checked(unsigned int b); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always 0. 10 | */ 11 | int main(void) 12 | { 13 | char *c; 14 | int *i; 15 | float *f; 16 | double *d; 17 | 18 | c = malloc_checked(sizeof(char) * 1024); 19 | printf("%p\n", (void *)c); 20 | i = malloc_checked(sizeof(int) * 402); 21 | printf("%p\n", (void *)i); 22 | f = malloc_checked(sizeof(float) * 100000000); 23 | printf("%p\n", (void *)f); 24 | d = malloc_checked(INT_MAX); 25 | printf("%p\n", (void *)d); 26 | free(c); 27 | free(i); 28 | free(f); 29 | free(d); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | char *concat; 13 | 14 | concat = string_nconcat("Holberton ", "School !!!", 6); 15 | printf("%s\n", concat); 16 | free(concat); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0D-preprocessor/0-object_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #define SIZE 1024 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /0x0D-preprocessor/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | /** 3 | * init_dog - initialize a variable of type struct dog. 4 | * @d: pointer to the adress to initialize. 5 | * @name: The dog's name'. 6 | * @age: The dog's age'. 7 | * @owner: The dog owner's name. 8 | */ 9 | void init_dog(struct dog *d, char *name, float age, char *owner) 10 | { 11 | if (d) 12 | { 13 | d->name = name; 14 | d->age = age; 15 | d->owner = owner; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x0D-preprocessor/1-pi.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #define PI 3.14159265359 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /0x0D-preprocessor/101-preprocessor_abuse.c: -------------------------------------------------------------------------------- 1 | #pragma message("Hello, Holberton\n") 2 | -------------------------------------------------------------------------------- /0x0D-preprocessor/3-function_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | #define ABS(X) ((X < 0) ? -(X) : (X)) 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x0D-preprocessor/4-sum.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #define SUM(X, Y) ((X + Y)) 4 | #endif 5 | -------------------------------------------------------------------------------- /0x0D-preprocessor/dog.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x0D-preprocessor/dog.h -------------------------------------------------------------------------------- /0x0D-preprocessor/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "0-object_like_macro.h" 2 | #include "0-object_like_macro.h" 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int s; 13 | 14 | s = 98 + SIZE; 15 | printf("%d\n", s); 16 | return (0); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /0x0D-preprocessor/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "1-pi.h" 2 | #include "1-pi.h" 3 | #include 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | float a; 13 | float r; 14 | 15 | r = 98; 16 | a = PI * r * r; 17 | printf("%.3f\n", a); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0D-preprocessor/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print the name of my file 4 | * 5 | * Return: 0 6 | */ 7 | int main(void) 8 | { 9 | printf("%s\n", __FILE__); 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x0D-preprocessor/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "3-function_like_macro.h" 3 | #include "3-function_like_macro.h" 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int i; 13 | int j; 14 | 15 | i = ABS(-98) * 10; 16 | j = ABS(98) * 10; 17 | printf("%d, %d\n", i, j); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0D-preprocessor/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "4-sum.h" 3 | #include "4-sum.h" 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | int s; 13 | 14 | s = SUM(98, 1024); 15 | printf("%d\n", s); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | /** 3 | * init_dog - initialize a variable of type struct dog. 4 | * @d: pointer to the adress to initialize. 5 | * @name: The dog's name'. 6 | * @age: The dog's age'. 7 | * @owner: The dog owner's name. 8 | */ 9 | void init_dog(struct dog *d, char *name, float age, char *owner) 10 | { 11 | if (d) 12 | { 13 | d->name = name; 14 | d->age = age; 15 | d->owner = owner; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-print_dog: -------------------------------------------------------------------------------- 1 | void print_dog(struct dog *d); 2 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-print_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | #include 4 | /** 5 | * print_dog - print a structure. 6 | * @d: pointer containing the structure. 7 | */ 8 | void print_dog(struct dog *d) 9 | { 10 | if (d == NULL) 11 | return; 12 | if ((*d).name == NULL) 13 | (*d).name = "(nil)"; 14 | 15 | if ((*d).owner == NULL) 16 | (*d).owner = "(nil)"; 17 | printf("Name: %s\n", (*d).name); 18 | printf("Age: %f\n", (*d).age); 19 | printf("Owner: %s\n", (*d).owner); 20 | } 21 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-free_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | /** 4 | * free_dog - frees the dogs.. 5 | * @d: Pointer to the struct. 6 | * Return: None. 7 | */ 8 | void free_dog(dog_t *d) 9 | { 10 | if (d) 11 | { 12 | free(d->name); 13 | free(d->owner); 14 | free(d); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/dog.h: -------------------------------------------------------------------------------- 1 | #ifndef DOG_H 2 | #define DOG_H 3 | #include 4 | #include 5 | /** 6 | * struct dog - this descripction about which dog 7 | * @name: sdfasdf 8 | * @age: asdfas 9 | * @owner: asdf 10 | */ 11 | 12 | struct dog 13 | { 14 | char *name; 15 | float age; 16 | char *owner; 17 | }; 18 | typedef struct dog dog_t; 19 | dog_t *new_dog(char *name, float age, char *owner); 20 | void init_dog(struct dog *d, char *name, float age, char *owner); 21 | void print_dog(struct dog *d); 22 | void free_dog(dog_t *d); 23 | #endif 24 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | struct dog my_dog; 12 | 13 | my_dog.name = "Django"; 14 | my_dog.age = 3.5; 15 | my_dog.owner = "Bob"; 16 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 17 | printf("The name of the owner is %s\n", my_dog.owner); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | struct dog my_dog; 12 | 13 | init_dog(&my_dog, "Django", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(void) 11 | { 12 | struct dog my_dog; 13 | 14 | my_dog.name = NULL; 15 | my_dog.age = 4.3; 16 | my_dog.owner = "Bob"; 17 | print_dog(&my_dog); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | dog_t my_dog; 12 | 13 | my_dog.name = "Django"; 14 | my_dog.age = 3.5; 15 | my_dog.owner = "Bob"; 16 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 17 | printf("The name of the owner is %s\n", my_dog.owner); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/4-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | dog_t *my_dog; 12 | 13 | my_dog = new_dog("Django", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/mains/5-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | dog_t *my_dog; 12 | 13 | my_dog = new_dog("Django", 3.5, "Bob"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | free_dog(my_dog); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0F-function_pointers/.3-get_op_func.c.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x0F-function_pointers/.3-get_op_func.c.swp -------------------------------------------------------------------------------- /0x0F-function_pointers/0-print_name.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * print_name - function that prints a name 5 | * 6 | * @name: THis is the input string or the input name 7 | * @f: This is the input function to print the name 8 | * 9 | */ 10 | void print_name(char *name, void (*f)(char *)) 11 | { 12 | if (f != 0 && name != 0) 13 | f(name); 14 | } 15 | -------------------------------------------------------------------------------- /0x0F-function_pointers/1-array_iterator.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * array_iterator - function that executes a function given as a parameter on 8 | * each element of an array. 9 | * 10 | * @size: This is large of the array 11 | * @array: This is the input array 12 | * @action: This is the input function 13 | * 14 | */ 15 | 16 | void array_iterator(int *array, size_t size, void (*action)(int)) 17 | { 18 | size_t a; 19 | 20 | if (array == NULL || action == NULL) 21 | return; 22 | for (a = 0; a < size; a++) 23 | { 24 | action(array[a]); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x0F-function_pointers/3-calc.h: -------------------------------------------------------------------------------- 1 | #ifndef CALC 2 | #define CALC 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | /** 9 | * struct op - Struct op 10 | * 11 | * @op: The operator 12 | * @f: The function associated 13 | */ 14 | 15 | typedef struct op 16 | { 17 | char *op; 18 | int (*f)(int a, int b); 19 | } op_t; 20 | 21 | int op_add(int a, int b); 22 | int op_sub(int a, int b); 23 | int op_mul(int a, int b); 24 | int op_div(int a, int b); 25 | int op_mod(int a, int b); 26 | int (*get_op_func(char *s))(int, int); 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /0x0F-function_pointers/function_pointers.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | 5 | int int_index(int *array, int size, int (*cmp)(int)); 6 | void array_iterator(int *array, size_t size, void (*action)(int)); 7 | void print_name(char *name, void (*f)(char *)); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x0F-function_pointers/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "function_pointers.h" 3 | 4 | /** 5 | * print_elem - prints an integer 6 | * @elem: the integer to print 7 | * 8 | * Return: Nothing. 9 | */ 10 | void print_elem(int elem) 11 | { 12 | printf("%d\n", elem); 13 | } 14 | 15 | /** 16 | * print_elem_hex - prints an integer, in hexadecimal 17 | * @elem: the integer to print 18 | * 19 | * Return: Nothing. 20 | */ 21 | void print_elem_hex(int elem) 22 | { 23 | printf("0x%x\n", elem); 24 | } 25 | 26 | /** 27 | * main - check the code for Holberton School students. 28 | * 29 | * Return: Always 0. 30 | */ 31 | int main(void) 32 | { 33 | int array[5] = {0, 98, 402, 1024, 4096}; 34 | 35 | array_iterator(array, 5, &print_elem); 36 | array_iterator(array, 5, &print_elem_hex); 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /0x0F-function_pointers/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "3-calc.h" 2 | /** 3 | * main - This function we have a two number and an operator 4 | * @ac: Is the length of Number of arguments 5 | * @av: These are the arguments 6 | * Return: Return to 0 7 | */ 8 | int main(int ac, char *av[]) 9 | { 10 | int numb1, numb2; 11 | int (*fun)(int, int); 12 | char *c = av[2]; 13 | 14 | if (ac != 4) 15 | { 16 | printf("Error\n"); 17 | exit(98); 18 | } 19 | if ((*c != '+' && *c != '-' && *c != '*' && *c != '/' && *c != '%') || 20 | *(c + 1) != 0) 21 | { 22 | printf("Error\n"); 23 | exit(99); 24 | } 25 | numb1 = atoi(av[1]); 26 | numb2 = atoi(av[3]); 27 | if ((*c == '/' || *c == '%') && numb2 == 0) 28 | { 29 | printf("Error\n"); 30 | exit(100); 31 | } 32 | fun = get_op_func(c); 33 | printf("%d\n", fun(numb1, numb2)); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /0x10-variadic_functions/0-sum_them_all.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "variadic_functions.h" 4 | /** 5 | * sum_them_all - function that returns the sum of all its parameters. 6 | * 7 | * @n: The number of items 8 | * 9 | * Return: Returns the sum of all its parameters. 10 | * If n == 0, return 0 11 | */ 12 | int sum_them_all(const unsigned int n, ...) 13 | { 14 | va_list ap; 15 | unsigned int count; 16 | int sum; 17 | 18 | sum = 0; 19 | va_start(ap, n); 20 | 21 | for (count = 0; count < n; count++) 22 | { 23 | sum += va_arg(ap, int); 24 | } 25 | va_end(ap); 26 | return (sum); 27 | } 28 | -------------------------------------------------------------------------------- /0x10-variadic_functions/1-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "variadic_functions.h" 4 | /** 5 | * print_numbers - Function that prints numbers, 6 | * followed by a new line. 7 | * 8 | * @separator: This is input separator 9 | * @n: This is the input number 10 | * 11 | */ 12 | void print_numbers(const char *separator, const unsigned int n, ...) 13 | { 14 | va_list valist; 15 | unsigned int count; 16 | 17 | va_start(valist, n); 18 | for (count = 0; count < n; count++) 19 | { 20 | printf("%d", va_arg(valist, const unsigned int)); 21 | if (separator != NULL && count != (n - 1)) 22 | printf("%s", separator); 23 | } 24 | printf("\n"); 25 | va_end(valist); 26 | } 27 | -------------------------------------------------------------------------------- /0x10-variadic_functions/100-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | section .text 2 | global _start ;must be declared for linker (ld) 3 | 4 | _start: ;tells linker entry point 5 | mov edx,len ;message length 6 | mov ecx,msg ;message to write 7 | mov ebx,1 ;file descriptor (stdout) 8 | mov eax,4 ;system call number (sys_write) 9 | int 0x80 ;call kernel 10 | 11 | mov eax,1 ;system call number (sys_exit) 12 | int 0x80 ;call kernel 13 | 14 | section .data 15 | msg db 'Hello, world!', 0xa ;string to be printed 16 | len equ $ - msg ;length of the string 17 | -------------------------------------------------------------------------------- /0x10-variadic_functions/100-hello_holberton.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x10-variadic_functions/100-hello_holberton.o -------------------------------------------------------------------------------- /0x10-variadic_functions/2-print_strings.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "variadic_functions.h" 4 | 5 | /** 6 | * print_strings - function that prints strings, followed by a new line 7 | * 8 | * @separator: This is the input separator 9 | * @n: This is the number of items 10 | * 11 | */ 12 | 13 | void print_strings(const char *separator, const unsigned int n, ...) 14 | { 15 | va_list ap; 16 | unsigned int count; 17 | 18 | va_start(ap, n); 19 | for (count = 0; count < n; count++) 20 | { 21 | char *s; 22 | s = va_arg(ap, char *); 23 | if (s == NULL) 24 | printf("(nil)"); 25 | else 26 | printf("%s", s); 27 | if (separator != NULL && (count + 1) != n) 28 | printf("%s", separator); 29 | } 30 | printf("\n"); 31 | va_end(ap); 32 | } 33 | -------------------------------------------------------------------------------- /0x10-variadic_functions/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "variadic_functions.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int sum; 12 | 13 | sum = sum_them_all(2, -98, -1024); 14 | printf("%d\n", sum); 15 | sum = sum_them_all(4, 98, 1024, 402, -1024); 16 | printf("%d\n", sum); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x10-variadic_functions/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_numbers(", ", 4, 0, 98, -1024, 402); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_strings(", ", 4, "Jay", "Django", "", "hola"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/mains/3-main.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | print_all("ceis", 'H', 0, "lberton"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/variadic_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int sum_them_all(const unsigned int n, ...); 5 | void print_strings(const char *separator, const unsigned int n, ...); 6 | void print_numbers(const char *separator, const unsigned int n, ...); 7 | void print_all(const char * const format, ...); 8 | 9 | 10 | #endif 11 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/0-print_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * print_list - function that prints all the elements of a list_t list. 5 | * 6 | * @h: This take the value of the single list 7 | * 8 | * Return: Return: the number of nodes 9 | * If str is NULL, print [0] (nil) 10 | */ 11 | 12 | size_t print_list(const list_t *h) 13 | { 14 | unsigned int count = 0; 15 | 16 | if (h == NULL) 17 | return (0); 18 | while (h != NULL) 19 | { 20 | if (h->str == NULL) 21 | printf("[%u] (nil)\n", h->len); 22 | else 23 | printf("[%u] %s\n", h->len, h->str); 24 | count += 1; 25 | h = h->next; 26 | } 27 | return (count); 28 | } 29 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * list_len - function that returns the number of elements in a linked list_t 4 | * list. 5 | * 6 | * @h: This is the sigle list 7 | * 8 | * Return: The number of elements in a linked list_t list 9 | */ 10 | size_t list_len(const list_t *h) 11 | { 12 | int count = 0; 13 | 14 | if (h == NULL) 15 | return (0); 16 | while (h != NULL) 17 | { 18 | count += 1; 19 | h = h->next; 20 | } 21 | return (count); 22 | } 23 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-first.c: -------------------------------------------------------------------------------- 1 | #include 2 | /* 3 | * Apply the constructor attribute to startupfun() 4 | * so that it is executed before main() 5 | */ 6 | void startupfun(void) __attribute__ ((constructor)); 7 | 8 | /* 9 | * Apply the destructor attribute to cleanupfun() 10 | *so that it is executed after main() 11 | */ 12 | 13 | void cleanupfun(void)__attribute__ ((destructor)); 14 | /** 15 | * startupfun - This functions print a text 16 | * 17 | */ 18 | void startupfun(void) 19 | { 20 | printf("You're beat! and yet, you must allow,"); 21 | printf("\nI bore my house upon my back!\n"); 22 | } 23 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | Creating files 2 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-free_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_list - Function that frees a list_t list. 5 | * @head: This is the linked listi 6 | */ 7 | 8 | void free_list(list_t *head) 9 | { 10 | 11 | if (head == NULL) 12 | { 13 | return; 14 | } 15 | while (head != NULL) 16 | { 17 | list_t *tmp; 18 | 19 | tmp = head; 20 | free(tmp->str); 21 | free(tmp); 22 | head = head->next; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/_putchar.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * _putchar - writes the character c to stdout 6 | * @c: The character to print 7 | * 8 | * Return: On success 1. 9 | * On error, -1 is returned, and errno is set appropriately. 10 | */ 11 | int _putchar(char c) 12 | { 13 | return(write(1, &c, 1)); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/lists.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | #include 5 | #include 6 | #include 7 | /** 8 | * struct list_s - singly linked list 9 | * @str: string - (malloc'ed string) 10 | * @len: length of the string 11 | * @next: points to the next node 12 | * 13 | * Description: singly linked list node structure 14 | * for Holberton project 15 | */ 16 | typedef struct list_s 17 | { 18 | char *str; 19 | unsigned int len; 20 | struct list_s *next; 21 | } list_t; 22 | 23 | int _putchar(char c); 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_ref, char *str); 27 | list_t *add_node_end(list_t **head, const char *str); 28 | void free_list(list_t *head); 29 | #endif 30 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | list_t *head; 14 | list_t *new; 15 | list_t hello = {"World", 5, NULL}; 16 | size_t n; 17 | 18 | head = &hello; 19 | new = malloc(sizeof(list_t)); 20 | if (new == NULL) 21 | { 22 | printf("Error\n"); 23 | return (1); 24 | } 25 | new->str = strdup("Hello"); 26 | new->len = 5; 27 | new->next = head; 28 | head = new; 29 | n = list_len(head); 30 | printf("-> %lu elements\n", n); 31 | free(new->str); 32 | free(new); 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/mains/100-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - check the code for Holberton School students. 5 | * 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | printf("(A tortoise, having pretty good sense of a hare's nature, challenges one to a race.)\n"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | list_t *head; 14 | 15 | head = NULL; 16 | add_node_end(&head, "Bob"); 17 | add_node_end(&head, "&"); 18 | add_node_end(&head, "Kris"); 19 | add_node_end(&head, "love"); 20 | add_node_end(&head, "asm"); 21 | print_list(head); 22 | free_list(head); 23 | head = NULL; 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-print_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * print_listint - This function print int in every position 4 | * @h: This is my structure entry 5 | * Return: This return to the number the nodes 6 | * 7 | */ 8 | size_t print_listint(const listint_t *h) 9 | { 10 | unsigned int count = 0; 11 | 12 | if (h == NULL) 13 | return (0); 14 | while (h != NULL) 15 | { 16 | printf("%d\n", h->n); 17 | count += 1; 18 | h = h->next; 19 | } 20 | return (count); 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/1-listint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * listint_len - This function return to the number of nudes 4 | * @h: This is my structure entry 5 | * Return: This return to the number the nodes 6 | * 7 | */ 8 | size_t listint_len(const listint_t *h) 9 | { 10 | unsigned int count = 0; 11 | 12 | if (h == NULL) 13 | return (0); 14 | while (h != NULL) 15 | { 16 | count += 1; 17 | h = h->next; 18 | } 19 | return (count); 20 | } 21 | 22 | 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/100-reverse_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * reverse_listint - Function that reverses a listint_t linked list 5 | * 6 | * @head: This is the input single linked list 7 | * 8 | * Return: Pointer to the first node of the reversed list 9 | */ 10 | 11 | listint_t *reverse_listint(listint_t **head) 12 | { 13 | listint_t *current = NULL; 14 | 15 | if (*head == NULL) 16 | return (NULL); 17 | if ((*head)->next == NULL) 18 | return (*head); 19 | while (*head != NULL) 20 | { 21 | listint_t *next; 22 | 23 | next = (*head)->next; 24 | (*head)->next = current; 25 | current = *head; 26 | *head = next; 27 | } 28 | *head = current; 29 | return (*head); 30 | } 31 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/2-add_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * add_nodeint - Creates a node and adds it to a linked list 4 | * @head: Pointer to head of the linked list 5 | * @n: Int to assigned to the node 6 | * Return: Pointer to the head of the linked list 7 | */ 8 | 9 | listint_t *add_nodeint(listint_t **head, const int n) 10 | { 11 | listint_t *new_node = (listint_t *) malloc(sizeof(listint_t)); 12 | 13 | if (new_node == NULL) 14 | return (NULL); 15 | new_node->n = n; 16 | new_node->next = (*head); 17 | (*head) = new_node; 18 | return (*head); 19 | } 20 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/3-add_nodeint_end.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * add_nodeint_end - Add a new node in the end of the node 5 | * @head: This is my struct 6 | * @n: This is the int take in my linked list. 7 | * Return: the address of the new element, or NULL if it failed. 8 | */ 9 | listint_t *add_nodeint_end(listint_t **head, const int n) 10 | { 11 | listint_t *new_node = (listint_t *) malloc(sizeof(listint_t)); 12 | listint_t *last = *head; 13 | 14 | if (new_node == NULL) 15 | { 16 | free(new_node); 17 | return (new_node); 18 | } 19 | new_node->n = n; 20 | new_node->next = NULL; 21 | if (*head == NULL) 22 | { 23 | *head = new_node; 24 | return (*head); 25 | } 26 | while (last->next != NULL) 27 | last = last->next; 28 | last->next = new_node; 29 | return (*head); 30 | } 31 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/4-free_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * free_listint - Free nodes and list 4 | * @head: This is my struct 5 | */ 6 | void free_listint(listint_t *head) 7 | { 8 | 9 | if (head == NULL) 10 | { 11 | return; 12 | } 13 | while (head != NULL) 14 | { 15 | listint_t *tmp; 16 | 17 | tmp = head; 18 | free(tmp); 19 | head = head->next; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-free_listint2.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * free_listint2 - Free nodes and list and set head to null 4 | * @head: This is my struct 5 | */ 6 | void free_listint2(listint_t **head) 7 | { 8 | 9 | if (head == NULL) 10 | { 11 | return; 12 | } 13 | while ((*head) != NULL) 14 | { 15 | listint_t *tmp; 16 | 17 | tmp = (*head); 18 | free(tmp); 19 | (*head) = (*head)->next; 20 | } 21 | (*head) = NULL; 22 | } 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/6-pop_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * pop_listint - deletes and returnes the head node's data 5 | * @head: This is my structures 6 | * Return: Return to head node's data(n) 7 | */ 8 | 9 | int pop_listint(listint_t **head) 10 | { 11 | listint_t *phead; 12 | int result; 13 | 14 | if (*head == NULL) 15 | return (0); 16 | result = (*head)->n; 17 | phead = *head; 18 | *head = (*head)->next; 19 | free(phead); 20 | return (result); 21 | } 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/7-get_nodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_nodeint_at_index - Function return to nth of the node 5 | * @head: THis is my structure 6 | * @index: This is my index 7 | * Return: This is the return 8 | */ 9 | 10 | listint_t *get_nodeint_at_index(listint_t *head, unsigned int index) 11 | { 12 | unsigned int count = 0; 13 | 14 | while (head != NULL) 15 | { 16 | if (count == index) 17 | return (head); 18 | count++; 19 | head = head->next; 20 | } 21 | return (NULL); 22 | } 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/8-sum_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_listint - Sum all head->n of this linked single list 5 | * @head: This is my linked list 6 | * Return: Return of the total of the sum 7 | */ 8 | int sum_listint(listint_t *head) 9 | { 10 | int sum = 0; 11 | 12 | if (head == NULL) 13 | return (0); 14 | 15 | while (head != NULL) 16 | { 17 | sum += head->n; 18 | head = head->next; 19 | } 20 | return (sum); 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | listint_t *new; 15 | listint_t hello = {8, NULL}; 16 | size_t n; 17 | 18 | head = &hello; 19 | new = malloc(sizeof(listint_t)); 20 | if (new == NULL) 21 | { 22 | printf("Error\n"); 23 | return (1); 24 | } 25 | new->n = 9; 26 | new->next = head; 27 | head = new; 28 | n = print_listint(head); 29 | printf("-> %lu elements\n", n); 30 | free(new); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | listint_t *new; 15 | listint_t hello = {8, NULL}; 16 | size_t n; 17 | 18 | head = &hello; 19 | new = malloc(sizeof(listint_t)); 20 | if (new == NULL) 21 | { 22 | printf("Error\n"); 23 | return (1); 24 | } 25 | new->n = 9; 26 | new->next = head; 27 | head = new; 28 | n = listint_len(head); 29 | printf("-> %lu elements\n", n); 30 | free(new); 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/100-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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint_end(&head, 0); 17 | add_nodeint_end(&head, 1); 18 | add_nodeint_end(&head, 2); 19 | add_nodeint_end(&head, 3); 20 | add_nodeint_end(&head, 4); 21 | add_nodeint_end(&head, 98); 22 | add_nodeint_end(&head, 402); 23 | add_nodeint_end(&head, 1024); 24 | print_listint(head); 25 | reverse_listint(&head); 26 | print_listint(head); 27 | free_listint2(&head); 28 | return (0); 29 | } 30 | 31 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint(&head, 0); 17 | add_nodeint(&head, 1); 18 | add_nodeint(&head, 2); 19 | add_nodeint(&head, 3); 20 | add_nodeint(&head, 4); 21 | add_nodeint(&head, 98); 22 | add_nodeint(&head, 402); 23 | add_nodeint(&head, 1024); 24 | print_listint(head); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint_end(&head, 0); 17 | add_nodeint_end(&head, 1); 18 | add_nodeint_end(&head, 2); 19 | add_nodeint_end(&head, 3); 20 | add_nodeint_end(&head, 4); 21 | add_nodeint_end(&head, 98); 22 | add_nodeint_end(&head, 402); 23 | add_nodeint_end(&head, 1024); 24 | print_listint(head); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint_end(&head, 0); 17 | add_nodeint_end(&head, 1); 18 | add_nodeint_end(&head, 2); 19 | add_nodeint_end(&head, 3); 20 | add_nodeint_end(&head, 4); 21 | add_nodeint_end(&head, 98); 22 | add_nodeint_end(&head, 402); 23 | add_nodeint_end(&head, 1024); 24 | print_listint(head); 25 | free_listint(head); 26 | head = NULL; 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint_end(&head, 0); 17 | add_nodeint_end(&head, 1); 18 | add_nodeint_end(&head, 2); 19 | add_nodeint_end(&head, 3); 20 | add_nodeint_end(&head, 4); 21 | add_nodeint_end(&head, 98); 22 | add_nodeint_end(&head, 402); 23 | add_nodeint_end(&head, 1024); 24 | print_listint(head); 25 | free_listint2(&head); 26 | printf("%p\n", (void *)head); 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | listint_t *node; 15 | 16 | head = NULL; 17 | add_nodeint_end(&head, 0); 18 | add_nodeint_end(&head, 1); 19 | add_nodeint_end(&head, 2); 20 | add_nodeint_end(&head, 3); 21 | add_nodeint_end(&head, 4); 22 | add_nodeint_end(&head, 98); 23 | add_nodeint_end(&head, 402); 24 | add_nodeint_end(&head, 1024); 25 | print_listint(head); 26 | node = get_nodeint_at_index(head, 5); 27 | printf("%d\n", node->n); 28 | print_listint(head); 29 | free_listint2(&head); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/8-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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | int sum; 15 | 16 | head = NULL; 17 | add_nodeint_end(&head, 0); 18 | add_nodeint_end(&head, 1); 19 | add_nodeint_end(&head, 2); 20 | add_nodeint_end(&head, 3); 21 | add_nodeint_end(&head, 4); 22 | add_nodeint_end(&head, 98); 23 | add_nodeint_end(&head, 402); 24 | add_nodeint_end(&head, 1024); 25 | sum = sum_listint(head); 26 | printf("sum = %d\n", sum); 27 | free_listint2(&head); 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/mains/9-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 0. 10 | */ 11 | int main(void) 12 | { 13 | listint_t *head; 14 | 15 | head = NULL; 16 | add_nodeint_end(&head, 0); 17 | add_nodeint_end(&head, 1); 18 | add_nodeint_end(&head, 2); 19 | add_nodeint_end(&head, 3); 20 | add_nodeint_end(&head, 4); 21 | add_nodeint_end(&head, 98); 22 | add_nodeint_end(&head, 402); 23 | add_nodeint_end(&head, 1024); 24 | print_listint(head); 25 | printf("-----------------\n"); 26 | insert_nodeint_at_index(&head, 5, 4096); 27 | print_listint(head); 28 | free_listint2(&head); 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/0-binary_to_uint.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * binary_to_uint - This funtion convert binary to decimal 4 | * @b: This is my string of entry 5 | * Return: This return to a digital number 6 | */ 7 | unsigned int binary_to_uint(const char *b) 8 | { 9 | unsigned int decimal = 0; 10 | int multiplicador = 1, index = 0; 11 | 12 | if (b == NULL) 13 | return (0); 14 | for (index = 0; b[index] != '\0'; index++) 15 | { 16 | if (b[index] != '0' && b[index] != '1') 17 | return (0); 18 | } 19 | for (index = index - 1; index >= 0; index--) 20 | { 21 | char currentCharacter; 22 | 23 | currentCharacter = b[index]; 24 | if (currentCharacter == '1') 25 | { 26 | decimal += multiplicador; 27 | } 28 | multiplicador = multiplicador * 2; 29 | if (index == 0) 30 | break; 31 | } 32 | return (decimal); 33 | } 34 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/1-print_binary.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_binary - prints the binary representation of a number 5 | * @n: number 6 | */ 7 | void print_binary(unsigned long int n) 8 | { 9 | if (n > 1) 10 | print_binary(n >> 1); 11 | 12 | _putchar((n & 1) + '0'); 13 | } 14 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-get_bit.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x14-bit_manipulation/2-get_bit.c -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-set_bit.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x14-bit_manipulation/3-set_bit.c -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-clear_bit.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x14-bit_manipulation/4-clear_bit.c -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-flip_bits.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x14-bit_manipulation/5-flip_bits.c -------------------------------------------------------------------------------- /0x14-bit_manipulation/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | #include 5 | #include 6 | #include 7 | unsigned int binary_to_uint(const char *b); 8 | void print_binary(unsigned long int n); 9 | int _putchar(char c); 10 | #endif 11 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | unsigned int n; 12 | 13 | n = binary_to_uint("1"); 14 | printf("%u\n", n); 15 | n = binary_to_uint("101"); 16 | printf("%u\n", n); 17 | n = binary_to_uint("1e01"); 18 | printf("%u\n", n); 19 | n = binary_to_uint("1100010"); 20 | printf("%u\n", n); 21 | n = binary_to_uint("0000000000000000000110010010"); 22 | printf("%u\n", n); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | print_binary(0); 12 | printf("\n"); 13 | print_binary(1); 14 | printf("\n"); 15 | print_binary(98); 16 | printf("\n"); 17 | print_binary(1024); 18 | printf("\n"); 19 | print_binary((1 << 10) + 1); 20 | printf("\n"); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x15-file_io/1-create_file.c: -------------------------------------------------------------------------------- 1 | 2 | #include "holberton.h" 3 | 4 | /** 5 | * create_file - Create a new files 6 | * @filename: Name of the file 7 | * @text_content: Content of the file 8 | * Return: Success is 1, and if failed is -1 9 | */ 10 | int create_file(const char *filename, char *text_content) 11 | { 12 | int fd; 13 | 14 | if (filename == NULL) 15 | return (-1); 16 | 17 | fd = open(filename, O_CREAT | O_WRONLY | O_TRUNC, 0600); 18 | 19 | if (fd == -1) 20 | return (-1); 21 | if (text_content != NULL) 22 | { 23 | int lenWrite, len_Text; 24 | 25 | for (len_Text = 0; text_content[len_Text] != '\0'; len_Text++) 26 | ; 27 | lenWrite = write(fd, text_content, (len_Text)); 28 | if (lenWrite == -1) 29 | { 30 | close(fd); 31 | return (-1); 32 | } 33 | } 34 | close(fd); 35 | return (1); 36 | } 37 | -------------------------------------------------------------------------------- /0x15-file_io/2-append_text_to_file.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * append_text_to_file - That appends text at the end of a file. 4 | * @filename: THis is the name of the file 5 | * @text_content: This the string to append to text 6 | * 7 | * Return: 1 if is success and if not is -1 8 | */ 9 | int append_text_to_file(const char *filename, char *text_content) 10 | { 11 | int fd; 12 | 13 | fd = open(filename, O_RDWR | O_APPEND); 14 | if (fd == -1) 15 | return (-1); 16 | if (text_content != NULL) 17 | { 18 | int len_Text, lenWrite; 19 | 20 | for (len_Text = 0; text_content[len_Text] != '\0'; len_Text++) 21 | ; 22 | lenWrite = write(fd, text_content, len_Text); 23 | 24 | if (lenWrite == -1) 25 | { 26 | close(fd); 27 | return (-1); 28 | } 29 | } 30 | close(fd); 31 | return (1); 32 | } 33 | -------------------------------------------------------------------------------- /0x15-file_io/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | ssize_t read_textfile(const char *filename, size_t letters); 10 | int create_file(const char *filename, char *text_content); 11 | int append_text_to_file(const char *filename, char *text_content); 12 | #endif 13 | -------------------------------------------------------------------------------- /0x15-file_io/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "holberton.h" 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char **av) 11 | { 12 | ssize_t n; 13 | 14 | if (ac != 2) 15 | { 16 | dprintf(2, "Usage: %s filename\n", av[0]); 17 | exit(1); 18 | } 19 | n = read_textfile(av[1], 114); 20 | printf("\n(printed chars: %li)\n", n); 21 | n = read_textfile(av[1], 1024); 22 | printf("\n(printed chars: %li)\n", n); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x15-file_io/mains/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "holberton.h" 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char **av) 11 | { 12 | int res; 13 | 14 | if (ac != 3) 15 | { 16 | dprintf(2, "Usage: %s filename text\n", av[0]); 17 | exit(1); 18 | } 19 | res = create_file(av[1], av[2]); 20 | printf("-> %i)\n", res); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x15-file_io/mains/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "holberton.h" 4 | 5 | /** 6 | * main - check the code for Holberton School students. 7 | * 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char **av) 11 | { 12 | int res; 13 | 14 | if (ac != 3) 15 | { 16 | dprintf(2, "Usage: %s filename text\n", av[0]); 17 | exit(1); 18 | } 19 | res = append_text_to_file(av[1], av[2]); 20 | printf("-> %i)\n", res); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x15-file_io/mains/Requiescat: -------------------------------------------------------------------------------- 1 | Requiescat 2 | by Oscar Wilde 3 | 4 | Tread lightly, she is near 5 | Under the snow, 6 | Speak gently, she can hear 7 | The daisies grow. 8 | 9 | All her bright golden hair 10 | Tarnished with rust, 11 | She that was young and fair 12 | Fallen to dust. 13 | 14 | Lily-like, white as snow, 15 | She hardly knew 16 | She was a woman, so 17 | Sweetly she grew. 18 | 19 | Coffin-board, heavy stone, 20 | Lie on her breast, 21 | I vex my heart alone, 22 | She is at rest. 23 | 24 | Peace, Peace, she cannot hear 25 | Lyre or sonnet, 26 | All my life's buried here, 27 | Heap earth upon it. 28 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/0-print_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * print_dlistint -Function that prints all the elements of a double list link 4 | * 5 | * @h: This is the input struct 6 | * 7 | * Return: Number of the element of the struct 8 | */ 9 | size_t print_dlistint(const dlistint_t *h) 10 | { 11 | int count = 0; 12 | 13 | if (h == NULL) 14 | return (0); 15 | 16 | while (h != NULL) 17 | { 18 | printf("%d\n", h->n); 19 | h = h->next; 20 | count++; 21 | } 22 | return (count); 23 | } 24 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/1-dlistint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * dlistint_len - Function that returns the number of elements in a 5 | * double list linked 6 | * 7 | * @h: This is the input struct 8 | * 9 | * Return: Number of the element of the struct 10 | * 11 | */ 12 | 13 | size_t dlistint_len(const dlistint_t *h) 14 | { 15 | int count = 0; 16 | 17 | if (h == NULL) 18 | return (0); 19 | 20 | while (h != NULL) 21 | { 22 | h = h->next; 23 | count++; 24 | } 25 | return (count); 26 | } 27 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/2-add_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * add_dnodeint - Write a function that adds a new node at the beginning of a 4 | * dlistint_t list. 5 | * 6 | * @head: This is the input Struct 7 | * @n: This is the input number 8 | * 9 | * Return: The address of the new element, or NULL if it failed 10 | * 11 | */ 12 | 13 | dlistint_t *add_dnodeint(dlistint_t **head, const int n) 14 | { 15 | 16 | dlistint_t *new_node = (dlistint_t *)malloc(sizeof(dlistint_t)); 17 | 18 | if (new_node == NULL) 19 | return (NULL); 20 | new_node->n = n; 21 | 22 | new_node->next = (*head); 23 | new_node->prev = NULL; 24 | 25 | if ((*head) != NULL) 26 | (*head)->prev = new_node; 27 | (*head) = new_node; 28 | return (*head); 29 | } 30 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/4-free_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_dlistint - Function that frees a double list linked. 5 | * @head: This is the double linked list 6 | */ 7 | 8 | void free_dlistint(dlistint_t *head) 9 | { 10 | dlistint_t *current = head; 11 | 12 | while (current != NULL) 13 | { 14 | dlistint_t *next = current->next; 15 | 16 | free(current); 17 | current = next; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/5-get_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_dnodeint_at_index - Write a function that returns the nth node of a 5 | * dlistint_t linked list. 6 | * 7 | * @head: THis is the input structure 8 | * @index: This is the input index 9 | * 10 | * Return: This is the return 11 | */ 12 | 13 | dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index) 14 | { 15 | unsigned int count = 0; 16 | 17 | while (head != NULL) 18 | { 19 | if (count == index) 20 | return (head); 21 | count++; 22 | head = head->next; 23 | } 24 | return (NULL); 25 | } 26 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/6-sum_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_dlistint - Write a function that returns the sum of all the data (n) 5 | * of a dlistint_t linked list.) 6 | * 7 | * @head: This is the input double linked list 8 | * 9 | * Return: Return of the total of the sum each position if if the list is 10 | * empty, return 0 11 | * 12 | */ 13 | 14 | int sum_dlistint(dlistint_t *head) 15 | { 16 | int sum = 0; 17 | 18 | if (head == NULL) 19 | return (0); 20 | 21 | while (head != NULL) 22 | { 23 | sum += head->n; 24 | head = head->next; 25 | } 26 | return (sum); 27 | } 28 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/mains/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/mains/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/mains/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/mains/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/mains/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/mains/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/mains/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 | 12 | int main(void) 13 | { 14 | dlistint_t *head; 15 | int sum; 16 | 17 | head = NULL; 18 | add_dnodeint_end(&head, 0); 19 | add_dnodeint_end(&head, 1); 20 | add_dnodeint_end(&head, 2); 21 | add_dnodeint_end(&head, 3); 22 | add_dnodeint_end(&head, 4); 23 | add_dnodeint_end(&head, 98); 24 | add_dnodeint_end(&head, 402); 25 | add_dnodeint_end(&head, 1024); 26 | sum = sum_dlistint(head); 27 | printf("sum = %d\n", sum); 28 | free_dlistint(head); 29 | head = NULL; 30 | return (EXIT_SUCCESS); 31 | } 32 | 33 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-create_dynamic_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -fPIC -c *.c && gcc -shared -o liball.so *.o 3 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/100-operations.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_FILE 2 | #define HEADER_FILE 3 | 4 | int _putchar(char c); 5 | int _islower(int c); 6 | int _isalpha(int c); 7 | int _abs(int n); 8 | int _isupper(int c); 9 | int _isdigit(int c); 10 | int _strlen(char *s); 11 | void _puts(char *s); 12 | char *_strcpy(char *dest, char *src); 13 | int _atoi(char *s); 14 | char *_strcat(char *dest, char *src); 15 | char *_strncat(char *dest, char *src, int n); 16 | char *_strncpy(char *dest, char *src, int n); 17 | int _strcmp(char *s1, char *s2); 18 | char *_memset(char *s, char b, unsigned int n); 19 | char *_memcpy(char *dest, char *src, unsigned int n); 20 | char *_strchr(char *s, char c); 21 | unsigned int _strspn(char *s, char *accept); 22 | char *_strpbrk(char *s, char *accept); 23 | char *_strstr(char *haystack, char *needle); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/liball.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/liball.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/libholberton.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/libholberton.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - If is uppercase return 1, if not return 0 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isupper(int c) 12 | { 13 | if (c >= 'A' && c <= 'Z') 14 | { 15 | return (1); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/0-isupper.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always EXIT_SUCCESS. 8 | */ 9 | int main(void) 10 | { 11 | printf("%d\n", _strlen("Holberton")); 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/0-main.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - Write a function that fills memory with a constant byte 5 | * The _memset() function fills the first n bytes of the memory area pointed to 6 | * by s with the constant byte b 7 | * 8 | * @s: This is the output and the return 9 | * @b: This is the this is the input string 10 | * @n: This is the number of bytes 11 | * 12 | * Return: A pointer to the memory area s 13 | */ 14 | char *_memset(char *s, char b, unsigned int n) 15 | { 16 | unsigned int count; 17 | 18 | for (count = 0; count < n ; count++) 19 | { 20 | s[count] = b; 21 | } 22 | return (s); 23 | } 24 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/0-memset.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_strcat - Write a function that concatenates two strings. 5 | *@dest: This is the output dest 6 | *@src: This is the input source 7 | * 8 | * Return: This return to dest, that concatenates two strings 9 | */ 10 | 11 | char *_strcat(char *dest, char *src) 12 | { 13 | int i, j; 14 | 15 | for (i = 0; dest[i] != '\0'; i++) 16 | ; 17 | for (j = 0; src[j] != '\0'; j++) 18 | { 19 | dest[i] = src[j]; 20 | i++; 21 | } 22 | return (dest); 23 | } 24 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/0-strcat.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - If is 0 to 9 return 1, if not return 0, function check a digit 5 | * 6 | * @c: this is the entry 7 | * 8 | * Return: 0 9 | * 10 | **/ 11 | int _isdigit(int c) 12 | { 13 | if (c >= '0' && c <= '9') 14 | { 15 | return (1); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/1-isdigit.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - Write a function that copies memory area. 5 | * The _memcpy() function copies n bytes from memory area src to memory area 6 | * dest 7 | * 8 | * @dest: This is the output string 9 | * @src: This is my input string 10 | * @n: This is the number bytes to copy 11 | * 12 | * Return: This is the string copied 13 | */ 14 | 15 | char *_memcpy(char *dest, char *src, unsigned int n) 16 | { 17 | unsigned int count; 18 | char *pDst = dest; 19 | char const *pSrc = src; 20 | 21 | for (count = 0; count < n; count++) 22 | { 23 | *pDst++ = *pSrc++; 24 | } 25 | return (dest); 26 | } 27 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/1-memcpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strncat - Write a function that concatenates two strings. it will use at 5 | * most n bytes from src 6 | * 7 | * @dest: This is the output dest 8 | * @src: This is the input src 9 | * @n: This is the number bytes fro src 10 | * 11 | * Return: This is my return 12 | */ 13 | char *_strncat(char *dest, char *src, int n) 14 | { 15 | int index, count; 16 | 17 | for (index = 0; dest[index] != '\0'; index++) 18 | ; 19 | for (count = 0; count < n && src[count] != '\0'; count++) 20 | { 21 | dest[index] = src[count]; 22 | index++; 23 | } 24 | if (count < n) 25 | { 26 | dest[index] = '\0'; 27 | } 28 | return (dest); 29 | } 30 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/1-strncat.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/100-atoi.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strchr - Function that locates a character in a string 5 | * @s: This is the input string 6 | * @c: This is the character 7 | * Return: Return to the character found, if not return a NULL 8 | */ 9 | char *_strchr(char *s, char c) 10 | { 11 | for (; ; s++) 12 | { 13 | if (*s == c) 14 | return (s); 15 | if (*s == 0) 16 | return (NULL); 17 | } 18 | return (NULL); 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/2-strchr.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - Function that returns the length of a string 5 | * 6 | * @s: this is the input string 7 | * 8 | * Return: Lenngth of the string 9 | */ 10 | int _strlen(char *s) 11 | { 12 | int index; 13 | 14 | for (index = 0; s[index] != '\0' ; index++) 15 | ; 16 | return (index); 17 | } 18 | 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/2-strlen.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strncpy - Write a function that copies a string, with number of bytes 4 | * @dest: This is the output dest 5 | * @src: This is the input source 6 | * @n: This is the number of bytes to copy 7 | * 8 | *Return: Copied string with the number of bytes 9 | */ 10 | 11 | char *_strncpy(char *dest, char *src, int n) 12 | { 13 | int index; 14 | 15 | for (index = 0; index < n && src[index] != '\0' ; index++) 16 | { 17 | dest[index] = src[index]; 18 | } 19 | for (; index < n; index++) 20 | { 21 | dest[index] = '\0'; 22 | } 23 | return (dest); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/2-strncpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check if the entry is in lower. 5 | * @c: This is the entry 6 | * 7 | * Return: Always 0. 8 | */ 9 | 10 | int _islower(int c) 11 | { 12 | if (c >= 'a' && c <= 'z') 13 | { 14 | return (1); 15 | } 16 | else 17 | { 18 | return (0); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/3-islower.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed by a new line, to 5 | * stdout. 6 | * 7 | * @str: This is my input string 8 | * 9 | */ 10 | 11 | void _puts(char *str) 12 | { 13 | int index; 14 | 15 | for (index = 0; str[index] != '\0'; index++) 16 | { 17 | _putchar(str[index]); 18 | } 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/3-puts.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcmp - Write a function that compares two strings. 4 | * 5 | * @s1: This is the input string 6 | * @s2: This is the input string 7 | * 8 | * Return: If the strings are equals return "0", if not return other number 9 | */ 10 | 11 | int _strcmp(char *s1, char *s2) 12 | { 13 | for (; (*s1 != '\0' && *s2 != '\0') && (*s1 == *s2); s1++, s2++) 14 | ; 15 | if (*s1 == *s2) 16 | { 17 | return (0); 18 | } 19 | return (*s1 - *s2); 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/3-strcmp.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strspn - Function that gets the length of a prefix substring 4 | * @s: This is the string literal 5 | * @accept: This is the second string 6 | * 7 | * Return: number of bytes in the initial segment of s which consist only of 8 | * bytes from accept 9 | */ 10 | 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int index, j, counter; 14 | 15 | counter = 0; 16 | for (index = 0; s[index] != '\0'; index++) 17 | { 18 | for (j = 0; accept[j] != '\0'; j++) 19 | { 20 | if (accept[j] == s[index]) 21 | { 22 | counter++; 23 | break; 24 | } 25 | } 26 | if (accept[j] != s[index]) 27 | { 28 | break; 29 | } 30 | } 31 | return (counter); 32 | } 33 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/3-strspn.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/4-isalpha.c: -------------------------------------------------------------------------------- 1 | 2 | #include "holberton.h" 3 | 4 | /** 5 | * _isalpha - check the the entry to deteminate if is lower or upper 6 | * 7 | * @c: This is the entry 8 | * Return: Always 0. 9 | */ 10 | 11 | int _isalpha(int c) 12 | { 13 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 14 | { 15 | return (1); 16 | } 17 | else 18 | { 19 | return (0); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/4-isalpha.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/4-strpbrk.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _strstr - Write a function that locates a substring. 5 | * 6 | * @haystack: This is the input string 7 | * @needle: This is a find to locate in the string 8 | * 9 | * Return: a pointer to the beginning of the located substring, or NULL if the 10 | * substring is not found. 11 | */ 12 | 13 | char *_strstr(char *haystack, char *needle) 14 | { 15 | char *temp; 16 | 17 | while (*haystack) 18 | { 19 | temp = haystack; 20 | while (*needle == *haystack) 21 | { 22 | haystack++, needle++; 23 | } 24 | if (*needle == '\0') 25 | return (temp); 26 | haystack++; 27 | } 28 | return (0); 29 | } 30 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/5-strstr.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _abs - This is a absolute value 5 | * 6 | * @a: This is the entry 7 | * 8 | * Return: Always 0. 9 | */ 10 | 11 | int _abs(int a) 12 | { 13 | if (a > 0) 14 | { 15 | return (a); 16 | } 17 | else if (a < 0) 18 | { 19 | a = a * -1; 20 | return (a); 21 | } 22 | else 23 | { 24 | return (a); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/6-abs.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcpy - Copiar el contenido de uno a otra variable 5 | * @dest: This is destiny 6 | * @src: This is the copia 7 | * 8 | * Return: This return copy 9 | */ 10 | char *_strcpy(char *dest, char *src) 11 | { 12 | char *start = dest; 13 | 14 | while (*src != '\0') 15 | { 16 | *dest = *src; 17 | dest++; 18 | src++; 19 | } 20 | *dest = '\0'; 21 | return (start); 22 | } 23 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/9-strcpy.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/_putchar.o -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/functiones.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) 2 | { 3 | return a + b; 4 | } 5 | int sub(int a, int b) 6 | { 7 | return a - b; 8 | } 9 | int div(int a, int b) 10 | { 11 | return a / b; 12 | } 13 | int mul(int a, int b) 14 | { 15 | return a * b; 16 | } 17 | int mod(int a, int b) 18 | { 19 | return a % b; 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/mains/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x18-dynamic_libraries/mains/main -------------------------------------------------------------------------------- /0x1A-hash_tables/0-hash_table_create.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | /** 3 | * hash_table_create - function to create a hash 4 | * table 5 | * @size: is the size of the array 6 | * Return: pointer to the newly creted hash table 7 | **/ 8 | hash_table_t *hash_table_create(unsigned long int size) 9 | { 10 | hash_table_t *new_hash_table = NULL; 11 | 12 | if (size > 0) 13 | { 14 | new_hash_table = malloc(sizeof(hash_table_t)); 15 | if (new_hash_table == NULL) 16 | { 17 | return (NULL); 18 | } 19 | 20 | new_hash_table->array = calloc(size, sizeof(hash_node_t *)); 21 | if (new_hash_table->array == NULL) 22 | { 23 | free(new_hash_table); 24 | return (NULL); 25 | } 26 | new_hash_table->size = size; 27 | return (new_hash_table); 28 | } 29 | return (NULL); 30 | } 31 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-djb2.c: -------------------------------------------------------------------------------- 1 | /** 2 | * hash_djb2 - implementation of the djb2 algorithm 3 | * @str: string used to generate hash value 4 | * 5 | * Return: hash value 6 | */ 7 | unsigned long int hash_djb2(const unsigned char *str) 8 | { 9 | unsigned long int hash; 10 | int c; 11 | 12 | hash = 5381; 13 | while ((c = *str++)) 14 | { 15 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 16 | } 17 | return (hash); 18 | } 19 | -------------------------------------------------------------------------------- /0x1A-hash_tables/2-key_index.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * key_index - Write a function that gives you the index of a key. 5 | * 6 | * @key: key is the key 7 | * @size: is the size of the array of the hash table 8 | * 9 | * Return: Returns the index at which the key/value pair shoud 10 | * be stored in the array of the hash table 11 | */ 12 | unsigned long int key_index(const unsigned char *key, unsigned long int size) 13 | { 14 | unsigned long int preHash = hash_djb2(key); 15 | 16 | return (preHash % size); 17 | } 18 | -------------------------------------------------------------------------------- /0x1A-hash_tables/5-hash_table_print.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | /** 3 | * hash_table_print - prints a hash table 4 | * @ht: hash table 5 | * Return: void 6 | **/ 7 | void hash_table_print(const hash_table_t *ht) 8 | { 9 | unsigned long int i; 10 | int first_element = 0; 11 | hash_node_t *ptr; 12 | 13 | if (ht == NULL) 14 | return; 15 | 16 | printf("{"); 17 | for (i = 0; i < ht->size; i++) 18 | { 19 | if (ht->array[i]) 20 | { 21 | ptr = ht->array[i]; 22 | while (ptr) 23 | { 24 | if (first_element == 0) 25 | { 26 | printf("'%s': '%s'", ptr->key, ptr->value); 27 | first_element += 1; 28 | } 29 | else 30 | printf(", '%s': '%s'", ptr->key, ptr->value); 31 | ptr = ptr->next; 32 | } 33 | } 34 | } 35 | printf("}\n"); 36 | } 37 | -------------------------------------------------------------------------------- /0x1A-hash_tables/6-hash_table_delete.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | /** 3 | * hash_table_delete - prints a hash table 4 | * @ht: hash table 5 | * Return: void 6 | **/ 7 | void hash_table_delete(hash_table_t *ht) 8 | { 9 | unsigned long int i; 10 | hash_node_t *temp; 11 | 12 | if (ht == NULL) 13 | return; 14 | 15 | for (i = 0; i < ht->size; i++) 16 | { 17 | if (ht->array[i]) 18 | { 19 | while (ht->array[i]) 20 | { 21 | temp = ht->array[i]; 22 | 23 | free(temp->key); 24 | free(temp->value); 25 | free(temp); 26 | ht->array[i] = ht->array[i]->next; 27 | } 28 | } 29 | } 30 | free(ht->array); 31 | free(ht); 32 | } 33 | -------------------------------------------------------------------------------- /0x1A-hash_tables/mains/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/mains/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, "Bob", "and Kris 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 | #The objective is compiler the program called holberton.c 2 | all: holberton 3 | 4 | holberton: main.c holberton.c 5 | gcc main.c holberton.c -o holberton 6 | 7 | -------------------------------------------------------------------------------- /0x1C-makefiles/1-Makefile: -------------------------------------------------------------------------------- 1 | #The objective is compiler the program called holberton.c with variables 2 | CC=gcc 3 | SRC=main.c holberton.c 4 | all: 5 | $(CC) $(SRC) -o holberton 6 | -------------------------------------------------------------------------------- /0x1C-makefiles/2-Makefile: -------------------------------------------------------------------------------- 1 | #Declartion of variables 2 | 3 | CC=gcc 4 | SRC=holberton.c main.c 5 | OBJ=$(SRC:.c=.o) 6 | NAME=holberton 7 | 8 | all: $(OBJ) 9 | $(CC) $(OBJ) -o $(NAME) 10 | -------------------------------------------------------------------------------- /0x1C-makefiles/3-Makefile: -------------------------------------------------------------------------------- 1 | #Declartion of variables 2 | 3 | CC=gcc 4 | SRC=holberton.c main.c 5 | OBJ=$(SRC:.c=.o) 6 | NAME=holberton 7 | RM=rm 8 | 9 | all: $(OBJ) 10 | $(CC) $(OBJ) -o $(NAME) 11 | 12 | clean: 13 | $(RM) -f *~ $(NAME) 14 | 15 | oclean: 16 | $(RM) -f $(OBJ) 17 | 18 | fclean: clean oclean 19 | 20 | re: oclean all 21 | -------------------------------------------------------------------------------- /0x1C-makefiles/4-Makefile: -------------------------------------------------------------------------------- 1 | #Declartion of variables 2 | 3 | CC=gcc 4 | SRC=holberton.c main.c 5 | OBJ=$(SRC:.c=.o) 6 | NAME=holberton 7 | RM=rm 8 | CFLAGS=-Wall -Werror -Wextra -pedantic 9 | 10 | all: $(OBJ) 11 | $(CC) $(OBJ) -o $(NAME) 12 | 13 | clean: 14 | $(RM) -f *~ $(NAME) 15 | 16 | oclean: 17 | $(RM) -f $(OBJ) 18 | 19 | fclean: clean oclean 20 | 21 | re: oclean all 22 | -------------------------------------------------------------------------------- /0x1C-makefiles/5-island_perimeter.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | Thechincal interview preparation 4 | This module that returns the perimeter of the island describ in grid 5 | """ 6 | 7 | 8 | def island_perimeter(grid): 9 | """ THis functions returns the 10 | perimeter of the island described in grid """ 11 | perimeter = 0 12 | for i, row in enumerate(grid): 13 | for j, col in enumerate(row): 14 | if grid[i][j] == 1: 15 | perimeter = perimeter + 4 16 | if i > 0 and grid[i-1][j] == 1: 17 | perimeter = perimeter - 2 18 | if j > 0 and grid[i][j-1] == 1: 19 | perimeter = perimeter - 2 20 | return perimeter 21 | -------------------------------------------------------------------------------- /0x1C-makefiles/holberton: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x1C-makefiles/holberton -------------------------------------------------------------------------------- /0x1C-makefiles/m.h: -------------------------------------------------------------------------------- 1 | #ifndef __M_H__ 2 | #define __M_H__ 3 | 4 | #include 5 | #include 6 | 7 | void print_holberton(void); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x1C-makefiles/main.c: -------------------------------------------------------------------------------- 1 | #include "m.h" 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 7 | */ 8 | int main(void) 9 | { 10 | print_holberton(); 11 | return (EXIT_SUCCESS); 12 | } 13 | /* Holberton */ 14 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/1-binary: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x1E-search_algorithms/1-binary -------------------------------------------------------------------------------- /0x1E-search_algorithms/101-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/104-advanced_binary: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x1E-search_algorithms/104-advanced_binary -------------------------------------------------------------------------------- /0x1E-search_algorithms/105-jump: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x1E-search_algorithms/105-jump -------------------------------------------------------------------------------- /0x1E-search_algorithms/105-jump_list.c: -------------------------------------------------------------------------------- 1 | #include "search_algos.h" 2 | #include 3 | 4 | listint_t *jump_list(listint_t *list, size_t size, int value) 5 | { 6 | // size_t end = sqrt(size), 7 | size_t start, i = 1; 8 | listint_t *temp = list; 9 | if (list == NULL || size == 0) 10 | return NULL; 11 | while(list != NULL && list->next != NULL) 12 | { 13 | printf("%d-----%zu\n", list->n, i); 14 | printf("%p-----%p\n", (void*)(list), (void *)(list)->(&(next[2]))); 15 | 16 | list = &(list)->next[0]; 17 | i = i * 2; 18 | 19 | } 20 | return list; 21 | (void)temp; 22 | (void)size; 23 | // (void)end; 24 | (void)i; 25 | (void)start; 26 | (void)value; 27 | } 28 | -------------------------------------------------------------------------------- /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/README.md: -------------------------------------------------------------------------------- 1 | Doing the web 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 | 12 | if (list) 13 | { 14 | listint_t *node; 15 | 16 | node = list->next; 17 | free(list); 18 | free_list(node); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/listint/print_list.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "search_algos.h" 3 | /** 4 | * print_list - Prints the content of a listint_t 5 | * 6 | * @list: Pointer to the head of the list 7 | */ 8 | void print_list(const listint_t *list) 9 | { 10 | printf("List :\n"); 11 | while (list) 12 | { 13 | printf("Index[%zu] = [%d]\n", list->index, list->n); 14 | list = list->next; 15 | } 16 | printf("\n"); 17 | } 18 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/mains/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/mains/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/mains/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/mains/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/mains/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\n", 999, exponential_search(array, size, 999)); 20 | printf("Found %d at index: %d\n", -2, exponential_search(array, size, -2)); 21 | return (EXIT_SUCCESS); 22 | } 23 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/mains/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 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/testing: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AndresSern/holbertonschool-low_level_programming/1dcbc3e47e413d305b733f54b1c8a958fc257604/0x1E-search_algorithms/testing --------------------------------------------------------------------------------