├── 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 ├── HelloC.c ├── README.md ├── a.out ├── c ├── main.c ├── main.o ├── main.s ├── q ├── quote ├── size32 └── size64 ├── 0x01-variables_if_else_while ├── 0-positive_or_negative ├── 0-positive_or_negative.c ├── 1-last_digit ├── 1-last_digit.c ├── 10-print_comb2 ├── 10-print_comb2.c ├── 100-print_comb3 ├── 100-print_comb3.c ├── 101-print_comb4 ├── 101-print_comb4.c ├── 102-print_comb5 ├── 102-print_comb5.c ├── 2-print_alphabet ├── 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 ├── 0-holberton.c ├── 1-alphabet ├── 1-alphabet.c ├── 1-main.c ├── 10-add ├── 10-add.c ├── 10-main.c ├── 100-main.c ├── 100-times_table ├── 100-times_table.c ├── 100-times_table.co ├── 101-natural ├── 101-natural.c ├── 102-fibonacci ├── 102-fibonacci.c ├── 103-fibonacci ├── 103-fibonacci.c ├── 11-98 ├── 11-main.c ├── 11-print_to_98.c ├── 2-alphabet_x10 ├── 2-main.c ├── 2-print_alphabet_x10.c ├── 3-islower ├── 3-islower.c ├── 3-main.c ├── 4-isalpha ├── 4-isalpha.c ├── 4-main.c ├── 5-main.c ├── 5-sign ├── 5-sign.c ├── 6-abs ├── 6-abs.c ├── 6-main.c ├── 7-last_digit ├── 7-main.c ├── 7-print_last_digit.c ├── 8-24 ├── 8-24_hours.c ├── 8-main.c ├── 8-main.c~ ├── 9-main.c ├── 9-main.c~ ├── 9-times_table ├── 9-times_table.c ├── README.md ├── _putchar.c ├── ejemplo ├── ejemplo.c └── holberton.h ├── 0x03-debugging ├── 0-main ├── 0-main.c ├── 1-main.c ├── 2-largest_number.c ├── 3-print_remaining_days.c ├── README.md ├── holberton.h ├── positive_or_negative.c └── positive_or_negative.c~ ├── 0x04-more_functions_nested_loops ├── 0-isuper ├── 0-isupper.c ├── 0-main.c ├── 1-isdigit ├── 1-isdigit.c ├── 1-main.c ├── 10-main.c ├── 10-main.c~ ├── 10-print_triangle.c ├── 10-triangles ├── 100-prime_factor ├── 100-prime_factor.c ├── 101-main.c ├── 101-print_number.c ├── 101-print_numbers ├── 2-main.c ├── 2-mul ├── 2-mul.c ├── 3-main.c ├── 3-print_numbers ├── 3-print_numbers.c ├── 4-main.c ├── 4-print_most_numbers ├── 4-print_most_numbers.c ├── 5-main.c ├── 5-more_numbers ├── 5-more_numbers.c ├── 6-lines ├── 6-main.c ├── 6-print_line.c ├── 7-diagonals ├── 7-main.c ├── 7-print_diagonal.c ├── 8-main.c ├── 8-print_square.c ├── 8-squares ├── 9-fizz_buzz ├── 9-fizz_buzz.c ├── README.md ├── _putchar.c └── holberton.h ├── 0x05-pointers_arrays_strings ├── + ├── 0-98 ├── 0-main.c ├── 0-reset_to_98.c ├── 1-main.c ├── 1-swap ├── 1-swap.c ├── 100-atoi.c ├── 100-main.c ├── 2-main.c ├── 2-strlen ├── 2-strlen.c ├── 3-main.c ├── 3-puts ├── 3-puts.c ├── 4-main.c ├── 4-print_rev ├── 4-print_rev.c ├── 4-print_rev1 ├── 4-print_rev1.c ├── 5-main.c ├── 5-rev_string ├── 5-rev_string.c ├── 5-rev_string1.c ├── 6-main.c ├── 6-puts2 ├── 6-puts2.c ├── 7-main.c ├── 7-puts_half ├── 7-puts_half.c ├── 8-main.c ├── 8-print_array ├── 8-print_array.c ├── 9-main.c ├── 9-main.c~ ├── 9-strcpy ├── 9-strcpy.c ├── README.md ├── _putchar.c └── holberton.h ├── 0x06-pointers_arrays_strings ├── 0-main.c ├── 0-strcat ├── 0-strcat.c ├── 1-main.c ├── 1-strncat ├── 1-strncat.c ├── 100-main.c ├── 100-print_number.c ├── 100-print_numbers ├── 101-magic ├── 101-magic.c ├── 2-main.c ├── 2-strncpy ├── 2-strncpy.c ├── 3-main.c ├── 3-strcmp ├── 3-strcmp.c ├── 4-main.c ├── 4-rev_array ├── 4-rev_array.c ├── 5-main.c ├── 5-string_toupper ├── 5-string_toupper.c ├── 6-cap ├── 6-cap_string.c ├── 6-main.c ├── 7-1337 ├── 7-leet.c ├── 7-main.c ├── 8-main.c ├── 8-rot13 ├── 8-rot13.c ├── README.md ├── _putchar.c └── holberton.h ├── 0x07-pointers_arrays_strings ├── 0-main.c ├── 0-memset ├── 0-memset.c ├── 1-main.c ├── 1-memcpy ├── 1-memcpy.c ├── 101-crackme_password ├── 2-main.c ├── 2-strchr ├── 2-strchr.c ├── 3-main.c ├── 3-strspn ├── 3-strspn.c ├── 4-main.c ├── 4-strpbrk ├── 4-strpbrk.c ├── 5-main.c ├── 5-strstr ├── 5-strstr.c ├── 7-main.c ├── 7-print_chessboard ├── 7-print_chessboard.c ├── 8-main.c ├── 8-print_diagsums ├── 8-print_diagsums.c ├── 9-main.c ├── 9-set_string ├── 9-set_string.c ├── README.md ├── _putchar.c ├── holberton.h └── holberton.h~ ├── 0x08-recursion ├── 0-main.c ├── 0-puts_recursion ├── 0-puts_recursion.c ├── 1-main.c ├── 1-print_rev_recursion ├── 1-print_rev_recursion.c ├── 100-main.c ├── 100-wildcmp ├── 100-wildcmp.c ├── 2-main.c ├── 2-strlen_recursion ├── 2-strlen_recursion.c ├── 3-factorial ├── 3-factorial.c ├── 3-main.c ├── 4-main.c ├── 4-pow ├── 4-pow_recursion.c ├── 5-main.c ├── 5-sqrt ├── 5-sqrt_recursion.c ├── 6-is_prime_number.c ├── 6-main.c ├── 6-prime ├── 7-is_palindrome.c ├── 7-main.c ├── 7-palindrome ├── README.md ├── _putchar.c ├── holberton.h └── holberton.h.gch ├── 0x09-static_libraries ├── 0-isupper.c ├── 0-isupper.o ├── 0-memset.c ├── 0-memset.o ├── 0-strcat.c ├── 0-strcat.o ├── 1-isdigit.c ├── 1-isdigit.o ├── 1-memcpy.c ├── 1-memcpy.o ├── 1-strncat.c ├── 1-strncat.o ├── 100-atoi.c ├── 100-atoi.o ├── 2-strchr.c ├── 2-strchr.o ├── 2-strlen.c ├── 2-strlen.o ├── 2-strncpy.c ├── 2-strncpy.o ├── 3-islower.c ├── 3-islower.o ├── 3-puts.c ├── 3-puts.o ├── 3-strcmp.c ├── 3-strcmp.o ├── 3-strspn.c ├── 3-strspn.o ├── 4-isalpha.c ├── 4-isalpha.o ├── 4-strpbrk.c ├── 4-strpbrk.o ├── 5-strstr.c ├── 5-strstr.o ├── 6-abs.c ├── 6-abs.o ├── 9-strcpy.c ├── 9-strcpy.o ├── README.md ├── _putchar.c ├── _putchar.o ├── create_static_lib.sh ├── holberton.h ├── liball.a ├── libholberton.a ├── main.c ├── main.o └── quote ├── 0x0A-argc_argv ├── 0-whatsmyname.c ├── 1-args.c ├── 100-change.c ├── 2-args.c ├── 3-mul.c ├── 4-add.c ├── README.md ├── _putchar.c ├── add ├── args ├── change ├── holberton.h ├── mul ├── mynewnameis └── nargs ├── 0x0B-malloc_free ├── 0-create_array.c ├── 0-main.c ├── 1-main.c ├── 1-strdup.c ├── 100-main.c ├── 100-strtow.c ├── 2-main.c ├── 2-str_concat.c ├── 3-alloc_grid.c ├── 3-main.c ├── 4-free_grid.c ├── 4-main.c ├── 5-argstostr.c ├── 5-main.c ├── 6-main.c ├── README.md ├── _putchar.c ├── a ├── args ├── c ├── f ├── g ├── holberton.h ├── s └── strtow ├── 0x0C-more_malloc_free ├── 0-main.c ├── 0-main.c~ ├── 0-malloc_checked.c ├── 1-main.c ├── 1-string_nconcat.c ├── 100-main.c ├── 100-realloc.c ├── 101-mul.c ├── 2-calloc.c ├── 2-main.c ├── 3-array_range.c ├── 3-main.c ├── README.md ├── _putchar.c ├── a ├── a} ├── b ├── c ├── d ├── e ├── holberton.h └── mul ├── 0x0D-preprocessor ├── 0-main.c ├── 0-object_like_macro.h ├── 1-main.c ├── 1-pi.h ├── 2-main.c ├── 3-function_like_macro.h ├── 3-main.c ├── 4-main.c ├── 4-sum.h ├── README.md ├── _putchar.c ├── d ├── e ├── hague.c └── holberton.h ├── 0x0E-structures_typedef ├── 0-main.c ├── 1-init_dog.c ├── 1-main.c ├── 2-main.c ├── 2-print_dog.c ├── 4-main.c ├── 4-new_dog.c ├── 5-free_dog.c ├── 5-main.c ├── README.md ├── _putchar.c ├── a ├── b ├── c ├── dog.h ├── dog.h~ └── e ├── 0x0F-function_pointers ├── 0-main.c ├── 0-print_name.c ├── 1-array_iterator.c ├── 1-main.c ├── 1-main.c~ ├── 100-main_opcodes.c ├── 2-int_index.c ├── 2-main.c ├── 3-calc.h ├── 3-get_op_func.c ├── 3-main.c ├── 3-op_functions.c ├── README.md ├── _putchar.c ├── a ├── b ├── c ├── calc ├── function_pointers.h └── main ├── 0x10-variadic_functions ├── 0-main.c ├── 0-sum_them_all.c ├── 1-main.c ├── 1-print_numbers.c ├── 100-hello_holberton.asm ├── 2-main.c ├── 2-main.c~ ├── 2-print_strings.c ├── 3-main.c ├── 3-print_all.c ├── README.md ├── _putchar.c ├── a ├── b ├── c ├── d └── variadic_functions.h ├── 0x12-singly_linked_lists ├── #100-first.c# ├── 0-main.c ├── 0-print_list.c ├── 1-list_len.c ├── 1-list_len_recursion.c ├── 1-main.c ├── 1-main.c~ ├── 100-first.c ├── 101-hello_holberton.asm ├── 11-main.c ├── 2-add_node.c ├── 2-main.c ├── 3-add_node_end.c ├── 3-main.c ├── 4-free_list.c ├── 4-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e └── lists.h ├── 0x13-more_singly_linked_lists ├── 0-main.c ├── 0-print_listint.c ├── 0-recursion_print_listint.c ├── 1-listint_len.c ├── 1-main.c ├── 10-delete_nodeint.c ├── 10-main.c ├── 100-main.c ├── 100-reverse_listint.c ├── 101-main.c ├── 101-main.c~ ├── 101-print_listint_safe.c ├── 102-free_listint_safe.c ├── 102-main.c ├── 103-find_loop.c ├── 103-main.c ├── 2-add_nodeint.c ├── 2-main.c ├── 3-add_nodeint_end.c ├── 3-main.c ├── 4-free_listint.c ├── 4-main.c ├── 5-free_listint2.c ├── 5-main.c ├── 6-main.c ├── 6-pop_listint.c ├── 7-get_nodeint.c ├── 7-main.c ├── 8-main.c ├── 8-sum_listint.c ├── 9-insert_nodeint.c ├── 9-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e ├── f ├── g ├── h ├── i ├── j ├── k ├── l ├── lists.h ├── m ├── n └── o ├── 0x14-bit_manipulation ├── 0-binary_to_uint.c ├── 0-main.c ├── 1-main.c ├── 1-print_binary.c ├── 100-get_endianness.c ├── 100-main.c ├── 101-password ├── 2-get_bit.c ├── 2-main.c ├── 3-main.c ├── 3-set_bit.c ├── 4-clear_bit.c ├── 4-main.c ├── 5-flip_bits.c ├── 5-main.c ├── README.md ├── _putchar.c ├── a ├── b ├── c ├── d ├── e ├── f ├── h └── holberton.h ├── 0x15-file_io ├── 0-main.c ├── 0-read_textfile.c ├── 1-create_file.c ├── 1-main.c ├── 100-elf_header.c ├── 2-append_text_to_file.c ├── 2-main.c ├── 3-cp.c ├── Incitatous ├── README.md ├── Requiescat ├── a ├── b ├── c ├── cp ├── hello ├── holberton.h └── incitatous ├── 0x17-doubly_linked_lists ├── 0-main.c ├── 0-print_dlistint.c ├── 1-dlistint_len.c ├── 1-main.c ├── 100-password ├── 102-result ├── 2-add_dnodeint.c ├── 2-main.c ├── 3-add_dnodeint_end.c ├── 3-main.c ├── 4-free_dlistint.c ├── 4-main.c ├── 5-get_dnodeint.c ├── 5-main.c ├── 6-main.c ├── 6-sum_dlistint.c ├── 7-insert_dnodeint.c ├── 7-main.c ├── 8-delete_dnodeint.c ├── 8-main.c ├── README.md ├── a ├── b ├── c ├── d ├── e ├── h ├── i ├── j ├── k ├── lists.h └── palindrome.c ├── 0x18-dynamic_libraries ├── .ls ├── 0-isupper.c ├── 0-main.c ├── 0-memset.c ├── 0-strcat.c ├── 1-create_dynamic_lib.sh ├── 1-isdigit.c ├── 1-memcpy.c ├── 1-strncat.c ├── 100-atoi.c ├── 100-operations.c ├── 100-operations.so ├── 100-tests.py ├── 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 ├── 6-abs.c ├── 9-strcpy.c ├── README.md ├── README.md~ ├── _putchar.c ├── holberton.h ├── len ├── liball.s ├── libholberton.so └── run ├── 0x1A-hash_tables ├── 0-hash_table_create.c ├── 0-main.c ├── 1-djb2.c ├── 1-main.c ├── 100-main.c ├── 100-sorted_hash_table.c ├── 2-key_index.c ├── 2-main.c ├── 3-hash_table_set.c ├── 3-main.c ├── 4-hash_table_get.c ├── 4-main.c ├── 5-hash_table_print.c ├── 5-main.c ├── 6-hash_table_delete.c ├── 6-main.c ├── README.md ├── f ├── hash_tables.h └── shash_tables.h ├── 0x1C-makefiles ├── 0-Makefile ├── 1-Makefile ├── 100-Makefile ├── 2-Makefile ├── 3-Makefile ├── 4-Makefile ├── 5-island_perimeter.py ├── 5-main.py ├── README.md ├── __pycache__ │ └── 5-island_perimeter.cpython-34.pyc ├── holberton ├── holberton.c ├── holberton.o ├── m.h ├── main.c └── main.o ├── 0x1E-search_algorithms ├── 0-linear ├── 0-linear.c ├── 0-main.c ├── 1-binary ├── 1-binary.c ├── 1-main.c ├── 100-jump.c ├── 100-main.c ├── 101-O ├── 102-interpolation.c ├── 102-main.c ├── 103-main.c ├── 104-main.c ├── 105-main.c ├── 106-main.c ├── 107-O ├── 108-O ├── 2-O ├── 3-O ├── 4-O ├── 5-O ├── 6-O ├── README.md └── search_algos.h ├── README.md └── miniShell ├── 0-av.c ├── 1-read_getline.c ├── 1-read_line.c ├── 2-strtok.c ├── README.md ├── README.md~ ├── _getline.c ├── _strtok.c ├── afork ├── afork.c ├── av ├── env-main.c ├── example.c ├── exec ├── execute ├── execute_prog.c ├── fork ├── fork.c ├── full ├── functional ├── getenv ├── getenv.c ├── getline2 ├── gettokenv.c ├── ls.c ├── mypid ├── pid.c ├── printenv ├── read_getline ├── shell ├── shell.c ├── shell_init.c ├── stat ├── stat.c ├── strtok ├── wait └── wait.c /0x00-hello_world/0-preprocessor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc $CFILE -E -o c 3 | -------------------------------------------------------------------------------- /0x00-hello_world/1-compiler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/100-intel: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S -masm=intel $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/101-quote.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - Entry point 6 | * Return: Always 1 (Success) 7 | */ 8 | int main(void) 9 | { 10 | write(STDOUT_FILENO, "and that piece of art is useful 11 | \" - Dora Korpar, 2015-10-19\n", 59); 12 | return (1); 13 | } 14 | -------------------------------------------------------------------------------- /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 - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | puts("\"Programming is like building a multilingual puzzle"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x00-hello_world/5-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | int main(void) 9 | { 10 | printf("with proper grammar, but the outcome is a piece of art,\n"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x00-hello_world/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x00-hello_world/a.out -------------------------------------------------------------------------------- /0x00-hello_world/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/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x00-hello_world/main.o -------------------------------------------------------------------------------- /0x00-hello_world/main.s: -------------------------------------------------------------------------------- 1 | .file "main.c" 2 | .text 3 | .globl main 4 | .type main, @function 5 | main: 6 | .LFB0: 7 | .cfi_startproc 8 | pushq %rbp 9 | .cfi_def_cfa_offset 16 10 | .cfi_offset 6, -16 11 | movq %rsp, %rbp 12 | .cfi_def_cfa_register 6 13 | movl $0, %eax 14 | popq %rbp 15 | .cfi_def_cfa 7, 8 16 | ret 17 | .cfi_endproc 18 | .LFE0: 19 | .size main, .-main 20 | .ident "GCC: (Ubuntu 4.8.4-2ubuntu1~14.04.4) 4.8.4" 21 | .section .note.GNU-stack,"",@progbits 22 | -------------------------------------------------------------------------------- /0x00-hello_world/q: -------------------------------------------------------------------------------- 1 | and that piece of art is useful" - Dora Korpar, 2015-10-19 2 |  -------------------------------------------------------------------------------- /0x00-hello_world/quote: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x00-hello_world/quote -------------------------------------------------------------------------------- /0x00-hello_world/size32: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x00-hello_world/size32 -------------------------------------------------------------------------------- /0x00-hello_world/size64: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x00-hello_world/size64 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/0-positive_or_negative -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /** 5 | * main - Entry point 6 | * 7 | * Return: Always 0 (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 | printf("%d is positive\n", n); 18 | else if (n == 0) 19 | printf("%d is zero\n", n); 20 | else 21 | printf("%d is negative\n", n); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/1-last_digit -------------------------------------------------------------------------------- /0x01-variables_if_else_while/10-print_comb2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/10-print_comb2 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/10-print_comb2.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | int d; 14 | 15 | for (d = 0; d < 100; d++) 16 | { 17 | putchar((d / 10) + '0'); 18 | putchar((d % 10) + '0'); 19 | if (d != 99) 20 | { 21 | putchar(','); 22 | putchar(' '); 23 | } 24 | } 25 | putchar('\n'); 26 | 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/100-print_comb3 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/101-print_comb4 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/102-print_comb5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/102-print_comb5 -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x01-variables_if_else_while/2-print_alphabet -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | char low; 14 | 15 | for (low = 'a'; low <= 'z'; low++) 16 | putchar(low); 17 | putchar('\n'); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | char low; 14 | 15 | for (low = 'a'; low <= 'z'; low++) 16 | putchar(low); 17 | for (low = 'A'; low <= 'Z'; low++) 18 | putchar(low); 19 | putchar('\n'); 20 | 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | char low, e, q; 14 | 15 | e = 'e'; 16 | q = 'q'; 17 | 18 | for (low = 'a'; low <= 'z'; low++) 19 | { 20 | if (low != e && low != q) 21 | putchar(low); 22 | } 23 | putchar('\n'); 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | int i; 14 | 15 | for (i = 0; i < 10; i++) 16 | printf("%d", i); 17 | printf("\n"); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | int d; 14 | 15 | for (d = '0'; d <= '9'; d++) 16 | putchar(d); 17 | putchar('\n'); 18 | 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | char low; 14 | 15 | for (low = 'z'; low >= 'a'; low--) 16 | putchar(low); 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 - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | int d; 14 | char low; 15 | 16 | for (d = '0'; d <= '9'; d++) 17 | putchar(d); 18 | for (low = 'a'; low <= 'f'; low++) 19 | putchar(low); 20 | putchar('\n'); 21 | 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | 11 | int main(void) 12 | { 13 | int d; 14 | 15 | for (d = '0'; d <= '9'; d++) 16 | { 17 | putchar(d); 18 | if (d != '9') 19 | { 20 | putchar(','); 21 | putchar(' '); 22 | } 23 | } 24 | putchar('\n'); 25 | 26 | return (0); 27 | } 28 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/0-holberton -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | /** 5 | * main - Check description 6 | * Description: It prints the word Holberton, followed by a new line. 7 | * Return: 0. 8 | */ 9 | int main(void) 10 | { 11 | char word[9] = "Holberton"; 12 | int i; 13 | 14 | for (i = 0; i < 9; i++) 15 | _putchar(word[i]); 16 | _putchar('\n'); 17 | 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/1-alphabet -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_alphabet - Check description 5 | * Description: It prints the alphabet in lowercase fallowed by a new line 6 | * Return: Nothing. 7 | */ 8 | void print_alphabet(void) 9 | { 10 | char i; 11 | 12 | for (i = 'a'; i <= 'z'; i++) 13 | _putchar(i); 14 | _putchar('\n'); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/10-add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/10-add -------------------------------------------------------------------------------- /0x02-functions_nested_loops/10-add.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * add - Check Holberton 5 | * @a: An integer a 6 | * @b: An integer b 7 | * Description: Function that adds two integers and returns the result 8 | * Return: Result to add a and b 9 | */ 10 | int add(int a, int b) 11 | { 12 | return (a + b); 13 | } 14 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/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_times_table(3); 11 | _putchar('\n'); 12 | print_times_table(5); 13 | _putchar('\n'); 14 | print_times_table(98); 15 | _putchar('\n'); 16 | print_times_table(12); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/100-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/100-times_table -------------------------------------------------------------------------------- /0x02-functions_nested_loops/100-times_table.co: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/100-times_table.co -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/101-natural -------------------------------------------------------------------------------- /0x02-functions_nested_loops/101-natural.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | 9 | int main(void) 10 | { 11 | int i, sum = 0; 12 | 13 | for (i = 0; i < 1024; i++) 14 | { 15 | if ((i % 5) == 0 || (i % 3) == 0) 16 | sum += i; 17 | } 18 | printf("%d\n", sum); 19 | 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/102-fibonacci -------------------------------------------------------------------------------- /0x02-functions_nested_loops/102-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | 9 | int main(void) 10 | { 11 | int i; 12 | long int fibonacci[50]; 13 | 14 | fibonacci[0] = 1; 15 | fibonacci[1] = 2; 16 | printf("%ld, %ld, ", fibonacci[0], fibonacci[1]); 17 | 18 | for (i = 2; i < 50; i++) 19 | { 20 | fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; 21 | if (i == 49) 22 | printf("%ld\n", fibonacci[i]); 23 | else 24 | printf("%ld, ", fibonacci[i]); 25 | } 26 | 27 | return (0); 28 | } 29 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/103-fibonacci -------------------------------------------------------------------------------- /0x02-functions_nested_loops/103-fibonacci.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * 6 | * Return: Always 0 (Success) 7 | */ 8 | 9 | int main(void) 10 | { 11 | int i; 12 | long int fibonacci[50], sum = 2; 13 | 14 | fibonacci[0] = 1; 15 | fibonacci[1] = 2; 16 | 17 | for (i = 2; i < 50; i++) 18 | { 19 | fibonacci[i] = fibonacci[i - 1] + fibonacci[i - 2]; 20 | if ((fibonacci[i] % 2) == 0 && fibonacci[i] < 4000000) 21 | sum += fibonacci[i]; 22 | } 23 | printf("%ld\n", sum); 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/11-98 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/11-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_to_98(0); 11 | print_to_98(98); 12 | print_to_98(111); 13 | print_to_98(81); 14 | print_to_98(-10); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-alphabet_x10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/2-alphabet_x10 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_alphabet_x10 - Check holberton 5 | * Description: function uses _putchar function to print 6 | * alphabet in lowercase 10 times 7 | * Return: Nothing. 8 | */ 9 | 10 | void print_alphabet_x10(void) 11 | { 12 | char i; 13 | int j; 14 | 15 | for (j = 0; j < 10; j++) 16 | { 17 | for (i = 'a'; i <= 'z'; i++) 18 | _putchar(i); 19 | _putchar('\n'); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/3-islower -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check Holberton 5 | * @c: An input character 6 | * Description: function uses _putchar function to print 7 | * alphabet in lowercase 10 times 8 | * Return: 1 if is lowercase or 0 if is uppercase 9 | */ 10 | int _islower(int c) 11 | { 12 | char i; 13 | int lower = 0; 14 | 15 | for (i = 'a'; i <= 'z'; i++) 16 | { 17 | if (i == c) 18 | lower = 1; 19 | } 20 | 21 | return (lower); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/4-isalpha: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/4-isalpha -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isalpha - Check Holberton 5 | * @c: An input character 6 | * Description: function returns 1 if the character is a 7 | * letter, lowercase or uppercase. 8 | * Return: 1 or 0 in otherwise. 9 | */ 10 | int _isalpha(int c) 11 | { 12 | char lower, upper; 13 | int isletter = 0; 14 | 15 | for (lower = 'a'; lower <= 'z'; lower++) 16 | { 17 | for (upper = 'A'; upper <= 'Z'; upper++) 18 | { 19 | if (c == lower || c == upper) 20 | isletter = 1; 21 | } 22 | } 23 | return (isletter); 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/5-sign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/5-sign -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/6-abs -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_abs - Check Holberton 5 | * @r: An integre input 6 | * Description: This function returns absolute value of a number 7 | * Return: Absolut value of number r 8 | */ 9 | int _abs(int r) 10 | { 11 | if (r >= 0) 12 | return (r); 13 | else 14 | return (r * -1); 15 | } 16 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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 = _abs(-1); 14 | printf("%d\n", r); 15 | r = _abs(0); 16 | printf("%d\n", r); 17 | r = _abs(1); 18 | printf("%d\n", r); 19 | r = _abs(-98); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/7-last_digit -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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 | int r; 11 | 12 | print_last_digit(98); 13 | print_last_digit(0); 14 | r = print_last_digit(-1024); 15 | _putchar('0' + r); 16 | _putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-print_last_digit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_last_digit - Check Holberton 5 | * @r: An integer input 6 | * Description: This function prints the last digit of a number 7 | * Return: last digit of number r 8 | */ 9 | int print_last_digit(int r) 10 | { 11 | int n; 12 | 13 | if (r < 0) 14 | n = -1 * (r % 10); 15 | else 16 | n = r % 10; 17 | 18 | _putchar((n % 10) + '0'); 19 | return (n % 10); 20 | } 21 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/8-24 -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24_hours.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * jack_bauer - Check Holberton 5 | * Description: function prints every minute in one day 6 | * Return: Nothing 7 | */ 8 | void jack_bauer(void) 9 | { 10 | int H, M; 11 | 12 | for (H = 0; H < 24; H++) 13 | { 14 | for (M = 0; M < 60; M++) 15 | { 16 | _putchar((H / 10) + '0'); 17 | _putchar((H % 10) + '0'); 18 | _putchar(':'); 19 | _putchar((M / 10) + '0'); 20 | _putchar((M % 10) + '0'); 21 | _putchar('\n'); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/8-main.c~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/8-main.c~ -------------------------------------------------------------------------------- /0x02-functions_nested_loops/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/9-main.c~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/9-main.c~ -------------------------------------------------------------------------------- /0x02-functions_nested_loops/9-times_table: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/9-times_table -------------------------------------------------------------------------------- /0x02-functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # **0x02. C - Functions, nested loops** 2 | 3 | ## General 4 | 5 | * What are nested loops and how to use them 6 | * What is a function and how do you use functions 7 | * What is the difference between a declaration and a definition of a function 8 | * What is a prototype 9 | * Scope of variables 10 | * What are the gcc flags -Wall -Werror -pedantic -Wextra 11 | * What are header files and how to to use them with #include 12 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/ejemplo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x02-functions_nested_loops/ejemplo -------------------------------------------------------------------------------- /0x02-functions_nested_loops/ejemplo.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 | 12 | int main(void) 13 | { 14 | char word[9] = "Holberton"; 15 | int i; 16 | 17 | for (i = 0; i < 9; i++) 18 | _putchar(word[i]); 19 | _putchar('\n'); 20 | 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void print_alphabet(void); 3 | void print_alphabet_x10(void); 4 | int _islower(int c); 5 | int _isalpha(int c); 6 | int print_sign(int n); 7 | int _abs(int r); 8 | int print_last_digit(int r); 9 | void jack_bauer(void); 10 | void times_table(void); 11 | int add(int a, int b); 12 | void print_to_98(int n); 13 | void print_times_table(int n); 14 | void putformat(int); 15 | -------------------------------------------------------------------------------- /0x03-debugging/0-main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x03-debugging/0-main -------------------------------------------------------------------------------- /0x03-debugging/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 | positive_or_negative(i); 14 | 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x03-debugging/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - causes an infinite loop 5 | * Return: 0 6 | */ 7 | 8 | int main(void) 9 | { 10 | int i; 11 | 12 | printf("Infinite loop incoming :(\n"); 13 | 14 | i = 0; 15 | 16 | /* while (i < 10)*/ 17 | /* {*/ 18 | /* putchar(i);*/ 19 | /* }*/ 20 | 21 | printf("Infinite loop avoided! \\o/\n"); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x03-debugging/2-largest_number.c: -------------------------------------------------------------------------------- 1 | #include "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 | int largest_number(int a, int b, int c) 11 | { 12 | int largest; 13 | 14 | if (a >= b && a >= c) 15 | { 16 | largest = a; 17 | } 18 | else if (b >= a && b >= c) 19 | { 20 | largest = b; 21 | } 22 | else if (c >= a && c >= b) 23 | { 24 | largest = c; 25 | } 26 | 27 | return (largest); 28 | } 29 | -------------------------------------------------------------------------------- /0x03-debugging/README.md: -------------------------------------------------------------------------------- 1 | # **0x03. C - Debugging** 2 | 3 | ## General 4 | 5 | * What is debugging 6 | * What are some methods of debugging manually 7 | * How to read the error messages 8 | 9 | -------------------------------------------------------------------------------- /0x03-debugging/holberton.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HOLBERTON_H 3 | #define HOLBERTON_H 4 | 5 | #include 6 | 7 | void positive_or_negative(int i); 8 | int largest_number(int, int, int); 9 | int convert_day(int month, int day); 10 | void print_remaining_days(int month, int day, int year); 11 | 12 | #endif /* HOLBERTON_H */ 13 | -------------------------------------------------------------------------------- /0x03-debugging/positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - Entry point 7 | * 8 | * Return: Always 0 (Success) 9 | */ 10 | int positive_or_negative(void) 11 | { 12 | int n; 13 | 14 | srand(time(0)); 15 | n = rand() - RAND_MAX / 2; 16 | 17 | if (n > 0) 18 | printf("%d is positive\n", n); 19 | else if (n == 0) 20 | printf("%d is zero\n", n); 21 | else 22 | printf("%d is negative\n", n); 23 | 24 | return (0); 25 | } 26 | -------------------------------------------------------------------------------- /0x03-debugging/positive_or_negative.c~: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /** 5 | * main - Entry point 6 | * 7 | * Return: Always 0 (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 | printf("%d is positive\n", n); 18 | else if (n == 0) 19 | printf("%d is zero\n", n); 20 | else 21 | printf("%d is negative\n", n); 22 | 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isuper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/0-isuper -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - A function that checks for uppercase character. 5 | * @c: An input character 6 | * Return: 1 if c is uppercase or 0 otherwise 7 | */ 8 | int _isupper(int c) 9 | { 10 | char uppercase = 'A'; 11 | int isupper = 0; 12 | 13 | for (; uppercase <= 'Z'; uppercase++) 14 | { 15 | if (c == uppercase) 16 | { 17 | isupper = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isupper); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/1-isdigit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/1-isdigit -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - A function that checks for a digit (0 through 9). 5 | * @c: An input integer 6 | * Return: 1 if c is a digit or 0 otherwise 7 | */ 8 | int _isdigit(int c) 9 | { 10 | char i = '0'; 11 | int isdigit = 0; 12 | 13 | for (; i <= '9'; i++) 14 | { 15 | if (i == c) 16 | { 17 | isdigit = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isdigit); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/10-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_triangle(2); 11 | print_triangle(10); 12 | print_triangle(1); 13 | print_triangle(0); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-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_triangle(2); 11 | print_triangle(10); 12 | print_triangle(1); 13 | print_triangle(0); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/10-triangles: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/10-triangles -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/100-prime_factor -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - Entry point 5 | * Return: Always 0 6 | */ 7 | int main(void) 8 | { 9 | unsigned long int i = 3, n = 612852475143; 10 | 11 | for (; i < 12057; i += 2) 12 | { 13 | while (n % i == 0 && n != i) 14 | n /= i; 15 | } 16 | printf("%lu\n", n); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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 | print_number(-987654321); 21 | _putchar('\n'); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/101-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/101-print_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/2-mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/2-mul -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * mul - a function that multiplies two integers. 5 | * @a: An input integer 6 | * @b: An input integer 7 | * Return: Always 0 8 | */ 9 | int mul(int a, int b) 10 | { 11 | return (a * b); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/3-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/3-print_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_numbers - a function that prints the numbers, from 0 to 9, 5 | * followed by a new line. 6 | * Return: Always 0 7 | */ 8 | void print_numbers(void) 9 | { 10 | int i = '0'; 11 | 12 | for (; i <= '9'; i++) 13 | _putchar(i); 14 | _putchar('\n'); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/4-print_most_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_most_numbers - a function that prints the numbers, from 0 to 9. 5 | * Do not print 2 and 4. 6 | * followed by a new line. 7 | * Return: Always 0 8 | */ 9 | void print_most_numbers(void) 10 | { 11 | int i = '0'; 12 | 13 | for (; i <= '9'; i++) 14 | { 15 | if (i != '2' && i != '4') 16 | _putchar(i); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/5-more_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/5-more_numbers -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * more_numbers - a function that prints 10 times the numbers, from 0 to 14, 5 | * followed by a new line. 6 | * Return: Always 0 7 | */ 8 | void more_numbers(void) 9 | { 10 | int i, j = 0; 11 | 12 | for (; j < 10; j++) 13 | { 14 | for (i = 0; i <= 14; i++) 15 | { 16 | if (i > 9) 17 | _putchar(i / 10 + '0'); 18 | 19 | _putchar(i % 10 + '0'); 20 | } 21 | _putchar('\n'); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/6-lines: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/6-lines -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_line - a function that draws a straight line in the terminal. 5 | * followed by a new line. 6 | * @n: An input integer 7 | * Return: Always 0 8 | */ 9 | void print_line(int n) 10 | { 11 | int i = 0; 12 | 13 | if (n > 0) 14 | { 15 | for (; i < n; i++) 16 | _putchar('_'); 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/7-diagonals: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/7-diagonals -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_diagonal - a function that draws a diagonal line on the terminal. 5 | * @n: An input integer 6 | * Return: Always 0 7 | */ 8 | void print_diagonal(int n) 9 | { 10 | int i = 0, j; 11 | 12 | if (n > 0) 13 | { 14 | for (; i < n; i++) 15 | { 16 | for (j = 0; j < i; j++) 17 | _putchar(' '); 18 | _putchar(92); 19 | _putchar('\n'); 20 | } 21 | } 22 | else 23 | _putchar('\n'); 24 | } 25 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/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/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_square - Write a function that prints a square, 5 | * followed by a new line. 6 | * @size: An input integer 7 | * Return: Always 0 8 | */ 9 | void print_square(int size) 10 | { 11 | int i, j; 12 | 13 | if (size > 0) 14 | { 15 | for (i = 0; i < size; i++) 16 | { 17 | for (j = 0; j < size; j++) 18 | _putchar('#'); 19 | _putchar('\n'); 20 | } 21 | } 22 | else 23 | _putchar('\n'); 24 | } 25 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/8-squares: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/8-squares -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x04-more_functions_nested_loops/9-fizz_buzz -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/9-fizz_buzz.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - Entry piont 6 | * Return: Always 0 7 | */ 8 | int main(void) 9 | { 10 | int i = 1; 11 | 12 | for (; i < 100 ; i++) 13 | { 14 | if (i % 3 == 0 && i % 5 == 0) 15 | printf("FizzBuzz "); 16 | else if (i % 3 == 0) 17 | printf("Fizz "); 18 | else if (i % 5 == 0) 19 | printf("Buzz "); 20 | else 21 | printf("%d ", i); 22 | } 23 | printf("Buzz\n"); 24 | 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # **0x04. C - More functions, more nested loops** 2 | 3 | ## General 4 | 5 | * What are nested loops and how to use them 6 | * What is a function and how do you use functions 7 | * What is the difference between a declaration and a definition of a function 8 | * What is a prototype 9 | * Scope of variables 10 | * What are the gcc flags -Wall -Werror -pedantic -Wextra 11 | * What are header files and how to to use them with #include 12 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x04-more_functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | int _isupper(int c); 3 | int _isdigit(int c); 4 | int mul(int a, int b); 5 | void print_numbers(void); 6 | void print_most_numbers(void); 7 | void more_numbers(void); 8 | void print_line(int n); 9 | void print_diagonal(int n); 10 | void print_square(int size); 11 | void print_triangle(int size); 12 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/+: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void reset_to_98(int *n); 3 | void swap_int(int *a, int *b); 4 | int _strlen(char *s); 5 | void _puts(char *str); 6 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-98: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/0-98 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * reset_to_98 - a function that takes a pointer to an int as parameter 5 | * and updates the value it points to to 98. 6 | * @n: An integer input pointer 7 | * Return: Nothing. 8 | */ 9 | void reset_to_98(int *n) 10 | { 11 | *n = 98; 12 | } 13 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/1-swap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/1-swap -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * swap_int - a function that swaps the values of two integers. 5 | * @a: an inout integer pointer 6 | * @b: an input integer pointer 7 | * Return: Nothing 8 | */ 9 | void swap_int(int *a, int *b) 10 | { 11 | int aux; 12 | 13 | aux = *a; 14 | *a = *b; 15 | *b = aux; 16 | } 17 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/2-strlen: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/2-strlen -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - a function that returns the length of a string. 5 | * @s: An input string 6 | * Return: Nothing 7 | */ 8 | int _strlen(char *s) 9 | { 10 | int len = 0; 11 | 12 | while (s[len] != '\0') 13 | len++; 14 | return (len); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/3-puts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/3-puts -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed 5 | * by a new line, to stdout. 6 | * @str: an input string 7 | * Return: Nothing 8 | */ 9 | void _puts(char *str) 10 | { 11 | int i = 0; 12 | 13 | while (str[i] != '\0') 14 | { 15 | _putchar(str[i]); 16 | i++; 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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 | } -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/4-print_rev -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_rev - a function that prints a string, in reverse, 5 | * followed by a new line. 6 | * @s: an input string 7 | * Return: Nothing 8 | */ 9 | void print_rev(char *s) 10 | { 11 | int len = 0; 12 | 13 | while (s[len] != '\0') 14 | len++; 15 | 16 | while (len) 17 | _putchar(s[--len]); 18 | 19 | _putchar('\n'); 20 | } 21 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/4-print_rev1 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/4-print_rev1.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_rev - a function that prints a string, in reverse, 5 | * followed by a new line. 6 | * @s: an input string 7 | * Return: Nothing 8 | */ 9 | void print_rev(char *s) 10 | { 11 | char *len = s; 12 | 13 | while (*len) 14 | len++; 15 | len -= 1; 16 | 17 | while (len) 18 | { 19 | _putchar(*s); 20 | len--; 21 | } 22 | _putchar('\n'); 23 | } 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/5-rev_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/5-rev_string -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * rev_string - a function that reverse a string 5 | * followed by a new line. 6 | * @s: an input string 7 | * Return: Nothing 8 | */ 9 | void rev_string(char *s) 10 | { 11 | int len = 0, i = 0; 12 | char aux; 13 | 14 | while (s[len] != '\0') 15 | len++; 16 | 17 | while (i < len--) 18 | { 19 | aux = s[i]; 20 | s[i++] = s[len]; 21 | s[len] = aux; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/6-puts2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/6-puts2 -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * puts2 - a function that prints every other character of a string, 5 | * starting with the first character, followed by a new line. 6 | * @str: An input string 7 | * Return: Nothing 8 | */ 9 | void puts2(char *str) 10 | { 11 | int len = 0, i = 0; 12 | 13 | while (str[len] != '\0') 14 | len++; 15 | 16 | len -= 1; 17 | 18 | for (; i <= len; i += 2) 19 | _putchar(str[i]); 20 | 21 | _putchar('\n'); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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 = "0123456780"; 13 | puts_half(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/7-puts_half -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * puts_half - a function that prints half of a string, followed by a new line. 5 | * @str: An input string 6 | * Return: Nothing 7 | */ 8 | void puts_half(char *str) 9 | { 10 | int len = 0, i, n; 11 | 12 | while (str[len] != '\0') 13 | len++; 14 | 15 | if (len % 2 == 0) 16 | n = len / 2; 17 | 18 | else 19 | n = (len + 1) / 2; 20 | 21 | for (i = n; i < len; i++) 22 | _putchar(str[i]); 23 | 24 | _putchar('\n'); 25 | } 26 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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/8-print_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/8-print_array -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/8-print_array.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * print_array - a function that prints n elements of an array of integers, 6 | * followed by a new line. 7 | * @a: an input array 8 | * @n: an input integer 9 | * Return: Nothing 10 | */ 11 | void print_array(int *a, int n) 12 | { 13 | int i = 0; 14 | 15 | for (; i < n; i++) 16 | { 17 | printf("%d", a[i]); 18 | if (i < n - 1) 19 | printf(", "); 20 | } 21 | putchar('\n'); 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/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 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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-main.c~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/9-main.c~ -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x05-pointers_arrays_strings/9-strcpy -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/9-strcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _strcpy - a function that copies the string pointed to by src, 3 | * including the terminating null byte (\0), 4 | * to the buffer pointed to by dest. 5 | * 6 | * @dest: A pointer to destination of string 7 | * @src: A pointer to source string to copy from 8 | * 9 | * Return: pointer to dest 10 | */ 11 | char *_strcpy(char *dest, char *src) 12 | { 13 | char *aux = dest; 14 | 15 | while (*src) 16 | *dest++ = *src++; 17 | return (aux); 18 | } 19 | -------------------------------------------------------------------------------- /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 | int _putchar(char c); 2 | void reset_to_98(int *n); 3 | void swap_int(int *a, int *b); 4 | int _strlen(char *s); 5 | void _puts(char *str); 6 | void print_rev(char *s); 7 | void rev_string(char *s); 8 | void puts2(char *str); 9 | void puts_half(char *str); 10 | void print_array(int *a, int n); 11 | char *_strcpy(char *dest, char *src); 12 | int _atoi(char *s); 13 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/0-strcat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcat - a function that concatenates two strings. 5 | * @dest: an input string 6 | * @src: an input string 7 | * Return: A pointer to the resulting string 8 | */ 9 | char *_strcat(char *dest, char *src) 10 | { 11 | char *temp = dest; 12 | 13 | while (*dest) 14 | dest++; 15 | 16 | while (*src) 17 | *dest++ = *src++; 18 | 19 | *dest = '\0'; 20 | return (temp); 21 | } 22 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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/1-strncat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/1-strncat -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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/100-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/100-print_numbers -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/101-magic: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/101-magic -------------------------------------------------------------------------------- /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: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/2-strncpy -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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/3-strcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/3-strcmp -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcmp - a function that compares two strings. 5 | * @s1: an input string 6 | * @s2: an input string 7 | * Return: The difference s1 - s2 8 | */ 9 | int _strcmp(char *s1, char *s2) 10 | { 11 | while (*s1 && *s2) 12 | { 13 | if (*s1 != *s2) 14 | return (*s1 - *s2); 15 | s1++, s2++; 16 | } 17 | return (*s1 - *s2); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/4-rev_array -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-rev_array.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * reverse_array - a function that reverse an array. 5 | * @a: an input array 6 | * @n: number of elements of array 7 | * Return: Nothing 8 | */ 9 | void reverse_array(int *a, int n) 10 | { 11 | int i = 0; 12 | int aux; 13 | 14 | while (i < n--) 15 | { 16 | aux = a[i]; 17 | a[i++] = a[n]; 18 | a[n] = aux; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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[] = "Holberton School!\n"; 12 | char *p; 13 | 14 | p = string_toupper(s); 15 | printf("%s", p); 16 | printf("%s", s); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/5-string_toupper -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-string_toupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * string_toupper - a function that changes all lowercase letters of a string 5 | * to upper case 6 | * @s: an input string 7 | * Return: char pointer to converted string 8 | */ 9 | char *string_toupper(char *s) 10 | { 11 | char *start = s; 12 | 13 | while (*s) 14 | { 15 | if (*s >= 'a' && *s <= 'z') 16 | *s -= 32; 17 | s++; 18 | } 19 | return (start); 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/6-cap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/6-cap -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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/7-1337: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/7-1337 -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/7-leet.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * leet - a function that encodes a string into 1337. 5 | * @s: an input string to encode 6 | * Return: An encode string 7 | */ 8 | char *leet(char *s) 9 | { 10 | int i = 0, j; 11 | char subs[10] = {'4', '4', '3', '3', '0', '0', '7', '7', '1', '1'}, 12 | str[10] = {'a', 'A', 'e', 'E', 'o', 'O', 't', 'T', 'l', 'L'}; 13 | 14 | while (s[i]) 15 | { 16 | for (j = 0; j < 10; j++) 17 | if (s[i] == str[j]) 18 | s[i] = subs[j]; 19 | 20 | i++; 21 | } 22 | 23 | return (s); 24 | } 25 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/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 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/8-rot13: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x06-pointers_arrays_strings/8-rot13 -------------------------------------------------------------------------------- /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 | int _putchar(char c); 2 | char *_strcat(char *dest, char *src); 3 | char *_strncat(char *dest, char *src, int n); 4 | char *_strncpy(char *dest, char *src, int n); 5 | int _strcmp(char *s1, char *s2); 6 | void reverse_array(int *a, int n); 7 | char *string_toupper(char *s); 8 | char *cap_string(char *s); 9 | char *leet(char *s); 10 | char *rot13(char *); 11 | void print_number(int n); 12 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/0-memset -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - a function that fills memory with constant bytes 5 | * @s: location to fill 6 | * @b: char to fill location with 7 | * @n: number of bytes to fill 8 | * Return: returns pointer to location filled 9 | */ 10 | char *_memset(char *s, char b, unsigned int n) 11 | { 12 | char *start = s; 13 | 14 | while (n--) 15 | { 16 | *s = b; 17 | s++; 18 | } 19 | return (start); 20 | } 21 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/1-memcpy -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - a function that copys memory area 5 | * @dest: memory area destination to copy 6 | * @src: memory area source to copy from 7 | * @n: number of bytes 8 | * Return: returns pointer to copy location 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | char *start = dest; 13 | 14 | while (n--) 15 | { 16 | *dest = *src; 17 | src++; 18 | dest++; 19 | } 20 | return (start); 21 | } 22 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/101-crackme_password: -------------------------------------------------------------------------------- 1 | abc123 -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/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 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/2-strchr -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strchr - a function that locates a character in a string. 6 | * @s: an input string to search in 7 | * @c: an input character to locate into string s 8 | * Return: returns pointer to c position 9 | */ 10 | char *_strchr(char *s, char c) 11 | { 12 | 13 | while (*s) 14 | { 15 | if (c == *s) 16 | return (s); 17 | s++; 18 | } 19 | if (c == *s) 20 | return (s); 21 | return (NULL); 22 | } 23 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/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; 14 | 15 | n = _strspn(s, f); 16 | printf("%u\n", n); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/3-strspn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/3-strspn -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/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/4-strpbrk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/4-strpbrk -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/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/5-strstr: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/5-strstr -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/7-print_chessboard -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/7-print_chessboard.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * print_chessboard - a function that prints a chessboard 5 | * @a: an array input to print 6 | * Return: Nothing 7 | */ 8 | void print_chessboard(char (*a)[8]) 9 | { 10 | int i = 0, j; 11 | 12 | for (; i < 8; i++) 13 | { 14 | for (j = 0; j < 8; j++) 15 | _putchar(a[i][j]); 16 | _putchar('\n'); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/8-print_diagsums: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/8-print_diagsums -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/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 = "Anne Cognet"; 12 | char *s1 = "Asaia Palacios"; 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 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/9-set_string: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x07-pointers_arrays_strings/9-set_string -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/9-set_string.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * set_string - sets value of a pointer to a char 5 | * @s: double pointer to a string 6 | * @to: pointer to the string to set s to 7 | * Return: Description of the returned value 8 | */ 9 | void set_string(char **s, char *to) 10 | { 11 | *s = to; 12 | } 13 | -------------------------------------------------------------------------------- /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 | int _putchar(char c); 2 | char *_memset(char *s, char b, unsigned int n); 3 | char *_memcpy(char *dest, char *src, unsigned int n); 4 | char *_strchr(char *s, char c); 5 | unsigned int _strspn(char *s, char *accept); 6 | char *_strpbrk(char *s, char *accept); 7 | char *_strstr(char *haystack, char *needle); 8 | void print_chessboard(char (*a)[8]); 9 | void print_diagsums(int *a, int size); 10 | void set_string(char **s, char *to); 11 | -------------------------------------------------------------------------------- /0x07-pointers_arrays_strings/holberton.h~: -------------------------------------------------------------------------------- 1 | int _putchar(char c)i; 2 | -------------------------------------------------------------------------------- /0x08-recursion/0-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 | _puts_recursion("Betty Holberton"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/0-puts_recursion -------------------------------------------------------------------------------- /0x08-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts_recursion - a function that prints a string, followed by a new line. 5 | * @s: An input string to printing 6 | * Return: Nothing 7 | */ 8 | void _puts_recursion(char *s) 9 | { 10 | if (*s) 11 | { 12 | _putchar(*s); 13 | _puts_recursion(s + 1); 14 | } 15 | else 16 | _putchar('\n'); 17 | } 18 | -------------------------------------------------------------------------------- /0x08-recursion/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_rev_recursion("\nColton Walker"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/1-print_rev_recursion -------------------------------------------------------------------------------- /0x08-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _print_rev_recursion - a function that prints a string in reverse, 5 | * followed by a new line. 6 | * @s: An input string to printing 7 | * Return: Nothing 8 | */ 9 | void _print_rev_recursion(char *s) 10 | { 11 | if (*s) 12 | { 13 | _print_rev_recursion(s + 1); 14 | _putchar(*s); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /0x08-recursion/100-wildcmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/100-wildcmp -------------------------------------------------------------------------------- /0x08-recursion/100-wildcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * wildcmp - A function that compares two strings 4 | * @s1: First input string 5 | * @s2: Second input string 6 | * Return: 1 if strings identical and 0 in otherwise 7 | */ 8 | int wildcmp(char *s1, char *s2) 9 | { 10 | if (!*s1 && !*s2) 11 | return (1); 12 | if (*s1 == *s2) 13 | return (wildcmp(s1 + 1, s2 + 1)); 14 | if (*s2 == '*' && (wildcmp(s1, s2 + 1) || wildcmp(s1 + 1, s2))) 15 | return (1); 16 | if (*s2 == '*' && *(s1 + 1) && *s2) 17 | return (0); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x08-recursion/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/2-strlen_recursion: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/2-strlen_recursion -------------------------------------------------------------------------------- /0x08-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen_recursion - a function that returns the length of a string. 5 | * @s: An input string to printing 6 | * Return: The length of the string 7 | */ 8 | int _strlen_recursion(char *s) 9 | { 10 | if (*s) 11 | return (1 + _strlen_recursion(s + 1)); 12 | return (0); 13 | } 14 | -------------------------------------------------------------------------------- /0x08-recursion/3-factorial: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/3-factorial -------------------------------------------------------------------------------- /0x08-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * factorial - a function that returns the factorial of a number. 5 | * @n: An input integer 6 | * Return: The factorial of n 7 | */ 8 | int factorial(int n) 9 | { 10 | if (n < 0) 11 | return (-1); 12 | if (n <= 1) 13 | return (1); 14 | return (n * factorial(n - 1)); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-recursion/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 | int r; 12 | 13 | r = factorial(1); 14 | printf("%d\n", r); 15 | r = factorial(5); 16 | printf("%d\n", r); 17 | r = factorial(10); 18 | printf("%d\n", r); 19 | r = factorial(-1024); 20 | printf("%d\n", r); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x08-recursion/4-pow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/4-pow -------------------------------------------------------------------------------- /0x08-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _pow_recursion - It returns the value of x raised to the power y. 5 | * @x: the base 6 | * @y: the exponent 7 | * Return: The result of x raised y 8 | */ 9 | int _pow_recursion(int x, int y) 10 | { 11 | if (y == 0) 12 | return (1); 13 | else if (y < 0) 14 | return (-1); 15 | else if (y == 1) 16 | return (x); 17 | return (x *= _pow_recursion(x, y - 1)); 18 | } 19 | -------------------------------------------------------------------------------- /0x08-recursion/5-sqrt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/5-sqrt -------------------------------------------------------------------------------- /0x08-recursion/6-prime: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/6-prime -------------------------------------------------------------------------------- /0x08-recursion/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 | -------------------------------------------------------------------------------- /0x08-recursion/7-palindrome: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/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 | -------------------------------------------------------------------------------- /0x08-recursion/holberton.h: -------------------------------------------------------------------------------- 1 | void _puts_recursion(char *s); 2 | int _putchar(char c); 3 | void _print_rev_recursion(char *s); 4 | int _strlen_recursion(char *s); 5 | int factorial(int n); 6 | int _pow_recursion(int x, int y); 7 | int _sqrt_recursion(int n); 8 | int is_prime_number(int n); 9 | int is_palindrome(char *s); 10 | int wildcmp(char *s1, char *s2); 11 | -------------------------------------------------------------------------------- /0x08-recursion/holberton.h.gch: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x08-recursion/holberton.h.gch -------------------------------------------------------------------------------- /0x09-static_libraries/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - A function that checks for uppercase character. 5 | * @c: An input character 6 | * Return: 1 if c is uppercase or 0 otherwise 7 | */ 8 | int _isupper(int c) 9 | { 10 | char uppercase = 'A'; 11 | int isupper = 0; 12 | 13 | for (; uppercase <= 'Z'; uppercase++) 14 | { 15 | if (c == uppercase) 16 | { 17 | isupper = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isupper); 23 | } 24 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/0-isupper.o -------------------------------------------------------------------------------- /0x09-static_libraries/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - a function that fills memory with constant bytes 5 | * @s: location to fill 6 | * @b: char to fill location with 7 | * @n: number of bytes to fill 8 | * Return: returns pointer to location filled 9 | */ 10 | char *_memset(char *s, char b, unsigned int n) 11 | { 12 | char *start = s; 13 | 14 | while (n--) 15 | { 16 | *s = b; 17 | s++; 18 | } 19 | return (start); 20 | } 21 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/0-memset.o -------------------------------------------------------------------------------- /0x09-static_libraries/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcat - a function that concatenates two strings. 5 | * @dest: an input string 6 | * @src: an input string 7 | * Return: A pointer to the resulting string 8 | */ 9 | char *_strcat(char *dest, char *src) 10 | { 11 | char *temp = dest; 12 | 13 | while (*dest) 14 | dest++; 15 | 16 | while (*src) 17 | *dest++ = *src++; 18 | 19 | *dest = '\0'; 20 | return (temp); 21 | } 22 | -------------------------------------------------------------------------------- /0x09-static_libraries/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - A function that checks for a digit (0 through 9). 5 | * @c: An input integer 6 | * Return: 1 if c is a digit or 0 otherwise 7 | */ 8 | int _isdigit(int c) 9 | { 10 | char i = '0'; 11 | int isdigit = 0; 12 | 13 | for (; i <= '9'; i++) 14 | { 15 | if (i == c) 16 | { 17 | isdigit = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isdigit); 23 | } 24 | -------------------------------------------------------------------------------- /0x09-static_libraries/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/1-isdigit.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - a function that copys memory area 5 | * @dest: memory area destination to copy 6 | * @src: memory area source to copy from 7 | * @n: number of bytes 8 | * Return: returns pointer to copy location 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | char *start = dest; 13 | 14 | while (n--) 15 | { 16 | *dest = *src; 17 | src++; 18 | dest++; 19 | } 20 | return (start); 21 | } 22 | -------------------------------------------------------------------------------- /0x09-static_libraries/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/1-memcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/1-strncat.o -------------------------------------------------------------------------------- /0x09-static_libraries/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strchr - a function that locates a character in a string. 6 | * @s: an input string to search in 7 | * @c: an input character to locate into string s 8 | * Return: returns pointer to c position 9 | */ 10 | char *_strchr(char *s, char c) 11 | { 12 | 13 | while (*s) 14 | { 15 | if (c == *s) 16 | return (s); 17 | s++; 18 | } 19 | if (c == *s) 20 | return (s); 21 | return (NULL); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/2-strchr.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - a function that returns the length of a string. 5 | * @s: An input string 6 | * Return: Nothing 7 | */ 8 | int _strlen(char *s) 9 | { 10 | int len = 0; 11 | 12 | while (s[len] != '\0') 13 | len++; 14 | return (len); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x09-static_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/2-strncpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check Holberton 5 | * @c: An input character 6 | * Description: function uses _putchar function to print 7 | * alphabet in lowercase 10 times 8 | * Return: 1 if is lowercase or 0 if is uppercase 9 | */ 10 | int _islower(int c) 11 | { 12 | char i; 13 | int lower = 0; 14 | 15 | for (i = 'a'; i <= 'z'; i++) 16 | { 17 | if (i == c) 18 | lower = 1; 19 | } 20 | 21 | return (lower); 22 | } 23 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/3-islower.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed 5 | * by a new line, to stdout. 6 | * @str: an input string 7 | * Return: Nothing 8 | */ 9 | void _puts(char *str) 10 | { 11 | int i = 0; 12 | 13 | while (str[i] != '\0') 14 | { 15 | _putchar(str[i]); 16 | i++; 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x09-static_libraries/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/3-puts.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x09-static_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/3-strspn.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isalpha - Check Holberton 5 | * @c: An input character 6 | * Description: function returns 1 if the character is a 7 | * letter, lowercase or uppercase. 8 | * Return: 1 or 0 in otherwise. 9 | */ 10 | int _isalpha(int c) 11 | { 12 | char lower, upper; 13 | int isletter = 0; 14 | 15 | for (lower = 'a'; lower <= 'z'; lower++) 16 | { 17 | for (upper = 'A'; upper <= 'Z'; upper++) 18 | { 19 | if (c == lower || c == upper) 20 | isletter = 1; 21 | } 22 | } 23 | return (isletter); 24 | } 25 | -------------------------------------------------------------------------------- /0x09-static_libraries/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x09-static_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x09-static_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/5-strstr.o -------------------------------------------------------------------------------- /0x09-static_libraries/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_abs - Check Holberton 5 | * @r: An integre input 6 | * Description: This function returns absolute value of a number 7 | * Return: Absolut value of number r 8 | */ 9 | int _abs(int r) 10 | { 11 | if (r >= 0) 12 | return (r); 13 | else 14 | return (r * -1); 15 | } 16 | -------------------------------------------------------------------------------- /0x09-static_libraries/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/6-abs.o -------------------------------------------------------------------------------- /0x09-static_libraries/9-strcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _strcpy - a function that copies the string pointed to by src, 3 | * including the terminating null byte (\0), 4 | * to the buffer pointed to by dest. 5 | * 6 | * @dest: A pointer to destination of string 7 | * @src: A pointer to source string to copy from 8 | * 9 | * Return: pointer to dest 10 | */ 11 | char *_strcpy(char *dest, char *src) 12 | { 13 | char *aux = dest; 14 | 15 | while (*src) 16 | *dest++ = *src++; 17 | return (aux); 18 | } 19 | -------------------------------------------------------------------------------- /0x09-static_libraries/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x09-static_libraries/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x09-static_libraries/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/_putchar.o -------------------------------------------------------------------------------- /0x09-static_libraries/create_static_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -Wall -pedantic -Werror -Wextra -c *.c 3 | ar -rc liball.a *.o 4 | -------------------------------------------------------------------------------- /0x09-static_libraries/liball.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/liball.a -------------------------------------------------------------------------------- /0x09-static_libraries/libholberton.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/libholberton.a -------------------------------------------------------------------------------- /0x09-static_libraries/main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | int main(void) 4 | { 5 | _puts("\"At the end of the day, my goal was to be the best hacker\"\n\t- Kevin Mitnick"); 6 | return (0); 7 | } 8 | -------------------------------------------------------------------------------- /0x09-static_libraries/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/main.o -------------------------------------------------------------------------------- /0x09-static_libraries/quote: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x09-static_libraries/quote -------------------------------------------------------------------------------- /0x0A-argc_argv/0-whatsmyname.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - a program that prints its name, followed by a new line 6 | * @argc: arguement count 7 | * @argv: argument value, a strings that come after calling function 8 | * Return: Always 0 (Success) 9 | */ 10 | int main(int argc, char *argv[]) 11 | { 12 | if (argc > 0) 13 | printf("%s\n", argv[0]); 14 | 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0A-argc_argv/1-args.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - A program that prints the number of arguements you passed into it 6 | * @argc: An argument counter 7 | * @argv: An argument values 8 | * Return: Always 0 (Success) 9 | */ 10 | int main(int argc, char *argv[]) 11 | { 12 | if (argv[0]) 13 | printf("%d\n", argc - 1); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0A-argc_argv/2-args.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - A program that prints all arguements it receives 6 | * @argc: The arguement counter 7 | * @argv: The arguement values 8 | * Return: Always 0 (Success) 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | while (argc--) 13 | { 14 | printf("%s\n", *argv++); 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0A-argc_argv/3-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - A program that multiplies two numbers 6 | * @argc: The arguments' counter 7 | * @argv: The arguments' values 8 | * Return: Always 0 (Success) 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | int num1, num2, result; 13 | 14 | if (argc != 3) 15 | { 16 | printf("Error\n"); 17 | return (1); 18 | } 19 | else 20 | { 21 | num1 = atoi(argv[1]); 22 | num2 = atoi(argv[2]); 23 | result = num1 * num2; 24 | printf("%d\n", result); 25 | return (0); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x0A-argc_argv/_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 | -------------------------------------------------------------------------------- /0x0A-argc_argv/add: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/add -------------------------------------------------------------------------------- /0x0A-argc_argv/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/args -------------------------------------------------------------------------------- /0x0A-argc_argv/change: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/change -------------------------------------------------------------------------------- /0x0A-argc_argv/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | -------------------------------------------------------------------------------- /0x0A-argc_argv/mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/mul -------------------------------------------------------------------------------- /0x0A-argc_argv/mynewnameis: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/mynewnameis -------------------------------------------------------------------------------- /0x0A-argc_argv/nargs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0A-argc_argv/nargs -------------------------------------------------------------------------------- /0x0B-malloc_free/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/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("Betty ", "Holberton"); 15 | if (s == NULL) 16 | { 17 | printf("failed\n"); 18 | return (1); 19 | } 20 | printf("%s\n", s); 21 | free(s); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x0B-malloc_free/4-free_grid.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * free_grid - A function that frees a 2D array of ints previously 6 | * created by your malloc_grid function 7 | * @grid: An input 2D array of integers to free 8 | * @height: height of grid 9 | * Return: Nothing 10 | */ 11 | void free_grid(int **grid, int height) 12 | { 13 | int i = 0; 14 | 15 | if (grid == NULL) 16 | return; 17 | while (i < height) 18 | free((int *)grid[i++]); 19 | free(grid); 20 | } 21 | -------------------------------------------------------------------------------- /0x0B-malloc_free/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 | -------------------------------------------------------------------------------- /0x0B-malloc_free/_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 | -------------------------------------------------------------------------------- /0x0B-malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/a -------------------------------------------------------------------------------- /0x0B-malloc_free/args: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/args -------------------------------------------------------------------------------- /0x0B-malloc_free/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/c -------------------------------------------------------------------------------- /0x0B-malloc_free/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/f -------------------------------------------------------------------------------- /0x0B-malloc_free/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/g -------------------------------------------------------------------------------- /0x0B-malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | char *create_array(unsigned int size, char c); 3 | char *_strdup(char *str); 4 | char *str_concat(char *s1, char *s2); 5 | int **alloc_grid(int width, int height); 6 | void free_grid(int **grid, int height); 7 | char *argstostr(int ac, char **av); 8 | char **strtow(char *str); 9 | -------------------------------------------------------------------------------- /0x0B-malloc_free/s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/s -------------------------------------------------------------------------------- /0x0B-malloc_free/strtow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0B-malloc_free/strtow -------------------------------------------------------------------------------- /0x0C-more_malloc_free/0-malloc_checked.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * malloc_checked - A function that allocates memory using malloc. 6 | * @b: An unsigned input integer 7 | * Return: Apointer to allocated memory or NULL if it fails 8 | */ 9 | void *malloc_checked(unsigned int b) 10 | { 11 | void *s; 12 | 13 | s = malloc(b); 14 | 15 | if (s == NULL) 16 | exit(98); 17 | 18 | return (s); 19 | } 20 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/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 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/101-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - Check the code 6 | * @argc: number of arguments 7 | * @argv: arguments 8 | * Return: Nothing 9 | */ 10 | int main(int argc, char **argv) 11 | { 12 | int num1, num2, result; 13 | 14 | if (argc != 3) 15 | { 16 | printf("Error\n"); 17 | exit(98); 18 | } 19 | else 20 | { 21 | num1 = atoi(argv[1]); 22 | num2 = atoi(argv[2]); 23 | result = num1 * num2; 24 | printf("%d\n", result); 25 | return (0); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/_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 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/a -------------------------------------------------------------------------------- /0x0C-more_malloc_free/a}: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/a} -------------------------------------------------------------------------------- /0x0C-more_malloc_free/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/b -------------------------------------------------------------------------------- /0x0C-more_malloc_free/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/c -------------------------------------------------------------------------------- /0x0C-more_malloc_free/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/d -------------------------------------------------------------------------------- /0x0C-more_malloc_free/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/e -------------------------------------------------------------------------------- /0x0C-more_malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void *malloc_checked(unsigned int b); 3 | char *string_nconcat(char *s1, char *s2, unsigned int n); 4 | void *_calloc(unsigned int nmemb, unsigned int size); 5 | int *array_range(int min, int max); 6 | void *_realloc(void *ptr, unsigned int old_size, unsigned int new_size); 7 | -------------------------------------------------------------------------------- /0x0C-more_malloc_free/mul: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0C-more_malloc_free/mul -------------------------------------------------------------------------------- /0x0D-preprocessor/0-main.c: -------------------------------------------------------------------------------- 1 | #include "0-object_like_macro.h" 2 | #include "0-object_like_macro.h" 3 | #include 4 | 5 | /** 6 | * main - check the code 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 | -------------------------------------------------------------------------------- /0x0D-preprocessor/0-object_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef _OBJECT_LIKE_MACRO_H_ 2 | #define _OBJECT_LIKE_MACRO_H_ 3 | #define SIZE 1024 4 | #endif /* _OBJECT_LIKE_MACRO_H_ */ 5 | -------------------------------------------------------------------------------- /0x0D-preprocessor/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/1-pi.h: -------------------------------------------------------------------------------- 1 | #ifndef _PI_H 2 | #define _PI_H 3 | #define PI 3.14159265359 4 | #endif 5 | -------------------------------------------------------------------------------- /0x0D-preprocessor/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - prints the name of file 4 | * Return: Always 0 (Success) 5 | */ 6 | int main(void) 7 | { 8 | printf("%s\n", __FILE__); 9 | return (0); 10 | } 11 | -------------------------------------------------------------------------------- /0x0D-preprocessor/3-function_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef _FUNC_LIKE_MACRO_H 2 | #define _FUNC_LIKE_MACRO_H 3 | #define ABS(x) (((x) < 0) ? -(x) : (x)) 4 | #endif 5 | -------------------------------------------------------------------------------- /0x0D-preprocessor/3-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "3-function_like_macro.h" 3 | #include "3-function_like_macro.h" 4 | 5 | /** 6 | * main - check the code 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/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 | -------------------------------------------------------------------------------- /0x0D-preprocessor/4-sum.h: -------------------------------------------------------------------------------- 1 | #ifndef _SUM_H 2 | #define _SUM_H 3 | #define SUM(X, Y) ((X) + (Y)) 4 | #endif 5 | -------------------------------------------------------------------------------- /0x0D-preprocessor/_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 | -------------------------------------------------------------------------------- /0x0D-preprocessor/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0D-preprocessor/d -------------------------------------------------------------------------------- /0x0D-preprocessor/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0D-preprocessor/e -------------------------------------------------------------------------------- /0x0D-preprocessor/holberton.h: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * Return: Always 0. 7 | */ 8 | int main(void) 9 | { 10 | struct dog my_dog; 11 | 12 | my_dog.name = "Candy"; 13 | my_dog.age = 4.8; 14 | my_dog.owner = "Meco"; 15 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | 4 | /** 5 | * init_dog - a function that initialize a variable of type struct dog. 6 | * @d: struct to initialize 7 | * @name: Dog's name 8 | * @age: Dog's age 9 | * @owner: Dog's owner 10 | * Return: Nothing. 11 | */ 12 | void init_dog(struct dog *d, char *name, float age, char *owner) 13 | { 14 | if (d == NULL) 15 | return; 16 | 17 | d->name = name; 18 | d->age = age; 19 | d->owner = owner; 20 | } 21 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/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, "Jay"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code 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 = "Jay"; 16 | print_dog(&my_dog); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/2-print_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | 4 | /** 5 | * print_dog - a function that prints a struct dog. 6 | * @d: struct to initialize 7 | * Return: Nothing. 8 | */ 9 | void print_dog(struct dog *d) 10 | { 11 | if (d == NULL) 12 | return; 13 | if (d->name == NULL) 14 | d->name = "(nil)"; 15 | if (d->owner == NULL) 16 | d->owner = "(nil)"; 17 | 18 | printf("Name: %s\nAge: %0.6f\nOwner: %s\n", d->name, d->age, d->owner); 19 | } 20 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/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, "Jay"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/5-free_dog.c: -------------------------------------------------------------------------------- 1 | #include "dog.h" 2 | #include 3 | 4 | /** 5 | * free_dog - frees a dog structure 6 | * @d: pointer to struct to free 7 | * Return: Nothing 8 | */ 9 | void free_dog(dog_t *d) 10 | { 11 | if (d == NULL) 12 | return; 13 | if (d->name != NULL) 14 | free(d->name); 15 | if (d->owner != NULL) 16 | free(d->owner); 17 | free(d); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/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, "Jay"); 14 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog->name, my_dog->age); 15 | free_dog(my_dog); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/_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 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0E-structures_typedef/a -------------------------------------------------------------------------------- /0x0E-structures_typedef/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0E-structures_typedef/b -------------------------------------------------------------------------------- /0x0E-structures_typedef/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0E-structures_typedef/c -------------------------------------------------------------------------------- /0x0E-structures_typedef/dog.h: -------------------------------------------------------------------------------- 1 | #ifndef _DOG_H_ 2 | #define _DOG_H_ 3 | 4 | /** 5 | * struct dog - structure for a basic dog 6 | * @name: Dog's name 7 | * @age: Dog's age 8 | * @owner: Dog's owner 9 | * Description: data structure for dog 10 | */ 11 | struct dog 12 | { 13 | char *name; 14 | float age; 15 | char *owner; 16 | }; 17 | typedef struct dog dog_t; 18 | void init_dog(struct dog *d, char *name, float age, char *owner); 19 | void print_dog(struct dog *d); 20 | dog_t *new_dog(char *name, float age, char *owner); 21 | void free_dog(dog_t *d); 22 | #endif 23 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/dog.h~: -------------------------------------------------------------------------------- 1 | int _putchar(char c); 2 | void init_dog(struct dog *d, char *name, float age, char *owner); 3 | void print_dog(struct dog *d); 4 | void free_dog(dog_t *d); 5 | -------------------------------------------------------------------------------- /0x0E-structures_typedef/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0E-structures_typedef/e -------------------------------------------------------------------------------- /0x0F-function_pointers/0-print_name.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "function_pointers.h" 3 | 4 | /** 5 | * print_name - a function that prints a name. 6 | * @name: pointer to name to print 7 | * @f: function to print name 8 | * Return: Nothing 9 | */ 10 | void print_name(char *name, void (*f)(char *name)) 11 | { 12 | if (name == NULL || f == NULL) 13 | return; 14 | f(name); 15 | } 16 | -------------------------------------------------------------------------------- /0x0F-function_pointers/1-array_iterator.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * array_iterator - a function that executes a function given as 5 | * a parameter on each element of an array. 6 | * @array: A pointer to array 7 | * @size: Size of the array 8 | * @action: action(function) to iterate throw array 9 | * Return: Nothing 10 | */ 11 | void array_iterator(int *array, size_t size, void (*action)(int)) 12 | { 13 | unsigned int i = 0; 14 | 15 | if (action == NULL || array == NULL) 16 | return; 17 | 18 | for (; i < size; i++) 19 | action(array[i]); 20 | } 21 | -------------------------------------------------------------------------------- /0x0F-function_pointers/1-main.c~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/1-main.c~ -------------------------------------------------------------------------------- /0x0F-function_pointers/3-calc.h: -------------------------------------------------------------------------------- 1 | #ifndef CALC_H 2 | #define CALC_H 3 | 4 | /** 5 | * struct op - Struct op 6 | * 7 | * @op: The operator 8 | * @f: The function associated 9 | */ 10 | typedef struct op 11 | { 12 | char *op; 13 | int (*f)(int a, int b); 14 | } op_t; 15 | 16 | int op_add(int a, int b); 17 | int op_sub(int a, int b); 18 | int op_mul(int a, int b); 19 | int op_div(int a, int b); 20 | int op_mod(int a, int b); 21 | int (*get_op_func(char *s))(int, int); 22 | #endif 23 | -------------------------------------------------------------------------------- /0x0F-function_pointers/_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 | -------------------------------------------------------------------------------- /0x0F-function_pointers/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/a -------------------------------------------------------------------------------- /0x0F-function_pointers/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/b -------------------------------------------------------------------------------- /0x0F-function_pointers/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/c -------------------------------------------------------------------------------- /0x0F-function_pointers/calc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/calc -------------------------------------------------------------------------------- /0x0F-function_pointers/function_pointers.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H 2 | #define HOLBERTON_H 3 | int _putchar(char c); 4 | void print_name(char *name, void (*f)(char *)); 5 | void array_iterator(int *array, size_t size, void (*action)(int)); 6 | int int_index(int *array, int size, int (*cmp)(int)); 7 | #endif 8 | -------------------------------------------------------------------------------- /0x0F-function_pointers/main: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x0F-function_pointers/main -------------------------------------------------------------------------------- /0x10-variadic_functions/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/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/100-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | 2 | global main 3 | 4 | section .text 5 | main: 6 | mov rax, 1 7 | mov rdi, 1 8 | mov rsi, message 9 | mov rdx, 17 10 | syscall 11 | 12 | mov eax, 60 13 | xor rdi, rdi 14 | syscall 15 | 16 | message: 17 | db "Hello, Holberton", 10 18 | -------------------------------------------------------------------------------- /0x10-variadic_functions/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(", ", 2, "Jay", "Django"); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/2-main.c~: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x10-variadic_functions/2-main.c~ -------------------------------------------------------------------------------- /0x10-variadic_functions/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("ceisf", 'H', 0, "lberton", 3.5); 11 | return (0); 12 | } 13 | -------------------------------------------------------------------------------- /0x10-variadic_functions/_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 | -------------------------------------------------------------------------------- /0x10-variadic_functions/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x10-variadic_functions/a -------------------------------------------------------------------------------- /0x10-variadic_functions/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x10-variadic_functions/b -------------------------------------------------------------------------------- /0x10-variadic_functions/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x10-variadic_functions/c -------------------------------------------------------------------------------- /0x10-variadic_functions/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x10-variadic_functions/d -------------------------------------------------------------------------------- /0x10-variadic_functions/variadic_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef VARIADIC_FUNCTIONS_H 2 | #define VARIADIC_FUNCTIONS_H 3 | 4 | int _putchar(char c); 5 | int sum_them_all(const unsigned int n, ...); 6 | void print_numbers(const char *separator, const unsigned int n, ...); 7 | void print_strings(const char *separator, const unsigned int n, ...); 8 | void print_all(const char * const format, ...); 9 | #endif 10 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/#100-first.c#: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Using constructors in C! Who knew!? */ 4 | void main_constructor(void) __attribute__((constructor)); 5 | /** 6 | * main_constructor - constructor function that runs before main () 7 | * 8 | * Return: always void 9 | */ 10 | void main_constructor(void) 11 | { 12 | printf("You're beat! and yet, you must allow,\n"); 13 | printf("I bore my house upon my back!\n"); 14 | } -------------------------------------------------------------------------------- /0x12-singly_linked_lists/0-print_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * print_list - A function that prints a linked list 6 | * @h: pointer t head of list 7 | * Return: number of nodes in list as size_t 8 | */ 9 | size_t print_list(const list_t *h) 10 | { 11 | unsigned int nodes = 0; 12 | 13 | while (h) 14 | { 15 | printf("[%u] ", h->len); 16 | if (h->str == NULL) 17 | printf("(nil)\n"); 18 | else 19 | printf("%s\n", h->str); 20 | 21 | h = h->next; 22 | nodes++; 23 | } 24 | return (nodes); 25 | } 26 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * list_len - A function that gets the number of nodes of linked list 5 | * @h: head of linked list 6 | * Return: number of nodes as size_t 7 | */ 8 | size_t list_len(const list_t *h) 9 | { 10 | unsigned int nodes = 0; 11 | 12 | while (h) 13 | { 14 | nodes++; 15 | h = h->next; 16 | } 17 | return (nodes); 18 | } 19 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-list_len_recursion.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * list_len_recursion - A function that gets the number of nodes of linked list 5 | * @h: head of linked list 6 | * Return: number of nodes as size_t 7 | */ 8 | size_t list_len_recursion(const list_t *h) 9 | { 10 | if (h != NULL) 11 | return (1 + list_len_recursion(h->next)); 12 | } 13 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/1-main.c~: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | /** 3 | * list_len - gets the linked lists number of nodes 4 | * @h: head of list 5 | * 6 | * Return: number of nodes as size_t 7 | */ 8 | size_t list_len(const list_t *h) 9 | { 10 | const list_t *temp; 11 | size_t n_nodes = 0; 12 | 13 | temp = h; 14 | while (temp != NULL) 15 | { 16 | temp = temp->next; 17 | n_nodes++; 18 | } 19 | return (n_nodes); 20 | } 21 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/100-first.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Using constructors in C */ 4 | void main_constructor(void) __attribute__((constructor)); 5 | /** 6 | * main_constructor - A constructor function that prints a message 7 | * before main runs 8 | * Return: Nothing 9 | */ 10 | void main_constructor(void) 11 | { 12 | printf("You're beat! and yet, you must allow,\n"); 13 | printf("I bore my house upon my back!\n"); 14 | } 15 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/101-hello_holberton.asm: -------------------------------------------------------------------------------- 1 | extern printf 2 | 3 | section .data 4 | msg: db "Hello, Holberton", 0 5 | fmt: db "%s", 10, 0 6 | 7 | section .text 8 | 9 | global main 10 | main: 11 | push rbp 12 | mov rdi,fmt 13 | mov rsi,msg 14 | mov rax,0 15 | call printf 16 | pop rbp 17 | mov rax,0 18 | ret 19 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/4-free_list.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_list - A function that frees all elements in a linked list 5 | * @head: pointer to head element of list 6 | * Return: Nothing 7 | */ 8 | void free_list(list_t *head) 9 | { 10 | list_t *temp; 11 | 12 | temp = head; 13 | while (head) 14 | { 15 | temp = head; 16 | head = head->next; 17 | free(temp->str); 18 | free(temp); 19 | } 20 | free(head); 21 | } 22 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/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, "Jennie"); 17 | add_node_end(&head, "&"); 18 | add_node_end(&head, "Jay"); 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 | -------------------------------------------------------------------------------- /0x12-singly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x12-singly_linked_lists/a -------------------------------------------------------------------------------- /0x12-singly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x12-singly_linked_lists/b -------------------------------------------------------------------------------- /0x12-singly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x12-singly_linked_lists/c -------------------------------------------------------------------------------- /0x12-singly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x12-singly_linked_lists/d -------------------------------------------------------------------------------- /0x12-singly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x12-singly_linked_lists/e -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-print_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * print_listint - A function that prints all the elements in the list 6 | * @h: A pointer to listint structure 7 | * Return: the number of nodes. 8 | */ 9 | size_t print_listint(const listint_t *h) 10 | { 11 | size_t nodes = 0; 12 | 13 | while (h) 14 | { 15 | printf("%d\n", h->n); 16 | h = h->next; 17 | nodes++; 18 | } 19 | return (nodes); 20 | } 21 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/0-recursion_print_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * recursion_printer - A function that prints all the elements in the list 6 | * @h: A pointer to listint structure 7 | * Return: the number of nodes. 8 | */ 9 | size_t recursion_printer(const listint_t *h) 10 | { 11 | printf("%d\n", h->n); 12 | return (1 + recursion_printer(h->next)); 13 | } 14 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/1-listint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * listint_len - A function that returns the number of elements in the list 6 | * @h: A pointer to listint_t structure 7 | * Return: number of elements. 8 | */ 9 | size_t listint_len(const listint_t *h) 10 | { 11 | size_t nodes = 0; 12 | 13 | while (h) 14 | { 15 | h = h->next; 16 | nodes++; 17 | } 18 | return (nodes); 19 | } 20 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/103-find_loop.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * find_listint_loop - A function that finds the loop in a list 5 | * @head: A pointer to listint_t structure 6 | * Return: The address of the node where the loop start, or NULL 7 | */ 8 | listint_t *find_listint_loop(listint_t *head) 9 | { 10 | listint_t *one = head, *two = head; 11 | 12 | while (one && two && two->next) 13 | { 14 | one = one->next; 15 | two = two->next->next; 16 | if (one == two) 17 | { 18 | return (one); 19 | } 20 | } 21 | return (NULL); 22 | } 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/4-free_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_listint - A function that frees a linked list 5 | * @head: A pointer to listint_t structure 6 | * Return: Nothing 7 | */ 8 | void free_listint(listint_t *head) 9 | { 10 | listint_t *temp; 11 | 12 | while (head) 13 | { 14 | temp = head; 15 | head = head->next; 16 | free(temp); 17 | } 18 | free(head); 19 | } 20 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/5-free_listint2.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_listint2 - A function that frees a list and sets head to NULL 5 | * @head: A pointer to listint_t structure 6 | * Return: Nothing. 7 | */ 8 | void free_listint2(listint_t **head) 9 | { 10 | listint_t *temp; 11 | 12 | if (head == NULL) 13 | return; 14 | 15 | temp = *head; 16 | while (*head) 17 | { 18 | temp = *head; 19 | (*head) = (*head)->next; 20 | free(temp); 21 | } 22 | *head = NULL; 23 | } 24 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/6-pop_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * pop_listint - A function that deletes the head node of a list 5 | * and returns the head node's data n. 6 | * @head: A pointer to listint_t structure. 7 | * Return: The head node's datafrom deleted element 8 | */ 9 | int pop_listint(listint_t **head) 10 | { 11 | listint_t *new_node; 12 | int n; 13 | 14 | if (*head == NULL) 15 | return (0); 16 | 17 | n = (*head)->n; 18 | new_node = (*head)->next; 19 | free(*head); 20 | *head = new_node; 21 | return (n); 22 | } 23 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/8-sum_listint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_listint - A function that sums values from listint_t 5 | * @head: A pointer listint_t structure 6 | * Return: The sum of all the data n from list 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) 16 | { 17 | sum += head->n; 18 | head = head->next; 19 | } 20 | return (sum); 21 | } 22 | -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/a -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/b -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/c -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/d -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/e -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/f -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/g -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/h -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/i -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/j: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/j -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/k -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/l: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/l -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/m -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/n: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/n -------------------------------------------------------------------------------- /0x13-more_singly_linked_lists/o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x13-more_singly_linked_lists/o -------------------------------------------------------------------------------- /0x14-bit_manipulation/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/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 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-get_endianness.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * get_endianness - A function that checks endianness 5 | * Return: 0 if big endian, 1 if little endian 6 | */ 7 | int get_endianness(void) 8 | { 9 | unsigned int i = 1; 10 | char *c = (char *)&i; 11 | 12 | if (*c) 13 | return (1); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/100-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | 4 | int main(void) 5 | { 6 | int n; 7 | 8 | n = get_endianness(); 9 | if (n != 0) 10 | { 11 | printf("Little Endian\n"); 12 | } 13 | else 14 | { 15 | printf("Big Endian\n"); 16 | } 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/101-password: -------------------------------------------------------------------------------- 1 | Hol 2 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-get_bit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * get_bit - A function that gets a bit at index 5 | * @n: The number to get bit from 6 | * @index: The index where the bit get at 7 | * Return: The value of the bit or -1 if an error occured 8 | */ 9 | int get_bit(unsigned long int n, unsigned int index) 10 | { 11 | unsigned long int max = 0x01; 12 | 13 | max <<= index; 14 | if (max == 0) 15 | return (-1); 16 | 17 | if ((n & max)) 18 | return (1); 19 | else 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/2-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 | int n; 12 | 13 | n = get_bit(1024, 10); 14 | printf("%d\n", n); 15 | n = get_bit(98, 1); 16 | printf("%d\n", n); 17 | n = get_bit(1024, 0); 18 | printf("%d\n", n); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-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 long int n; 12 | 13 | n = 1024; 14 | set_bit(&n, 5); 15 | printf("%lu\n", n); 16 | n = 0; 17 | set_bit(&n, 10); 18 | printf("%lu\n", n); 19 | n = 98; 20 | set_bit(&n, 0); 21 | printf("%lu\n", n); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/3-set_bit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * set_bit - A function that sets a bit at given index to 1 5 | * @n: The number to set bit in 6 | * @index: The index to set bit at 7 | * Return: 1 if it worked, or -1 on error 8 | */ 9 | int set_bit(unsigned long int *n, unsigned int index) 10 | { 11 | unsigned long int max = 0x01; 12 | 13 | max <<= index; 14 | if (max == 0) 15 | return (-1); 16 | *n |= max; 17 | return (1); 18 | } 19 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-clear_bit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * clear_bit - A function that sets a bit to 0 at given index 5 | * @n: The number to set bit in 6 | * @index: The index to set bit at 7 | * Return: 1 if it worked, or -1 on error 8 | */ 9 | int clear_bit(unsigned long int *n, unsigned int index) 10 | { 11 | unsigned long int max = 0x01; 12 | 13 | max = ~(max << index); 14 | if (max == 0x00) 15 | return (-1); 16 | *n &= max; 17 | return (1); 18 | } 19 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/4-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 long int n; 12 | 13 | n = 1024; 14 | clear_bit(&n, 10); 15 | printf("%lu\n", n); 16 | n = 0; 17 | clear_bit(&n, 10); 18 | printf("%lu\n", n); 19 | n = 98; 20 | clear_bit(&n, 1); 21 | printf("%lu\n", n); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-flip_bits.c: -------------------------------------------------------------------------------- 1 | /** 2 | * flip_bits - A function that gets number of bits needed to flip 3 | * @n: How many bit flips are needed to equal m for n 4 | * @m: The number to set other equal 5 | * Return: The number of fliped bits 6 | */ 7 | unsigned int flip_bits(unsigned long int n, unsigned long int m) 8 | { 9 | unsigned int flips = 0; 10 | unsigned long int xor = (n ^ m); 11 | unsigned long int max = 0x01; 12 | 13 | while (max <= xor) 14 | { 15 | if (max & xor) 16 | flips++; 17 | max <<= 1; 18 | } 19 | return (flips); 20 | } 21 | -------------------------------------------------------------------------------- /0x14-bit_manipulation/5-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 = flip_bits(1024, 1); 14 | printf("%u\n", n); 15 | n = flip_bits(402, 98); 16 | printf("%u\n", n); 17 | n = flip_bits(1024, 3); 18 | printf("%u\n", n); 19 | n = flip_bits(1024, 1025); 20 | printf("%u\n", n); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /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/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/a -------------------------------------------------------------------------------- /0x14-bit_manipulation/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/b -------------------------------------------------------------------------------- /0x14-bit_manipulation/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/c -------------------------------------------------------------------------------- /0x14-bit_manipulation/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/d -------------------------------------------------------------------------------- /0x14-bit_manipulation/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/e -------------------------------------------------------------------------------- /0x14-bit_manipulation/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/f -------------------------------------------------------------------------------- /0x14-bit_manipulation/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x14-bit_manipulation/h -------------------------------------------------------------------------------- /0x14-bit_manipulation/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef _HOLBERTON_H_ 2 | #define _HOLBERTON_H_ 3 | #include 4 | 5 | unsigned int binary_to_uint(const char *b); 6 | void print_binary(unsigned long int n); 7 | void _putchar(char c); 8 | int get_bit(unsigned long int n, unsigned int index); 9 | int set_bit(unsigned long int *n, unsigned int index); 10 | int clear_bit(unsigned long int *n, unsigned int index); 11 | unsigned int flip_bits(unsigned long int n, unsigned long int m); 12 | int get_endianness(void); 13 | #endif /* _HOLBERTON_H_ */ 14 | -------------------------------------------------------------------------------- /0x15-file_io/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/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/100-elf_header.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - The entry point for program to get header of ELF file 5 | * @argc: The number of arguments 6 | * @argv: The pointer to array of arguments 7 | * Return: 1 on success, error code on failure 8 | */ 9 | int main(int argc, char *argv[]) 10 | { 11 | printf("argc:%d, argv:%p\n", argc, (void *)*argv); 12 | return (1); 13 | } 14 | -------------------------------------------------------------------------------- /0x15-file_io/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/Incitatous: -------------------------------------------------------------------------------- 1 | Why you should think twice before putting pictures on social media. 2 | (What you always wanted to know about @Incitatous) 3 | #PrivacyAware 4 | http://imgur.com/a/Mq1tc -------------------------------------------------------------------------------- /0x15-file_io/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x15-file_io/a -------------------------------------------------------------------------------- /0x15-file_io/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x15-file_io/b -------------------------------------------------------------------------------- /0x15-file_io/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x15-file_io/c -------------------------------------------------------------------------------- /0x15-file_io/cp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x15-file_io/cp -------------------------------------------------------------------------------- /0x15-file_io/hello: -------------------------------------------------------------------------------- 1 | Hello World! 2 | > -------------------------------------------------------------------------------- /0x15-file_io/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef __HOLBERTON_H__ 2 | #define __HOLBERTON_H__ 3 | ssize_t read_textfile(const char *filename, size_t letters); 4 | int create_file(const char *filename, char *text_content); 5 | int append_text_to_file(const char *filename, char *text_content); 6 | #endif /* __HOLBERTON_H__ */ 7 | -------------------------------------------------------------------------------- /0x15-file_io/incitatous: -------------------------------------------------------------------------------- 1 | Why you should think twice before putting pictures on social media. 2 | (What you always wanted to know about @Incitatous) 3 | #PrivacyAware 4 | http://imgur.com/a/Mq1tc -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/0-print_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | #include 3 | 4 | /** 5 | * print_dlistint - A function that prints a doubly linked list 6 | * @h: head of doubly linked list 7 | * Return: number of nodes in list 8 | */ 9 | size_t print_dlistint(const dlistint_t *h) 10 | { 11 | size_t nodes = 0; 12 | const dlistint_t *temp; 13 | 14 | temp = h; 15 | while (temp) 16 | { 17 | printf("%d\n", temp->n); 18 | temp = temp->next; 19 | nodes++; 20 | } 21 | return (nodes); 22 | } 23 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/1-dlistint_len.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * dlistint_len - A function that gets the length of the list 5 | * @h: The head of the list 6 | * Return: The number of nodes 7 | */ 8 | size_t dlistint_len(const dlistint_t *h) 9 | { 10 | size_t nodes = 0; 11 | const dlistint_t *temp; 12 | 13 | temp = h; 14 | while (temp) 15 | { 16 | temp = temp->next; 17 | nodes++; 18 | } 19 | return (nodes); 20 | } 21 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/100-password: -------------------------------------------------------------------------------- 1 | en C Pyfo neZ 2 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/102-result: -------------------------------------------------------------------------------- 1 | 906609 -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/4-free_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * free_dlistint - A function that frees a doubly linked list 5 | * @head: The pointer to head of doubly linked list to free 6 | * Return: Nothing 7 | */ 8 | void free_dlistint(dlistint_t *head) 9 | { 10 | dlistint_t *temp; 11 | 12 | while (head) 13 | { 14 | temp = head->next; 15 | free(head); 16 | head = temp; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/5-get_dnodeint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * get_dnodeint_at_index - A function that gets a node at index 5 | * @head: The pointer to head of list to look through 6 | * @index: The index of node to find 7 | * Return: A pointer to node if found, or NULL in otherwise 8 | */ 9 | dlistint_t *get_dnodeint_at_index(dlistint_t *head, unsigned int index) 10 | { 11 | unsigned int i = 0; 12 | 13 | while (head) 14 | { 15 | if (i++ == index) 16 | break; 17 | head = head->next; 18 | } 19 | return (head); 20 | } 21 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/6-sum_dlistint.c: -------------------------------------------------------------------------------- 1 | #include "lists.h" 2 | 3 | /** 4 | * sum_dlistint - A function that sums The elements in the list 5 | * @head: The pointer to head of the list 6 | * Return: The sum of all elements in the list, or 0 if list is NULL 7 | */ 8 | int sum_dlistint(dlistint_t *head) 9 | { 10 | int sum = 0; 11 | 12 | while (head) 13 | { 14 | sum += head->n; 15 | head = head->next; 16 | } 17 | return (sum); 18 | } 19 | -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/a -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/b: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/b -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/c -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/d: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/d -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/e: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/e -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/h -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/i: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/i -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/j: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/j -------------------------------------------------------------------------------- /0x17-doubly_linked_lists/k: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x17-doubly_linked_lists/k -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isupper - A function that checks for uppercase character. 5 | * @c: An input character 6 | * Return: 1 if c is uppercase or 0 otherwise 7 | */ 8 | int _isupper(int c) 9 | { 10 | char uppercase = 'A'; 11 | int isupper = 0; 12 | 13 | for (; uppercase <= 'Z'; uppercase++) 14 | { 15 | if (c == uppercase) 16 | { 17 | isupper = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isupper); 23 | } 24 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/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 (EXIT_SUCCESS); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memset - a function that fills memory with constant bytes 5 | * @s: location to fill 6 | * @b: char to fill location with 7 | * @n: number of bytes to fill 8 | * Return: returns pointer to location filled 9 | */ 10 | char *_memset(char *s, char b, unsigned int n) 11 | { 12 | char *start = s; 13 | 14 | while (n--) 15 | { 16 | *s = b; 17 | s++; 18 | } 19 | return (start); 20 | } 21 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcat - a function that concatenates two strings. 5 | * @dest: an input string 6 | * @src: an input string 7 | * Return: A pointer to the resulting string 8 | */ 9 | char *_strcat(char *dest, char *src) 10 | { 11 | char *temp = dest; 12 | 13 | while (*dest) 14 | dest++; 15 | 16 | while (*src) 17 | *dest++ = *src++; 18 | 19 | *dest = '\0'; 20 | return (temp); 21 | } 22 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-create_dynamic_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -fPIC *.c -shared -o liball.so 3 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isdigit - A function that checks for a digit (0 through 9). 5 | * @c: An input integer 6 | * Return: 1 if c is a digit or 0 otherwise 7 | */ 8 | int _isdigit(int c) 9 | { 10 | char i = '0'; 11 | int isdigit = 0; 12 | 13 | for (; i <= '9'; i++) 14 | { 15 | if (i == c) 16 | { 17 | isdigit = 1; 18 | break; 19 | } 20 | } 21 | 22 | return (isdigit); 23 | } 24 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _memcpy - a function that copys memory area 5 | * @dest: memory area destination to copy 6 | * @src: memory area source to copy from 7 | * @n: number of bytes 8 | * Return: returns pointer to copy location 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | char *start = dest; 13 | 14 | while (n--) 15 | { 16 | *dest = *src; 17 | src++; 18 | dest++; 19 | } 20 | return (start); 21 | } 22 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.c: -------------------------------------------------------------------------------- 1 | int add(int a, int b) 2 | { 3 | return (a + b); 4 | } 5 | 6 | int sub(int a, int b) 7 | { 8 | return (a - b); 9 | } 10 | 11 | int div(int a, int b) 12 | { 13 | return (a / b); 14 | } 15 | 16 | int mul(int a, int b) 17 | { 18 | return (a * b); 19 | } 20 | 21 | int mod(int a, int b) 22 | { 23 | return (a % b); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-operations.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x18-dynamic_libraries/100-operations.so -------------------------------------------------------------------------------- /0x18-dynamic_libraries/100-tests.py: -------------------------------------------------------------------------------- 1 | import random 2 | import ctypes 3 | 4 | cops = ctypes.CDLL('./100-operations.so') 5 | a = random.randint(-111, 111) 6 | b = random.randint(-111, 111) 7 | print("{} + {} = {}".format(a, b, cops.add(a, b))) 8 | print("{} - {} = {}".format(a, b, cops.sub(a, b))) 9 | print("{} x {} = {}".format(a, b, cops.mul(a, b))) 10 | print("{} / {} = {}".format(a, b, cops.div(a, b))) 11 | print("{} % {} = {}".format(a, b, cops.mod(a, b))) 12 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strchr - a function that locates a character in a string. 6 | * @s: an input string to search in 7 | * @c: an input character to locate into string s 8 | * Return: returns pointer to c position 9 | */ 10 | char *_strchr(char *s, char c) 11 | { 12 | 13 | while (*s) 14 | { 15 | if (c == *s) 16 | return (s); 17 | s++; 18 | } 19 | if (c == *s) 20 | return (s); 21 | return (NULL); 22 | } 23 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strlen - a function that returns the length of a string. 5 | * @s: An input string 6 | * Return: Nothing 7 | */ 8 | int _strlen(char *s) 9 | { 10 | int len = 0; 11 | 12 | while (s[len] != '\0') 13 | len++; 14 | return (len); 15 | } 16 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _islower - Check Holberton 5 | * @c: An input character 6 | * Description: function uses _putchar function to print 7 | * alphabet in lowercase 10 times 8 | * Return: 1 if is lowercase or 0 if is uppercase 9 | */ 10 | int _islower(int c) 11 | { 12 | char i; 13 | int lower = 0; 14 | 15 | for (i = 'a'; i <= 'z'; i++) 16 | { 17 | if (i == c) 18 | lower = 1; 19 | } 20 | 21 | return (lower); 22 | } 23 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _puts - Write a function that prints a string, followed 5 | * by a new line, to stdout. 6 | * @str: an input string 7 | * Return: Nothing 8 | */ 9 | void _puts(char *str) 10 | { 11 | int i = 0; 12 | 13 | while (str[i] != '\0') 14 | { 15 | _putchar(str[i]); 16 | i++; 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strcmp - a function that compares two strings. 5 | * @s1: an input string 6 | * @s2: an input string 7 | * Return: The difference s1 - s2 8 | */ 9 | int _strcmp(char *s1, char *s2) 10 | { 11 | while (*s1 && *s2) 12 | { 13 | if (*s1 != *s2) 14 | return (*s1 - *s2); 15 | s1++, s2++; 16 | } 17 | return (*s1 - *s2); 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _isalpha - Check Holberton 5 | * @c: An input character 6 | * Description: function returns 1 if the character is a 7 | * letter, lowercase or uppercase. 8 | * Return: 1 or 0 in otherwise. 9 | */ 10 | int _isalpha(int c) 11 | { 12 | char lower, upper; 13 | int isletter = 0; 14 | 15 | for (lower = 'a'; lower <= 'z'; lower++) 16 | { 17 | for (upper = 'A'; upper <= 'Z'; upper++) 18 | { 19 | if (c == lower || c == upper) 20 | isletter = 1; 21 | } 22 | } 23 | return (isletter); 24 | } 25 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_abs - Check Holberton 5 | * @r: An integre input 6 | * Description: This function returns absolute value of a number 7 | * Return: Absolut value of number r 8 | */ 9 | int _abs(int r) 10 | { 11 | if (r >= 0) 12 | return (r); 13 | else 14 | return (r * -1); 15 | } 16 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/9-strcpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _strcpy - a function that copies the string pointed to by src, 3 | * including the terminating null byte (\0), 4 | * to the buffer pointed to by dest. 5 | * 6 | * @dest: A pointer to destination of string 7 | * @src: A pointer to source string to copy from 8 | * 9 | * Return: pointer to dest 10 | */ 11 | char *_strcpy(char *dest, char *src) 12 | { 13 | char *aux = dest; 14 | 15 | while (*src) 16 | *dest++ = *src++; 17 | return (aux); 18 | } 19 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/_putchar.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | -------------------------------------------------------------------------------- /0x18-dynamic_libraries/len: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x18-dynamic_libraries/len -------------------------------------------------------------------------------- /0x18-dynamic_libraries/liball.s: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x18-dynamic_libraries/liball.s -------------------------------------------------------------------------------- /0x18-dynamic_libraries/libholberton.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x18-dynamic_libraries/libholberton.so -------------------------------------------------------------------------------- /0x1A-hash_tables/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "hash_tables.h" 5 | 6 | /** 7 | * main - check the code for 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/1-djb2.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * hash_djb2 - A function that passed the key to the hash table. 5 | * @str: The key to set/get in the hash table. 6 | * Return: The index in the has table. 7 | */ 8 | unsigned long int hash_djb2(const unsigned char *str) 9 | { 10 | unsigned long int hash; 11 | int c; 12 | 13 | hash = 5381; 14 | while ((c = *str++)) 15 | { 16 | hash = ((hash << 5) + hash) + c; /* hash * 33 + c */ 17 | } 18 | return (hash); 19 | } 20 | -------------------------------------------------------------------------------- /0x1A-hash_tables/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "hash_tables.h" 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always EXIT_SUCCESS. 10 | */ 11 | int main(void) 12 | { 13 | char *s; 14 | 15 | s = "cisfun"; 16 | printf("%lu\n", hash_djb2((unsigned char *)s)); 17 | s = "Don't forget to tweet today"; 18 | printf("%lu\n", hash_djb2((unsigned char *)s)); 19 | s = "98"; 20 | printf("%lu\n", hash_djb2((unsigned char *)s)); 21 | return (EXIT_SUCCESS); 22 | } 23 | -------------------------------------------------------------------------------- /0x1A-hash_tables/2-key_index.c: -------------------------------------------------------------------------------- 1 | #include "hash_tables.h" 2 | 3 | /** 4 | * key_index - A function that returns the normalized index for a key. 5 | * @key: The key to get/set in the has table. 6 | * @size: the size of the hash table 7 | * Return: Normalized index. 8 | */ 9 | unsigned long int key_index(const unsigned char *key, unsigned long int size) 10 | { 11 | unsigned long int index = 0; 12 | 13 | index = hash_djb2((unsigned char *)key); 14 | return (index % size); 15 | } 16 | -------------------------------------------------------------------------------- /0x1A-hash_tables/f: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1A-hash_tables/f -------------------------------------------------------------------------------- /0x1C-makefiles/0-Makefile: -------------------------------------------------------------------------------- 1 | all : main.c holberton.c m.h 2 | gcc main.c holberton.c -o holberton 3 | -------------------------------------------------------------------------------- /0x1C-makefiles/1-Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | SRC = main.c holberton.c 3 | 4 | all : $(SRC) m.h 5 | $(CC) $(SRC) -o holberton 6 | -------------------------------------------------------------------------------- /0x1C-makefiles/100-Makefile: -------------------------------------------------------------------------------- 1 | CC = gcc 2 | SRC = holberton.c main.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME = holberton 5 | CFLAGS = -Wall -Werror -Wextra -pedantic 6 | 7 | .PHONY: all clean oclean fclean re 8 | all: $(OBJ) m.h 9 | $(CC) $(OBJ) -o $(NAME) 10 | clean: 11 | $(RM) *~ $(NAME) 12 | oclean: 13 | $(RM) $(OBJ) 14 | fclean: clean oclean 15 | re: oclean all 16 | -------------------------------------------------------------------------------- /0x1C-makefiles/2-Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | SRC= main.c holberton.c 3 | OBJ=$(SRC:.c=.o) 4 | NAME=holberton 5 | 6 | all : $(OBJ) 7 | $(CC) $(OBJ) -o $(NAME) 8 | -------------------------------------------------------------------------------- /0x1C-makefiles/3-Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | SRC = main.c holberton.c 3 | OBJ =$(SRC:.c=.o) 4 | NAME=holberton 5 | RM=rm -f 6 | 7 | all : $(OBJ) 8 | $(CC) $(OBJ) -o $(NAME) 9 | 10 | .PHONY : clean oclean fclean 11 | 12 | clean : 13 | $(RM) *~ $(NAME) 14 | 15 | oclean : 16 | $(RM) $(OBJ) 17 | 18 | fclean : clean oclean 19 | 20 | re : oclean all 21 | -------------------------------------------------------------------------------- /0x1C-makefiles/4-Makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | SRC = main.c holberton.c 3 | OBJ = $(SRC:.c=.o) 4 | NAME=holberton 5 | RM=rm -f 6 | CFLAGS = -Wall -Werror -Wextra -pedantic 7 | 8 | all : $(OBJ) 9 | $(CC) $(OBJ) -o $(NAME) 10 | 11 | .PHONY : clean oclean fclean 12 | 13 | clean : 14 | $(RM) *~ $(NAME) 15 | 16 | oclean : 17 | $(RM) $(OBJ) 18 | 19 | fclean : clean oclean 20 | 21 | re : oclean all 22 | -------------------------------------------------------------------------------- /0x1C-makefiles/5-main.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | """ 3 | 5-main 4 | """ 5 | island_perimeter = __import__('5-island_perimeter').island_perimeter 6 | 7 | if __name__ == "__main__": 8 | grid = [ 9 | [0, 0, 0, 0, 0, 0], 10 | [0, 1, 0, 0, 0, 0], 11 | [0, 1, 0, 0, 0, 0], 12 | [0, 1, 1, 1, 0, 0], 13 | [0, 0, 0, 0, 0, 0] 14 | ] 15 | print(island_perimeter(grid)) 16 | -------------------------------------------------------------------------------- /0x1C-makefiles/__pycache__/5-island_perimeter.cpython-34.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1C-makefiles/__pycache__/5-island_perimeter.cpython-34.pyc -------------------------------------------------------------------------------- /0x1C-makefiles/holberton: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1C-makefiles/holberton -------------------------------------------------------------------------------- /0x1C-makefiles/holberton.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1C-makefiles/holberton.o -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x1C-makefiles/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1C-makefiles/main.o -------------------------------------------------------------------------------- /0x1E-search_algorithms/0-linear: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1E-search_algorithms/0-linear -------------------------------------------------------------------------------- /0x1E-search_algorithms/1-binary: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/0x1E-search_algorithms/1-binary -------------------------------------------------------------------------------- /0x1E-search_algorithms/101-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/107-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/108-O: -------------------------------------------------------------------------------- 1 | O(sqrt(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/2-O: -------------------------------------------------------------------------------- 1 | O(n) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/3-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/4-O: -------------------------------------------------------------------------------- 1 | O(log(n)) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/5-O: -------------------------------------------------------------------------------- 1 | O(1) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/6-O: -------------------------------------------------------------------------------- 1 | O(nm) 2 | -------------------------------------------------------------------------------- /0x1E-search_algorithms/search_algos.h: -------------------------------------------------------------------------------- 1 | #ifndef SEARCH_ALGOS_H 2 | #define SEARCH_ALGOS_H 3 | 4 | #include 5 | #include 6 | 7 | int linear_search(int *array, size_t size, int value); 8 | int binary_search(int *array, size_t size, int value); 9 | int jump_search(int *array, size_t size, int value); 10 | int interpolation_search(int *array, size_t size, int value); 11 | 12 | #endif /* SEARCH_ALGOS_H */ 13 | -------------------------------------------------------------------------------- /miniShell/0-av.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - a program that prints its name, followed by a new line 5 | * @argc: arguement count 6 | * @argv: argument value, a strings that come after calling function 7 | * Return: Always 0 (Success) 8 | */ 9 | int main(int argc, char *av[]) 10 | { 11 | while (*av) 12 | printf("%s\n", *av++); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /miniShell/1-read_getline.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | //int input(char *s,int length); 5 | 6 | int main() 7 | { 8 | char *buffer; 9 | size_t bufsize = 32; 10 | size_t characters; 11 | 12 | buffer = (char *)malloc(bufsize * sizeof(char)); 13 | if( buffer == NULL) 14 | { 15 | perror("Unable to allocate buffer"); 16 | exit(1); 17 | } 18 | 19 | printf(" $ "); 20 | characters = getline(&buffer,&bufsize,stdin); 21 | printf("%zu characters were read.\n",characters); 22 | printf("You typed: '%s'\n",buffer); 23 | 24 | return(0); 25 | } 26 | -------------------------------------------------------------------------------- /miniShell/1-read_line.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - An entry function 5 | * Return: Nothing 6 | */ 7 | int main(void) 8 | { 9 | char string[40]; 10 | 11 | printf(" $ "); 12 | scanf("%s", string); 13 | printf(" %s\n", string); 14 | 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /miniShell/afork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/afork -------------------------------------------------------------------------------- /miniShell/afork.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - fork example 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | pid_t my_pid; 12 | pid_t child_pid; 13 | 14 | child_pid = fork(); 15 | if (child_pid == -1) 16 | { 17 | perror("Error:"); 18 | return (1); 19 | } 20 | my_pid = getpid(); 21 | printf("My pid is %u\n", my_pid); 22 | if (child_pid == 0) 23 | { 24 | printf("(%u) Nooooooooo!\n", my_pid); 25 | } 26 | else 27 | { 28 | printf("(%u) %u, I am your father\n", my_pid, child_pid); 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /miniShell/av: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/av -------------------------------------------------------------------------------- /miniShell/env-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - prints the environment 5 | * @ac: The number of arguments 6 | * @av: The pointer to array of arguments 7 | * @env: The pointer to anviromental variables 8 | * Return: Always 0. 9 | */ 10 | int main(int ac, char **av, char **env) 11 | { 12 | unsigned int i; 13 | 14 | i = 0; 15 | while (env[i] != NULL) 16 | { 17 | printf("%s\n", env[i]); 18 | i++; 19 | } 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /miniShell/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int input (char * s, int length); 4 | int main () 5 | { 6 | char *buffer; 7 | size_t bufsize = 32; 8 | int caracteres = 0; 9 | buffer = (char *) malloc (bufsize * sizeof (char)); 10 | if (buffer == NULL) 11 | { 12 | exit (1); 13 | } 14 | printf ("$ "); 15 | getline (&buffer, &bufsize, stdin); 16 | printf("%d caracteres fueron leídos. \n", caracteres); 17 | printf("%s", buffer); 18 | free(buffer); 19 | return (0); 20 | } 21 | -------------------------------------------------------------------------------- /miniShell/exec: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/exec -------------------------------------------------------------------------------- /miniShell/execute: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/execute -------------------------------------------------------------------------------- /miniShell/fork: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/fork -------------------------------------------------------------------------------- /miniShell/full: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/full -------------------------------------------------------------------------------- /miniShell/functional: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/functional -------------------------------------------------------------------------------- /miniShell/getenv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/getenv -------------------------------------------------------------------------------- /miniShell/getenv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main () { 5 | printf("PATH : %s\n", getenv("PATH")); 6 | printf("HOME : %s\n", getenv("HOME")); 7 | printf("ROOT : %s\n", getenv("ROOT")); 8 | 9 | return(0); 10 | } 11 | -------------------------------------------------------------------------------- /miniShell/getline2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/getline2 -------------------------------------------------------------------------------- /miniShell/ls.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int ac,char **av[]) 7 | { 8 | DIR *dp; 9 | struct dirent *dentry; 10 | 11 | if(! (dp=opendir(argv[1])) ) { 12 | printf("opendir error\n"); 13 | exit(2); 14 | } 15 | 16 | while(1) { 17 | dentry=readdir(dp); 18 | if(!dentry) 19 | break; 20 | 21 | printf("%s\n", dentry->d_name); 22 | } 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /miniShell/mypid: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/mypid -------------------------------------------------------------------------------- /miniShell/pid.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - PID 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | pid_t process_id, p_process_id; 12 | 13 | process_id = getpid(); 14 | p_process_id = getppid(); 15 | printf("Process id: %d\n", process_id); 16 | printf("Parent Process id: %d\n", p_process_id); 17 | /* echo $$ print ppid */ 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /miniShell/printenv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/printenv -------------------------------------------------------------------------------- /miniShell/read_getline: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/read_getline -------------------------------------------------------------------------------- /miniShell/shell: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/shell -------------------------------------------------------------------------------- /miniShell/shell.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * main - execve example 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | char *argv[] = {"/bin/ls", "-l", ".", NULL}; 12 | 13 | if (execve(argv[0], argv, NULL) == -1) 14 | { 15 | perror("Error:"); 16 | } 17 | 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /miniShell/stat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/stat -------------------------------------------------------------------------------- /miniShell/strtok: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/strtok -------------------------------------------------------------------------------- /miniShell/wait: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mecomonteshbtn/C-low_level_programming/850c33d18064e0015a51c76ff5797463f45c3ccf/miniShell/wait --------------------------------------------------------------------------------