├── 0x00-hello_world ├── 1-compiler ├── 2-assembler ├── 3-name ├── 0-preprocessor ├── 100-intel ├── main.c ├── a.out ├── cisfun ├── main.o ├── 4-puts.c ├── 5-printf.c ├── main.s ├── 6-size.c ├── README.md └── c ├── 0x0C-preprocessor ├── 1-pi.h ├── 4-sum.h ├── 0-object_like_macro.h ├── 3-function_like_macro.h ├── 2-main.c ├── 4-main.c ├── 0-main.c ├── 1-main.c ├── 3-main.c └── README.md ├── 0x08-static_libraries ├── create_static_lib.sh ├── 6-abs.o ├── quote ├── 3-puts.o ├── 0-isupper.o ├── 0-memset.o ├── 0-strcat.o ├── 1-isdigit.o ├── 1-memcpy.o ├── 1-strncat.o ├── 100-atoi.o ├── 2-strchr.o ├── 2-strlen.o ├── 2-strncpy.o ├── 3-islower.o ├── 3-strcmp.o ├── 3-strspn.o ├── 4-isalpha.o ├── 4-strpbrk.o ├── 5-strstr.o ├── 9-strcpy.o ├── _putchar.o ├── libholberton.a ├── main.c ├── 0-isupper.c ├── 100-atoi.c ├── 1-isdigit.c ├── 0-strcat.c ├── 9-strcpy.c ├── 0-memset.c ├── _putchar.c ├── 1-strncat.c ├── 2-strlen.c ├── 3-islower.c ├── 6-abs.c ├── 3-puts.c ├── 1-memcpy.c ├── 2-strchr.c ├── 4-isalpha.c ├── 3-strcmp.c ├── 2-strncpy.c ├── 4-strpbrk.c ├── 3-strspn.c ├── 5-strstr.c ├── holberton.h ├── README.md └── liball.a ├── 0x01-variables_if_else_while ├── .emacs ├── a.out ├── 1-last_digit ├── 9-print_comb ├── 4-print_alphabt ├── 5-print_numbers ├── 6-print_numberz ├── 8-print_base16 ├── 2-print_alphabet ├── 3-print_alphabets ├── 7-print_tebahpla ├── 0-positive_or_negative ├── 5-print_numbers.c ├── 6-print_numberz.c ├── 7-print_tebahpla.c ├── 2-print_alphabet.c ├── 10-print_comb2.c ├── 4-print_alphabt.c ├── 9-print_comb.c~ ├── 8-print_base16.c ├── 3-print_alphabets.c ├── 9-print_comb.c ├── 100-print_comb3.c ├── 101-print_comb4.c ├── 0-positive_or_negative.c ├── 1-last_digit.c └── README.md ├── 0x02-functions_nested_loops ├── 0-holberton ├── 1-alphabet.c ├── _putchar.c ├── 3-islower.c ├── 6-abs.c ├── 2-print_alphabet_x10.c ├── 4-isalpha.c ├── 0-holberton.c ├── 5-sign.c ├── 7-print_last_digit.c ├── holberton.h ├── 8-24_hours.c └── README.md ├── 0x0B-more_malloc_free ├── holberton.h~ ├── README.md ├── holberton.h ├── 1-main.c ├── 0-malloc_checked.c ├── 3-array_range.c ├── 0-main.c ├── 1-string_nconcat.c ├── 2-calloc.c ├── 3-main.c └── 2-main.c ├── 0x03-more_functions_nested_loops ├── 0-issuper ├── 3-print_numbers.c ├── 0-isupper.c ├── 1-isdigit.c ├── 2-mul.c ├── 4-print_most_numbers.c ├── 6-print_line.c ├── 5-more_numbers.c ├── 8-print_square.c ├── 7-print_diagonal.c ├── 9-fizz_buzz.c ├── 100-prime_factor.c ├── 10-print_triangle.c └── README.md ├── 0x05-pointers_arrays_strings ├── holberton.h ├── 3-main.c ├── 0-main.c ├── 0-strcat.c ├── 3-strcmp.c ├── 1-strncat.c ├── 1-main.c ├── README.md ├── 2-strncpy.c └── 2-main.c ├── 0x06-pointers_arrays_strings ├── holberton.h ├── 2-main.c ├── 5-main.c ├── 3-main.c ├── 4-main.c ├── 1-memcpy.c ├── 0-memset.c ├── 2-strchr.c ├── 4-strpbrk.c ├── 3-strspn.c ├── 5-strstr.c ├── 1-main.c ├── 0-main.c └── README.md ├── 0x0A-malloc_free ├── holberton.h ├── 4-free_grid.c ├── 0-create_array.c ├── README.md ├── 1-strdup.c ├── 2-str_concat.c └── 0-main.c ├── 0x07-recursion ├── 0-main.c ├── 1-main.c ├── 2-main.c ├── 2-strlen_recursion.c ├── 1-print_rev_recursion.c ├── 3-factorial.c ├── 0-puts_recursion.c ├── holberton.h ├── 3-main.c ├── 4-pow_recursion.c ├── 7-main.c ├── 5-main.c ├── 4-main.c ├── 6-is_prime_number.c ├── 6-main.c ├── 5-sqrt_recursion.c ├── 7-is_palindrome.c └── README.md ├── 0x0F-variadic_functions ├── 2-main.c ├── 1-main.c ├── variadic_functions.h ├── README.md ├── 0-main.c ├── 0-sum_them_all.c ├── 1-print_numbers.c └── 2-print_strings.c ├── 0x04-pointers_arrays_strings ├── 6-main.c ├── 7-main.c ├── holberton.h ├── 0-reset_to_98.c ├── 3-main.c ├── 4-main.c ├── 2-strlen.c ├── 5-main.c ├── 0-main.c ├── 2-main.c ├── 3-puts.c ├── 1-main.c ├── 1-swap.c ├── 4-print_rev.c ├── 6-puts2.c ├── 5-rev_string.c ├── 7-puts_half.c └── README.md ├── 0x0E-function_pointers ├── README.md ├── 0-print_name.c ├── function_pointers.h ├── 1-array_iterator.c ├── 2-int_index.c ├── 1-main.c ├── 0-main.c └── 2-main.c ├── 0x09-argc_argv ├── README.md ├── 1-args.c ├── 2-args.c ├── 0-whatsmyname.c ├── 3-mul.c └── 4-add.c └── 0x0D-structures_typedef ├── 1-main.c ├── README.md ├── 0-main.c ├── 1-init_dog.c └── dog.h /0x00-hello_world/1-compiler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/2-assembler: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c $CFILE 3 | -------------------------------------------------------------------------------- /0x00-hello_world/3-name: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc $CFILE -o cisfun 3 | -------------------------------------------------------------------------------- /0x00-hello_world/0-preprocessor: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -E $CFILE -o c 3 | -------------------------------------------------------------------------------- /0x00-hello_world/100-intel: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -S -masm=intel $CFILE 3 | -------------------------------------------------------------------------------- /0x0C-preprocessor/1-pi.h: -------------------------------------------------------------------------------- 1 | #ifndef PI 2 | #define PI 3.14159265359 3 | #endif 4 | -------------------------------------------------------------------------------- /0x0C-preprocessor/4-sum.h: -------------------------------------------------------------------------------- 1 | #ifndef SUM 2 | #define SUM(x,y) (x + y) 3 | #endif 4 | -------------------------------------------------------------------------------- /0x0C-preprocessor/0-object_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef SIZE 2 | #define SIZE 1024 3 | #endif 4 | -------------------------------------------------------------------------------- /0x00-hello_world/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main(void) 4 | { 5 | return (0); 6 | } 7 | -------------------------------------------------------------------------------- /0x08-static_libraries/create_static_lib.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | gcc -c *.c 3 | ar -rc liball.a *.o 4 | ranlib liball.a 5 | -------------------------------------------------------------------------------- /0x0C-preprocessor/3-function_like_macro.h: -------------------------------------------------------------------------------- 1 | #ifndef ABS 2 | #define ABS(x) ((x) < 0 ? (x * -1) : (x)) 3 | #endif 4 | -------------------------------------------------------------------------------- /0x00-hello_world/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x00-hello_world/a.out -------------------------------------------------------------------------------- /0x00-hello_world/cisfun: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x00-hello_world/cisfun -------------------------------------------------------------------------------- /0x00-hello_world/main.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x00-hello_world/main.o -------------------------------------------------------------------------------- /0x08-static_libraries/6-abs.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/6-abs.o -------------------------------------------------------------------------------- /0x08-static_libraries/quote: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/quote -------------------------------------------------------------------------------- /0x08-static_libraries/3-puts.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/3-puts.o -------------------------------------------------------------------------------- /0x01-variables_if_else_while/.emacs: -------------------------------------------------------------------------------- 1 | (setq c-default-style "bsd" 2 | c-basic-offset 8 3 | tab-width 8 4 | indent-tabs-mode t) 5 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/a.out: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/a.out -------------------------------------------------------------------------------- /0x08-static_libraries/0-isupper.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/0-isupper.o -------------------------------------------------------------------------------- /0x08-static_libraries/0-memset.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/0-memset.o -------------------------------------------------------------------------------- /0x08-static_libraries/0-strcat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/0-strcat.o -------------------------------------------------------------------------------- /0x08-static_libraries/1-isdigit.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/1-isdigit.o -------------------------------------------------------------------------------- /0x08-static_libraries/1-memcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/1-memcpy.o -------------------------------------------------------------------------------- /0x08-static_libraries/1-strncat.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/1-strncat.o -------------------------------------------------------------------------------- /0x08-static_libraries/100-atoi.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/100-atoi.o -------------------------------------------------------------------------------- /0x08-static_libraries/2-strchr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/2-strchr.o -------------------------------------------------------------------------------- /0x08-static_libraries/2-strlen.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/2-strlen.o -------------------------------------------------------------------------------- /0x08-static_libraries/2-strncpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/2-strncpy.o -------------------------------------------------------------------------------- /0x08-static_libraries/3-islower.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/3-islower.o -------------------------------------------------------------------------------- /0x08-static_libraries/3-strcmp.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/3-strcmp.o -------------------------------------------------------------------------------- /0x08-static_libraries/3-strspn.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/3-strspn.o -------------------------------------------------------------------------------- /0x08-static_libraries/4-isalpha.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/4-isalpha.o -------------------------------------------------------------------------------- /0x08-static_libraries/4-strpbrk.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/4-strpbrk.o -------------------------------------------------------------------------------- /0x08-static_libraries/5-strstr.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/5-strstr.o -------------------------------------------------------------------------------- /0x08-static_libraries/9-strcpy.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/9-strcpy.o -------------------------------------------------------------------------------- /0x08-static_libraries/_putchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/_putchar.o -------------------------------------------------------------------------------- /0x08-static_libraries/libholberton.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x08-static_libraries/libholberton.a -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x02-functions_nested_loops/0-holberton -------------------------------------------------------------------------------- /0x0B-more_malloc_free/holberton.h~: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | 4 | void *malloc_checked(unsigned int b); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/1-last_digit -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/9-print_comb -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/4-print_alphabt -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/5-print_numbers -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/6-print_numberz -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/8-print_base16 -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/0-issuper: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x03-more_functions_nested_loops/0-issuper -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/2-print_alphabet -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/3-print_alphabets -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/7-print_tebahpla -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_INCLUDED 2 | #define HOLBERTON_H_INCLUDED 3 | 4 | char *_strcat(char *dest, char *src); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kalson/holbertonschool-low_level_programming/HEAD/0x01-variables_if_else_while/0-positive_or_negative -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_INCLUDED 2 | #define HOLBERTON_H_INCLUDED 3 | 4 | char *_memset(char *s, char b, unsigned int n); 5 | 6 | #endif 7 | -------------------------------------------------------------------------------- /0x0A-malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | 4 | int _putchar(char c); 5 | char *create_array(unsigned int size, char c); 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /0x08-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 | -------------------------------------------------------------------------------- /0x0C-preprocessor/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - prints the file name with a new line 4 | * Return: 0; 5 | */ 6 | int main (void) 7 | { 8 | printf("%s\n", __FILE__); 9 | return (0); 10 | } 11 | -------------------------------------------------------------------------------- /0x08-static_libraries/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _isupper - writes the character c to stdout 5 | * @c: The character to print 6 | * Return: 0 7 | */ 8 | int _isupper(int c) 9 | { 10 | return 0; 11 | } -------------------------------------------------------------------------------- /0x08-static_libraries/100-atoi.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _atoi - function that convert a string to an integer 5 | * @s: The character to print 6 | * Return: 0 7 | */ 8 | int _atoi(char *s) 9 | { 10 | return (0); 11 | } 12 | -------------------------------------------------------------------------------- /0x07-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 | -------------------------------------------------------------------------------- /0x07-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-static_libraries/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _isdigit - function that checks for uppercase character. 4 | * @c: the int for the paramaters of my function 5 | * Return: 0 6 | */ 7 | int _isdigit(int c) 8 | { 9 | return (0); 10 | } 11 | -------------------------------------------------------------------------------- /0x0F-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 | -------------------------------------------------------------------------------- /0x0F-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 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x04-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 = "0123456789"; 13 | puts_half(str); 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-static_libraries/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _strcat - function that concatenates two strings. 4 | * @src: parameter to a src 5 | * @dest: parameter to append 6 | * Return: Always 0. 7 | */ 8 | char *_strcat(char *dest, char *src) 9 | { 10 | return (dest); 11 | } 12 | -------------------------------------------------------------------------------- /0x08-static_libraries/9-strcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _strcpy - function that copies the string pointed to by src 4 | * @dest: dest parameter 5 | * @src: src paramter 6 | * Return: dest char 7 | */ 8 | char *_strcpy(char *dest, char *src) 9 | { 10 | return (dest); 11 | } 12 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_INCLUDED 2 | #define HOLBERTON_H_INCLUDED 3 | 4 | int _putchar(char c); 5 | void reset_to_98(int *n); 6 | void swap_int(int *a, int *b); 7 | int _strlen(char *s); 8 | void _puts(char *str); 9 | void print_rev(char *s); 10 | 11 | #endif 12 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/1-alphabet.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_alphabet - function to print abc 4 | * 5 | * Return: 0 6 | */ 7 | void print_alphabet(void) 8 | { 9 | char c; 10 | 11 | for (c = 'a'; c <= 'z'; c++) 12 | { 13 | _putchar(c); 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/0-reset_to_98.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * reset_to_98 - check the code for Holberton School students. 4 | * @n: declaration of n and paramters for the function reset_to_98 5 | * Return: Always 0. 6 | */ 7 | void reset_to_98(int *n) 8 | { 9 | *n = 98; 10 | } 11 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/README.md: -------------------------------------------------------------------------------- 1 | # C - more malloc, free 2 | * 0 - Write a function that allocates memory using malloc. 3 | * 1 - Write a function that concatenates two strings. 4 | * 2 - Write a function that allocates memory for an array, using malloc. 5 | * 3 - Write a function that creates an array of integers. 6 | -------------------------------------------------------------------------------- /0x0F-variadic_functions/variadic_functions.h: -------------------------------------------------------------------------------- 1 | #ifndef V_FUNCTION_H_FILE 2 | #define V_FUNCTION_H_FILE 3 | 4 | int sum_them_all(const unsigned int n, ...); 5 | void print_numbers(const char *separator, const unsigned int n, ...); 6 | void print_strings(const char *separator, const unsigned int n, ...); 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | 4 | void *malloc_checked(unsigned int b); 5 | char *string_nconcat(char *s1, char *s2, unsigned int n); 6 | void *_calloc(unsigned int nmemb, unsigned int size); 7 | int *array_range(int min, int max); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x0E-function_pointers/README.md: -------------------------------------------------------------------------------- 1 | # C - Function pointers 2 | * 0 - Write a function that prints a name. 3 | * 1 - Write a function that executes a function given as a parameter on each element of an array. 4 | * 2 - Write a function that searches for an integer. 5 | * 3 - Write a program that performs simple operations. 6 | -------------------------------------------------------------------------------- /0x0F-variadic_functions/README.md: -------------------------------------------------------------------------------- 1 | # C - Variadic functions 2 | * 0 - Write a function that returns the sum of all its parameters. 3 | * 1 - Write a function that prints numbers, followed by a new line. 4 | * 2 - Write a function that prints strings, followed by a new line. 5 | * 3 - Write a function that prints anything. 6 | -------------------------------------------------------------------------------- /0x08-static_libraries/0-memset.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * _memset - function that fills memory with a constant byte. 5 | * @b: b character 6 | * @s: s character 7 | * @n: int n 8 | * Return: On success 1. 9 | */ 10 | char *_memset(char *s, char b, unsigned int n) 11 | { 12 | return (s); 13 | } 14 | -------------------------------------------------------------------------------- /0x07-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 | -------------------------------------------------------------------------------- /0x0E-function_pointers/0-print_name.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | /** 3 | * print_name - Write a function that prints a name 4 | * @name: name of the person 5 | * @f: paramter for the function pointer 6 | * Return: Nothing. 7 | */ 8 | void print_name(char *name, void (*f)(char *)) 9 | { 10 | (*f)(name); 11 | } 12 | -------------------------------------------------------------------------------- /0x0E-function_pointers/function_pointers.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | #include 4 | 5 | void print_name(char *name, void (*f)(char *)); 6 | void array_iterator(int *array, size_t size, void (*action)(int)); 7 | int int_index(int *array, int size, int (*cmp)(int)); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /0x0C-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 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/3-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_numbers - function that checks for uppercase character. 4 | * Return: 0 5 | */ 6 | void print_numbers(void) 7 | { 8 | char c = '0'; 9 | 10 | while (c <= '9') 11 | { 12 | _putchar(c); 13 | c++; 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x08-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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /0x08-static_libraries/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _strncat - function that concatenates two strings 4 | * @dest: parmater for dest to append to 5 | * @src: parameter for src 6 | * @n: parameter for n 7 | * Return: Always 0. 8 | */ 9 | char *_strncat(char *dest, char *src, int n) 10 | { 11 | return (dest); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/0-isupper.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _isupper - function that checks for uppercase character. 4 | * @c: the int for the paramaters of my function 5 | * Return: 0 6 | */ 7 | int _isupper(int c) 8 | { 9 | if (c >= 65 && c <= 90) 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/1-isdigit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _isdigit - function that checks for uppercase character. 4 | * @c: the int for the paramaters of my function 5 | * Return: 0 6 | */ 7 | int _isdigit(int c) 8 | { 9 | if (c >= 48 && c <= 57) 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/2-mul.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * mul - function that prints the numbers, from 0 to 9, followed by a new line. 4 | * @a: the int for the paramaters of my function 5 | * @b: the int for the paramaters of my function 6 | * Return: 0 7 | */ 8 | int mul(int a, int b) 9 | { 10 | return (a * b); 11 | } 12 | -------------------------------------------------------------------------------- /0x04-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 | } 16 | -------------------------------------------------------------------------------- /0x06-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 | printf("%s\n", f); 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x08-static_libraries/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _strlen - check the code for Holberton School students. 4 | * @s: declaration of *s and paramters for the function _strlen 5 | * Return: Always 0. 6 | */ 7 | int _strlen(char *s) 8 | { 9 | int c; 10 | 11 | for (c = 0; s[c] != 0; c++) 12 | { 13 | } 14 | return (c); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-static_libraries/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _islower - function to check for lowercase character 4 | * @c: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int _islower(int c) 8 | { 9 | if (c >= 'a' && c <= 'z') 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0C-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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/3-islower.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _islower - function to check for lowercase character 4 | * @c: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int _islower(int c) 8 | { 9 | if (c >= 'a' && c <= 'z') 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/2-strlen.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strlen - check the code for Holberton School students. 4 | * @s: declaration of *s and paramters for the function _strlen 5 | * Return: Always 0. 6 | */ 7 | int _strlen(char *s) 8 | { 9 | int c; 10 | 11 | for (c = 0; s[c] != 0; c++) 12 | { 13 | } 14 | return (c); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x09-argc_argv/README.md: -------------------------------------------------------------------------------- 1 | # C - argc, argv 2 | * 0 - Write a program that prints its name, followed by a new line. 3 | * 1 - Write a program that prints the number of arguments you passed to it. 4 | * 2 - Write a program that prints all arguments it receives. 5 | * 3 - Write a program that multiply two numbers. 6 | * 4 - Write a program that adds positive numbers. 7 | -------------------------------------------------------------------------------- /0x0C-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 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x00-hello_world/4-puts.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - print the string in the put function 5 | * 6 | * Description: using the main function 7 | * this program prints "Programming is like building a multilingual puzzle 8 | * Return: 0 9 | */ 10 | int main(void) 11 | { 12 | puts("\"Programming is like building a multilingual puzzle"); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /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 = "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 | -------------------------------------------------------------------------------- /0x08-static_libraries/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _abs - function that computes the absolute value of an integer 5 | * @n: is the int that will use for the argument of the function 6 | * Return: 0 7 | */ 8 | int _abs(int n) 9 | { 10 | if (n > 0 || n == 0) 11 | { 12 | return (n); 13 | } 14 | else 15 | return (n * -1); 16 | } 17 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/6-abs.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _abs - function that computes the absolute value of an integer 5 | * @c: is the int that will use for the argument of the function 6 | * Return: 0 7 | */ 8 | int _abs(int c) 9 | { 10 | if (c > 0 || c == 0) 11 | { 12 | return (c); 13 | } 14 | else 15 | return (c * -1); 16 | } 17 | -------------------------------------------------------------------------------- /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 *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-recursion/2-strlen_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strlen_recursion - function that returns the length of a string 4 | * @s: parameter for checking length of a string 5 | * Return: Always 0. 6 | */ 7 | int _strlen_recursion(char *s) 8 | { 9 | if (*s == '\0') 10 | { 11 | return (0); 12 | } 13 | s++; 14 | return (1 + _strlen_recursion(s)); 15 | } 16 | -------------------------------------------------------------------------------- /0x08-static_libraries/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _puts - function that prints a string, followed by a new line 4 | * @s: declaration of *str and paramters for the function _puts 5 | * Return: Always 0. 6 | */ 7 | void _puts(char *s) 8 | { 9 | int c; 10 | 11 | for (c = 0; s[c] != 0; c++) 12 | { 13 | _putchar(s[c]); 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x00-hello_world/5-printf.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - print the string in the put function 5 | * 6 | * Description: using the main function 7 | * this program prints "Programming is like building a multilingual puzzle 8 | * Return: 0 9 | */ 10 | int main(void) 11 | { 12 | printf("with proper grammar, but the outcome is a piece of art,\n"); 13 | return (0); 14 | } 15 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/2-print_alphabet_x10.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_alphabet_x10 - function to print abc 10 times 4 | * 5 | * Return: 0 6 | */ 7 | void print_alphabet_x10(void) 8 | { 9 | char c, i; 10 | 11 | for (i = 0; i <= 9; i++) 12 | { 13 | for (c = 'a'; c <= 'z'; c++) 14 | { 15 | _putchar(c); 16 | } 17 | _putchar('\n'); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /0x06-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 | } -------------------------------------------------------------------------------- /0x08-static_libraries/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _memcpy - copies n bytes form the memory area src 4 | * to memory area dest 5 | * @src: source code to copy 6 | * @dest: paramater for destination to copy to 7 | * @n: how many bytes to copy 8 | * Return: dest; 9 | */ 10 | char *_memcpy(char *dest, char *src, unsigned int n) 11 | { 12 | return (dest); 13 | } 14 | -------------------------------------------------------------------------------- /0x08-static_libraries/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * _strchr - returns a pointer to the first occurence of the 4 | * character c in the string s 5 | * @c: parameter for c to return 6 | * @s: string to search character 7 | * Return: pointer to first occurence of character c or null if not found 8 | */ 9 | char *_strchr(char *s, char c) 10 | { 11 | return (s); 12 | } 13 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/3-puts.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _puts - function that prints a string, followed by a new line 4 | * @str: declaration of *str and paramters for the function _puts 5 | * Return: Always 0. 6 | */ 7 | void _puts(char *str) 8 | { 9 | int c; 10 | 11 | for (c = 0; str[c] != 0; c++) 12 | { 13 | _putchar(str[c]); 14 | } 15 | _putchar('\n'); 16 | } 17 | -------------------------------------------------------------------------------- /0x07-recursion/1-print_rev_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _print_rev_recursion - function that prints a string, in reverse 4 | * @s: points to elements of the char array or string 5 | * Return: Always 0. 6 | */ 7 | void _print_rev_recursion(char *s) 8 | { 9 | if (*s == '\0') 10 | { 11 | return; 12 | } 13 | 14 | _print_rev_recursion(s + 1); 15 | _putchar(*s); 16 | } 17 | -------------------------------------------------------------------------------- /0x08-static_libraries/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _isalpha - function to check if c is a letter, lowercase or uppercase 4 | * @c: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int _isalpha(int c) 8 | { 9 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x0A-malloc_free/4-free_grid.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * free_grid - function that concatenates two strings 5 | * @grid: parmater for grid 6 | * @height: parameter for height 7 | * Return: Always 0. 8 | */ 9 | void free_grid(int **grid, int height) 10 | { 11 | int i; 12 | 13 | for (i = 0; i < height; i++) 14 | free(grid[i]); 15 | free(grid); 16 | } 17 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/4-isalpha.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _isalpha - function to check if c is a letter, lowercase or uppercase 4 | * @c: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int _isalpha(int c) 8 | { 9 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 10 | { 11 | return (1); 12 | } 13 | else 14 | return (0); 15 | } 16 | -------------------------------------------------------------------------------- /0x04-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 | -------------------------------------------------------------------------------- /0x0D-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 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/0-holberton.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * main - function to print 5 | * 6 | * Return: 0 7 | */ 8 | int main(void) 9 | { 10 | char holberton[9] = {'H', 'o', 'l', 'b', 'e', 'r', 't', 'o', 'n'}; 11 | unsigned int c; 12 | 13 | for (c = 0; c < sizeof(holberton); c++) 14 | { 15 | _putchar(holberton[c]); 16 | } 17 | _putchar('\n'); 18 | return (0); 19 | } 20 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/4-print_most_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_most_numbers - check the code for Holberton School students. 4 | * Return: Always 0. 5 | */ 6 | void print_most_numbers(void) 7 | { 8 | char c = '0'; 9 | 10 | while (c <= '9') 11 | { 12 | if (c != '2' && c != '4') 13 | { 14 | _putchar(c); 15 | } 16 | c++; 17 | } 18 | _putchar('\n'); 19 | } 20 | -------------------------------------------------------------------------------- /0x0B-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-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 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/1-swap.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * swap_int - check the code for Holberton School students. 4 | * @a: declaration of a and paramters for the function swap_int 5 | * @b: declaration of b and paramters for the function swap_int 6 | * Return: Always 0. 7 | */ 8 | void swap_int(int *a, int *b) 9 | { 10 | int c; 11 | 12 | c = *a; 13 | *a = *b; 14 | *b = c; 15 | } 16 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/0-malloc_checked.c: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | #include 4 | 5 | /** 6 | * malloc_checked - alloates memory using malloc 7 | * @b:how much bits to use 8 | * Return: pointer to allocated memory 9 | */ 10 | 11 | void *malloc_checked(unsigned int b) 12 | { 13 | void *ptr; 14 | 15 | ptr = malloc(b); 16 | if (ptr == NULL) 17 | exit(98); 18 | return (ptr); 19 | } 20 | -------------------------------------------------------------------------------- /0x0D-structures_typedef/README.md: -------------------------------------------------------------------------------- 1 | # C - Structures, typedef 2 | * 0 - Define a new type struct dog with the following elements: 3 | * 1 - Write a function that initialize a variable of type struct dog 4 | * 2 - Write a function that prints a struct dog 5 | * 3 - Define a new type dog_t as a new name for the type struct dog. 6 | * 4 - Write a function that creates a new dog. 7 | * 5 - Write a function that frees dogs. 8 | -------------------------------------------------------------------------------- /0x0F-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 | -------------------------------------------------------------------------------- /0x07-recursion/3-factorial.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * factorial - function that returns the factorial of a given number 4 | * @n: number to do factorialization on 5 | * Return: Always 0. 6 | */ 7 | int factorial(int n) 8 | { 9 | if (n < 0) 10 | { 11 | return (-1); 12 | } 13 | else if (n <= 1) 14 | { 15 | return (1); 16 | } 17 | else 18 | { 19 | return (n * factorial(n - 1)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /0x09-argc_argv/1-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints its name, followed by a new line 4 | * @argc: argument that counts argument input 5 | * @argv: argument that stores the strings in an array of char* (strings) 6 | * Return: 0 7 | */ 8 | int main(int argc, char *argv[]) 9 | { 10 | if (argc) 11 | { 12 | printf("%d\n", argc - 1); 13 | (void)argv; 14 | } 15 | return (0); 16 | } 17 | -------------------------------------------------------------------------------- /0x05-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 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/5-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | int i; 12 | for (i = 0; i < 10; i++) 13 | { 14 | printf("%i", i); 15 | } 16 | printf("\n"); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/6-print_numberz.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | for (c = '0'; c <= '9'; c++) 13 | { 14 | putchar(c); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/7-print_tebahpla.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | for (c = 'z'; c >= 'a'; c--) 13 | { 14 | putchar(c); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/2-print_alphabet.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char ch; 12 | for (ch = 'a' ; ch <= 'z' ; ch++) 13 | { 14 | putchar(ch); 15 | } 16 | putchar('\n'); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x07-recursion/0-puts_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _puts_recursion - function that prints a string, followed by a new line 4 | * @s: points to char array or string 5 | * Return: Always 0. 6 | */ 7 | void _puts_recursion(char *s) 8 | { 9 | unsigned int index = 0; 10 | 11 | if (s[index] == '\0') 12 | { 13 | _putchar('\n'); 14 | return; 15 | } 16 | _putchar(s[index]); 17 | _puts_recursion(s + 1); 18 | } 19 | -------------------------------------------------------------------------------- /0x09-argc_argv/2-args.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints its name, followed by a new line 4 | * @argc: argument that counts argument input 5 | * @argv: argument that stores the strings in an array of char* (strings) 6 | * Return: 0 7 | */ 8 | int main(int argc, char *argv[]) 9 | { 10 | int i; 11 | 12 | for (i = 0; i < argc; i++) 13 | { 14 | printf("%s\n", argv[i]); 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x0D-structures_typedef/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "dog.h" 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | struct dog my_dog; 12 | 13 | my_dog.name = "Django"; 14 | my_dog.age = 3.5; 15 | my_dog.owner = "Jay"; 16 | printf("My name is %s, and I am %.1f :) - Woof!\n", my_dog.name, my_dog.age); 17 | return (0); 18 | } 19 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/10-print_comb2.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints numbers from 0 to 99. 4 | * Return: 0 5 | */ 6 | 7 | int main(void) 8 | { 9 | int c = 0; 10 | 11 | while (c <= 99) 12 | { 13 | putchar(c / 10 + '0'); 14 | putchar(c % 10 + '0'); 15 | if (c != 99) 16 | { 17 | putchar(','); 18 | putchar(' '); 19 | } 20 | c++; 21 | } 22 | putchar('\n'); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/4-print_rev.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_rev - func that prints a string, in reverse, followed by a new line 4 | * @s: declaration of s and paramters for the function 5 | * Return: Always 0. 6 | */ 7 | void print_rev(char *s) 8 | { 9 | int c; 10 | 11 | for (c = 0; s[c] != 0; c++) 12 | { 13 | } 14 | for (c = c - 1; c >= 0; c--) 15 | _putchar(s[c]); 16 | _putchar('\n'); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /0x07-recursion/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | 4 | int _putchar(char c); 5 | void _puts_recursion(char *s); 6 | void _print_rev_recursion(char *s); 7 | int _strlen_recursion(char *s); 8 | int factorial(int n); 9 | int _pow_recursion(int x, int y); 10 | int _sqrt_recursion(int n); 11 | int helper(int n, int i); 12 | int is_prime_number(int n); 13 | int helper_prime(int n, int i, int limit); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /0x09-argc_argv/0-whatsmyname.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints its name, followed by a new line 4 | * @argc: argument that counts argument input 5 | * @argv: argument that stores the strings in an array of char* (strings) 6 | * Return: 0 7 | */ 8 | int main(int argc, char *argv[]) 9 | { 10 | int i; 11 | 12 | for (i = 0; i < argc; i++) 13 | { 14 | printf("%s\n", argv[i]); 15 | } 16 | return (0); 17 | } 18 | -------------------------------------------------------------------------------- /0x07-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 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/6-print_line.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_line - function that checks for uppercase character. 4 | * @n: is the integer for the paramaters of my function 5 | * Return: 0 6 | */ 7 | void print_line(int n) 8 | { 9 | int a = 0; 10 | 11 | if (n > 0) 12 | { 13 | while (a <= n) 14 | { 15 | _putchar('_'); 16 | a++; 17 | } 18 | _putchar('\n'); 19 | } 20 | else 21 | _putchar('\n'); 22 | } 23 | -------------------------------------------------------------------------------- /0x07-recursion/4-pow_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _pow_recursion - func that returns the value of x raised to the power of y 5 | * @x: paramater for the number 6 | * @y: number to be raised to 7 | * Return: Always 0. 8 | */ 9 | int _pow_recursion(int x, int y) 10 | { 11 | if (y < 0) 12 | { 13 | return (-1); 14 | } 15 | else if (y == 0) 16 | return (1); 17 | return (x * _pow_recursion(x, y - 1)); 18 | } 19 | -------------------------------------------------------------------------------- /0x0E-function_pointers/1-array_iterator.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | /** 3 | * array_iterator - func that executes a func given as a parameter 4 | * @array: parameter for array 5 | * @size: parameter for size 6 | * @action: paramter for action 7 | * Return: Nothing. 8 | */ 9 | void array_iterator(int *array, size_t size, void (*action)(int)) 10 | { 11 | size_t i; 12 | 13 | for (i = 0; i < size; i++) 14 | { 15 | action(array[i]); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/5-sign.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_sign - function to check for a sign of a number 4 | * @n: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int print_sign(int n) 8 | { 9 | if (n > 0) 10 | { 11 | _putchar('+'); 12 | return (1); 13 | } 14 | else if (n < 0) 15 | { 16 | _putchar('-'); 17 | return (-1); 18 | } 19 | else 20 | { 21 | _putchar('0'); 22 | return (0); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/6-puts2.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * puts2 - func that prints 1 char/2 of a string, followed by a new line. 4 | * @str: declaration of str and paramters for the function puts2 5 | * Return: Always 0. 6 | */ 7 | void puts2(char *str) 8 | { 9 | int c; 10 | char l; 11 | 12 | for (c = 0; str[c] != 0; c++) 13 | { 14 | if (c % 2 == 0) 15 | { 16 | l = str[c]; 17 | _putchar(l); 18 | } 19 | } 20 | _putchar('\n'); 21 | } 22 | -------------------------------------------------------------------------------- /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 | 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 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/0-strcat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcat - function that concatenates two strings. 4 | * @src: parameter to a src 5 | * @dest: parameter to append 6 | * Return: Always 0. 7 | */ 8 | char *_strcat(char *dest, char *src) 9 | { 10 | int a = 0; 11 | int b = 0; 12 | 13 | while (dest[a] != '\0') 14 | a++; 15 | while (src[b] != '\0') 16 | { 17 | dest[a] = src[b]; 18 | b++; 19 | a++; 20 | } 21 | return (dest); 22 | } 23 | -------------------------------------------------------------------------------- /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.3) 4.8.4" 21 | .section .note.GNU-stack,"",@progbits 22 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/5-more_numbers.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * more_numbers - function that checks for uppercase character 4 | * Return: 0 5 | */ 6 | void more_numbers(void) 7 | { 8 | 9 | int a = 0; 10 | int b = 0; 11 | 12 | while (b <= 9) 13 | { 14 | while (a <= 14) 15 | { 16 | if (a > 9) 17 | _putchar(a / 10 + '0'); 18 | _putchar(a % 10 + '0'); 19 | a++; 20 | 21 | } 22 | _putchar('\n'); 23 | b++; 24 | a = 0; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /0x08-static_libraries/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcmp - function that compares two strings 4 | * @s2: paramater for string 2 5 | * @s1: paramater for string 1 6 | * Return: Always 0. 7 | */ 8 | int _strcmp(char *s1, char *s2) 9 | { 10 | int a = 0; 11 | 12 | while (s1[a] != '\0') 13 | { 14 | if (s1[a] < s2[a]) 15 | return (s1[a] - s2[a]); 16 | if (s1[a] > s2[a]) 17 | return (s1[a] - s2[a]); 18 | a++; 19 | } 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/4-print_alphabt.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char ch; 12 | for (ch = 'a' ; ch <= 'z' ; ch++) 13 | { 14 | if (ch != 'e' && ch != 'q') 15 | { 16 | putchar(ch); 17 | } 18 | } 19 | putchar('\n'); 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c~: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - printing numbers from 0-9 with commas and space between them 4 | * Description: using the main function 5 | * this program prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" 6 | * Return: 0 7 | */ 8 | int main(void) 9 | { 10 | char c; 11 | for (c = '0'; c <= '9'; c++) 12 | { 13 | putchar(c); 14 | if (c != '9') 15 | { 16 | putchar(','); 17 | putchar(' '); 18 | } 19 | } 20 | putchar('\n'); 21 | return 0; 22 | } 23 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/3-strcmp.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strcmp - function that compares two strings 4 | * @s2: paramater for string 2 5 | * @s1: paramater for string 1 6 | * Return: Always 0. 7 | */ 8 | int _strcmp(char *s1, char *s2) 9 | { 10 | int a = 0; 11 | 12 | while (s1[a] != '\0') 13 | { 14 | if (s1[a] < s2[a]) 15 | return (s1[a] - s2[a]); 16 | if (s1[a] > s2[a]) 17 | return (s1[a] - s2[a]); 18 | a++; 19 | } 20 | return (0); 21 | } 22 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/8-print_base16.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char c; 12 | for (c = '0'; c <= '9'; c++) 13 | { 14 | putchar(c); 15 | } 16 | for (c = 'a'; c <= 'f'; c++) 17 | { 18 | putchar(c); 19 | } 20 | putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/7-print_last_digit.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_last_digit - function that computes the absolute value of an integer 4 | * @c: is the int that will use for the argument of the function 5 | * Return: 0 6 | */ 7 | int print_last_digit(int c) 8 | { 9 | if (c > 0 || c == 0) 10 | { 11 | _putchar (c % 10 + '0'); 12 | return (c % 10); 13 | } 14 | else 15 | { 16 | c = c * -1; 17 | _putchar (c % 10 + '0'); 18 | return (c % 10); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-memcpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _memcpy - copies n bytes form the memory area src 4 | * to memory area dest 5 | * @src: source code to copy 6 | * @dest: paramater for destination to copy to 7 | * @n: how many bytes to copy 8 | * Return: dest; 9 | */ 10 | 11 | char *_memcpy(char *dest, char *src, unsigned int n) 12 | { 13 | unsigned int i; 14 | 15 | for (i = 0; i < n; i++) 16 | { 17 | dest[i] = src[i]; 18 | } 19 | return (dest); 20 | } 21 | -------------------------------------------------------------------------------- /0x07-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 | -------------------------------------------------------------------------------- /0x0D-structures_typedef/1-init_dog.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "dog.h" 4 | 5 | /** 6 | * init_dog - dog structure 7 | * @d: the struct 8 | * @name: dog's name 9 | * @age: dog's age 10 | * @owner: the owner of dog 11 | */ 12 | 13 | 14 | void init_dog(struct dog *d, char *name, float age, char *owner) 15 | { 16 | if (d == NULL) 17 | ; 18 | else 19 | { 20 | d->name = name; 21 | d->age = age; 22 | d->owner = owner; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-memset.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _memset - check the code for Holberton School students. 4 | * @s: parameter for the array 5 | * @b: parameter for the values in the array 6 | * @n: parameter for the number of times to print the new values 7 | * Return: Always 0. 8 | */ 9 | char *_memset(char *s, char b, unsigned int n) 10 | { 11 | unsigned int a = 0; 12 | 13 | while (a < n) 14 | { 15 | s[a] = b; 16 | a++; 17 | } 18 | 19 | return (s); 20 | } 21 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/3-print_alphabets.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - print if the number is postive, zero, or negative 4 | * 5 | * Description: using the main function 6 | * this program prints "Programming is positive, zero, or negative 7 | * Return: 0 8 | */ 9 | int main(void) 10 | { 11 | char ch; 12 | for (ch = 'a' ; ch <= 'z' ; ch++) 13 | { 14 | putchar(ch); 15 | } 16 | for (ch = 'A' ; ch <= 'Z' ; ch++) 17 | { 18 | putchar(ch); 19 | } 20 | putchar('\n'); 21 | return (0); 22 | } 23 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/9-print_comb.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - printing numbers from 0-9 with commas and space between them 4 | * Description: using the main function 5 | * this program prints "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" 6 | * Return: 0 7 | */ 8 | int main(void) 9 | { 10 | int c; 11 | 12 | for (c = 48; c <= 57; c++) 13 | { 14 | putchar(c); 15 | if (c != 57) 16 | { 17 | putchar(','); 18 | putchar(' '); 19 | } 20 | } 21 | putchar('\n'); 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/5-rev_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * rev_string - function that reverses a string. 4 | * @s: declaration of *s and paramters for the function 5 | * Return: Always 0. 6 | */ 7 | void rev_string(char *s) 8 | { 9 | int f, r_s; 10 | char character; 11 | 12 | for (f = '\0'; s[f] != 0; f++) 13 | { 14 | } 15 | r_s = 0; 16 | for (f = f - 1; r_s < f; r_s++) 17 | { 18 | character = s[f]; 19 | s[f] = s[r_s]; 20 | s[r_s] = character; 21 | f--; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /0x0D-structures_typedef/dog.h: -------------------------------------------------------------------------------- 1 | #ifndef DOG_H_FILE 2 | #define DOG_H_FILE 3 | 4 | /** 5 | * struct dog - structure definition of a dog 6 | * @name: dog name 7 | * @age: dog age 8 | * @owner: owner 9 | */ 10 | typedef struct dog 11 | { 12 | char *name; 13 | float age; 14 | char *owner; 15 | } dog_t; 16 | 17 | void init_dog(struct dog *d, char *name, float age, char *owner); 18 | void print_dog(struct dog *d); 19 | dog_t *new_dog(char *name, float age, char *owner); 20 | void free_dog(dog_t *d); 21 | #endif 22 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_INCLUDED 2 | #define HOLBERTON_H_INCLUDED 3 | 4 | int _putchar(char); 5 | void print_alphabet(void); 6 | void print_alphabet_x10(void); 7 | int _islower(int c); 8 | int _isalpha(int c); 9 | int print_sign(int n); 10 | int _abs(int); 11 | int print_last_digit(int); 12 | void jack_bauer(void); 13 | void times_table(void); 14 | int add(int a, int b); 15 | void print_to_98(int n); 16 | void print_times_table(int n); 17 | void num(int r, int n); 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/1-strncat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strncat - function that concatenates two strings 4 | * @dest: parmater for dest to append to 5 | * @src: parameter for src 6 | * @n: parameter for n 7 | * Return: Always 0. 8 | */ 9 | char *_strncat(char *dest, char *src, int n) 10 | { 11 | int a = 0; 12 | int b = 0; 13 | 14 | while (dest[a] != '\0') 15 | a++; 16 | while (src[b] != '\0' && b < n) 17 | { 18 | dest[a] = src[b]; 19 | b++; 20 | a++; 21 | } 22 | return (dest); 23 | } 24 | -------------------------------------------------------------------------------- /0x0C-preprocessor/README.md: -------------------------------------------------------------------------------- 1 | # C - Preprocessor 2 | * 0 - Create a header file that defines a macro named SIZE as an abbreviation for the token 1024. 3 | * 1 - Create a header file that defines a macro named PI as an abbreviation for the token 3.14159265359. 4 | * 2 - Write a program that prints the name of the file it was compiled from, followed by a new line. 5 | * 3 - Write a function-like macro ABS(x) that computes the absolute value of a number x. 6 | * 4 - Write a function-like macro SUM(x, y) that computes the sum of the numbers x and y. 7 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/2-strchr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strchr - returns a pointer to the first occurence of the 4 | * character c in the string s 5 | * @c: parameter for c to return 6 | * @s: string to search character 7 | * Return: pointer to first occurence of character c or null if not found 8 | */ 9 | char *_strchr(char *s, char c) 10 | { 11 | while (*s != '\0') 12 | { 13 | if (*s == c) 14 | return (s); 15 | s++; 16 | } 17 | if (*s == c) 18 | return (s); 19 | else 20 | return ('\0'); 21 | } 22 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/8-print_square.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_square - function that checks for uppercase character. 4 | * @size: the int for the paramaters of my function 5 | * Return: 0 6 | */ 7 | void print_square(int size) 8 | { 9 | int a = 0; 10 | int b = 0; 11 | 12 | if (size > 0) 13 | { 14 | while (a < size) 15 | { 16 | while (b < size) 17 | { 18 | _putchar('#'); 19 | b++; 20 | } 21 | b = 0; 22 | a++; 23 | _putchar('\n'); 24 | } 25 | } 26 | else 27 | _putchar('\n'); 28 | } 29 | -------------------------------------------------------------------------------- /0x08-static_libraries/2-strncpy.c: -------------------------------------------------------------------------------- 1 | /** 2 | * _strncpy - check the code for Holberton School students. 3 | * @src: parameter to a src to copy 4 | * @dest: parameter for dest 5 | * @n: parameter for number of bytes 6 | * Return: Always 0. 7 | */ 8 | 9 | char *_strncpy(char *dest, char *src, int n) 10 | { 11 | int a = 0; 12 | int b = 0; 13 | 14 | while (a != n) 15 | { 16 | dest[b] = src[a]; 17 | b++; 18 | a++; 19 | if (src[a] == '\0') 20 | { 21 | break; 22 | } 23 | } 24 | while (b != n) 25 | dest[b++] = '\0'; 26 | return (dest); 27 | } 28 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/7-print_diagonal.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_diagonal - function that draws a diagonal line on the terminal. 4 | * @n: the int for the paramaters of my function 5 | * Return: 0 6 | */ 7 | void print_diagonal(int n) 8 | { 9 | int a = 0; 10 | int b = 0; 11 | 12 | if (n > 0) 13 | { 14 | while (a < n) 15 | { 16 | while (b < a) 17 | { 18 | _putchar(' '); 19 | b++; 20 | } 21 | a++; 22 | b = 0; 23 | _putchar('\\'); 24 | _putchar('\n'); 25 | } 26 | } 27 | else 28 | _putchar('\n'); 29 | } 30 | -------------------------------------------------------------------------------- /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 | 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 | -------------------------------------------------------------------------------- /0x07-recursion/5-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _sqrt_recursion(1); 14 | printf("%d\n", r); 15 | r = _sqrt_recursion(1024); 16 | printf("%d\n", r); 17 | r = _sqrt_recursion(16); 18 | printf("%d\n", r); 19 | r = _sqrt_recursion(17); 20 | printf("%d\n", r); 21 | r = _sqrt_recursion(25); 22 | printf("%d\n", r); 23 | r = _sqrt_recursion(-1); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x09-argc_argv/3-mul.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - program that prints its name, followed by a new line 5 | * @argc: argument that counts argument input 6 | * @argv: argument that stores the strings in an array of char* (strings) 7 | * Return: 0 8 | */ 9 | int main(int argc, char *argv[]) 10 | { 11 | int num_1, num_2, mul; 12 | 13 | if (argc != 3) 14 | printf("Error\n"); 15 | else 16 | { 17 | num_1 = atoi(argv[1]); 18 | num_2 = atoi(argv[2]); 19 | mul = num_1 * num_2; 20 | printf("%d\n", mul); 21 | } 22 | return (0); 23 | } 24 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | # C - more pointers, arrays and strings 2 | * 0 - Write a function that concatenates two strings. 3 | * 2 - Write a function that copies a string. 4 | * 3 - Write a function that compares two strings. 5 | * 4 - Write a function that reverses the content of an array of integers. 6 | * 5 - Write a function that changes all lowercase letters of a string to uppercase. 7 | * 6 - Write a function that capitalizes all words of a string. 8 | * 7 - Write a function that encodes a string into 1337. 9 | * 8 - Write a function that encodes a string using rot13. 10 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/100-print_comb3.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints all possible different combinations of 2 digits 4 | * Return: 0 5 | */ 6 | int main(void) 7 | { 8 | int c = 0; 9 | int f_d; 10 | int l_d; 11 | 12 | while (c <= 99) 13 | { 14 | f_d = (c / 10 + '0'); 15 | l_d = (c % 10 + '0'); 16 | 17 | if (f_d < l_d) 18 | { 19 | putchar(f_d); 20 | putchar(l_d); 21 | 22 | if (c != 89) 23 | { 24 | putchar(','); 25 | putchar(' '); 26 | } 27 | } 28 | c++; 29 | } 30 | putchar('\n'); 31 | return (0); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /0x05-pointers_arrays_strings/2-strncpy.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strncpy - check the code for Holberton School students. 4 | * @src: parameter to a src to copy 5 | * @dest: parameter for dest 6 | * @n: parameter for number of bytes 7 | * Return: Always 0. 8 | */ 9 | 10 | char *_strncpy(char *dest, char *src, int n) 11 | { 12 | int a = 0; 13 | int b = 0; 14 | 15 | while (a != n) 16 | { 17 | dest[b] = src[a]; 18 | b++; 19 | a++; 20 | if (src[a] == '\0') 21 | { 22 | break; 23 | } 24 | } 25 | while (b != n) 26 | dest[b++] = '\0'; 27 | return (dest); 28 | } 29 | -------------------------------------------------------------------------------- /0x07-recursion/4-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = _pow_recursion(1, 10); 14 | printf("%d\n", r); 15 | r = _pow_recursion(1024, 0); 16 | printf("%d\n", r); 17 | r = _pow_recursion(2, 16); 18 | printf("%d\n", r); 19 | r = _pow_recursion(5, 2); 20 | printf("%d\n", r); 21 | r = _pow_recursion(5, -2); 22 | printf("%d\n", r); 23 | r = _pow_recursion(-5, 3); 24 | printf("%d\n", r); 25 | return (0); 26 | } 27 | -------------------------------------------------------------------------------- /0x0A-malloc_free/0-create_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "holberton.h" 3 | /** 4 | * create_array - check the code for Holberton School students. 5 | * @size: argument for size of the array 6 | * @c: argument for char 7 | * Return: Always 0. 8 | */ 9 | char *create_array(unsigned int size, char c) 10 | { 11 | char *my_array; 12 | unsigned int i = 0; 13 | 14 | my_array = malloc(size * sizeof(c)); 15 | 16 | while (i < size) 17 | { 18 | if (my_array == NULL) 19 | { 20 | return (NULL); 21 | } 22 | my_array[i] = c; 23 | i++; 24 | } 25 | return (my_array); 26 | } 27 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/9-fizz_buzz.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - function that checks for uppercase character. 4 | * Return: 0 5 | */ 6 | int main(void) 7 | { 8 | int h = 1; 9 | 10 | while (h <= 100) 11 | { 12 | if (h % 3 == 0 && h % 5 == 0) 13 | printf("FizzBuzz "); 14 | else if (h % 5 == 0) 15 | { 16 | if (h == 100) 17 | { 18 | printf("Buzz"); 19 | printf("\n"); 20 | } 21 | else 22 | printf("Buzz "); 23 | } 24 | else if (h % 3 == 0) 25 | printf("Fizz "); 26 | else 27 | printf("%d ", h); 28 | h++; 29 | } 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x0A-malloc_free/README.md: -------------------------------------------------------------------------------- 1 | # C - malloc, free 2 | * 0 - Write a function that creates an array of chars, and initializes it with a specific char. 3 | * 1 - Write a function that returns a pointer to a newly allocated space in memory, which contains a copy of the string given as a parameter. 4 | * 2 - Write a function that concatenates two strings. 5 | * 3 - Write a function that returns a pointer to a newly created 2 dimensional integers grid. 6 | * 4 - Write a function that frees a 2 dimensional grid previously created by alloc_grid. 7 | * 5 - Write a function that concatenates all the arguments of your program. 8 | -------------------------------------------------------------------------------- /0x0A-malloc_free/1-strdup.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strdup - check the code for Holberton School students. 5 | * @str: argument for array 6 | * Return: Always 0. 7 | */ 8 | char *_strdup(char *str) 9 | { 10 | char *my_array; 11 | int i, len; 12 | 13 | my_array = malloc(sizeof(str)); 14 | 15 | i = len = 0; 16 | while (str[i] != '\0') 17 | { 18 | len++; 19 | i++; 20 | } 21 | 22 | if (my_array == NULL) 23 | return (NULL); 24 | i = 0; 25 | while (str[i] != '\0') 26 | { 27 | my_array[i] = str[i]; 28 | i++; 29 | } 30 | 31 | return (my_array); 32 | } 33 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/100-prime_factor.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | /** 4 | * main - program that finds and prints the largest prime factor of a number 5 | * Return: Always 0. 6 | */ 7 | 8 | int main(void) 9 | { 10 | long int num = 612852475143; 11 | int prime; 12 | 13 | for (prime = 2; prime <= sqrt(num); prime++) 14 | { 15 | /*int saved_prime;*/ 16 | 17 | if (num % prime == 0) 18 | { 19 | /*saved_prime = prime;*/ 20 | num = num / prime; 21 | prime = 1; 22 | /* printf("%ld\n", num);*/ 23 | } 24 | } 25 | printf("%ld\n", num); 26 | return (0); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /0x0E-function_pointers/2-int_index.c: -------------------------------------------------------------------------------- 1 | #include "function_pointers.h" 2 | 3 | /** 4 | * int_index - Write a function that searches for an integer 5 | * @array: the array to check 6 | * @size: parameter for size 7 | * @cmp: paratmeter for cmp 8 | * Return: 0 if false, something else otherwise. 9 | */ 10 | int int_index(int *array, int size, int (*cmp)(int)) 11 | { 12 | int i; 13 | 14 | if (array == NULL || cmp == NULL || size <= 0) 15 | { 16 | return (-1); 17 | } 18 | 19 | for (i = 0; i < size; i++) 20 | { 21 | if (cmp(array[i])) 22 | { 23 | return (i); 24 | } 25 | } 26 | return (-1); 27 | } 28 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/3-array_range.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * array_range - create anarray of integers (min to max) 6 | * @min: min number to start 7 | * @max: max number to start 8 | * Return: pointer 9 | */ 10 | 11 | int *array_range(int min, int max) 12 | { 13 | int *ptr; 14 | int diff, i; 15 | 16 | if (min > max) 17 | return (NULL); 18 | diff = max - min; 19 | ptr = malloc((diff + 1) * sizeof(int)); 20 | if (ptr == NULL) 21 | return (NULL); 22 | for (i = 0; i <= diff; min++, i++) 23 | { 24 | ptr[i] = min; 25 | } 26 | return (ptr); 27 | } 28 | -------------------------------------------------------------------------------- /0x08-static_libraries/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strpbrk - locates the first occurrence in the string s of any 5 | * of the bytes in the string accept 6 | * @s: for the char 7 | * @accept: paramter for accept 8 | * Return: pointer to the byte s 9 | */ 10 | 11 | char *_strpbrk(char *s, char *accept) 12 | { 13 | int i, t, j; 14 | 15 | i = 0; 16 | while (s[i] != '\0') 17 | { 18 | t = 0; 19 | for (j = 0; accept[j] != '\0'; j++) 20 | { 21 | if (s[i] == accept[j]) 22 | t = 1; 23 | } 24 | j = 0; 25 | if (t == 1) 26 | return (s + i); 27 | i++; 28 | } 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/4-strpbrk.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | * _strpbrk - locates the first occurrence in the string s of any 5 | * of the bytes in the string accept 6 | * @s: for the char 7 | * @accept: paramter for accept 8 | * Return: pointer to the byte s 9 | */ 10 | 11 | char *_strpbrk(char *s, char *accept) 12 | { 13 | int i, t, j; 14 | 15 | i = 0; 16 | while (s[i] != '\0') 17 | { 18 | t = 0; 19 | for (j = 0; accept[j] != '\0'; j++) 20 | { 21 | if (s[i] == accept[j]) 22 | t = 1; 23 | } 24 | j = 0; 25 | if (t == 1) 26 | return (s + i); 27 | i++; 28 | } 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x08-static_libraries/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strspn - returns number of bytes in the initial sengment s 6 | * @s: for the count action 7 | * @accept: parameter for char 8 | * Return: number of bytes; 9 | */ 10 | 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int num; 14 | int i, j, t; 15 | 16 | i = 0; 17 | while (s[i] != '\0') 18 | { 19 | t = 0; 20 | for (j = 0; accept[j] != '\0'; j++) 21 | { 22 | if (s[i] == accept[j]) 23 | t = 1; 24 | } 25 | j = 0; 26 | if (t == 0) 27 | break; 28 | num++; 29 | i++; 30 | } 31 | return (i); 32 | } 33 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/3-strspn.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * _strspn - returns number of bytes in the initial sengment s 6 | * @s: for the count action 7 | * @accept: parameter for char 8 | * Return: number of bytes; 9 | */ 10 | 11 | unsigned int _strspn(char *s, char *accept) 12 | { 13 | unsigned int num; 14 | int i, j, t; 15 | 16 | i = 0; 17 | while (s[i] != '\0') 18 | { 19 | t = 0; 20 | for (j = 0; accept[j] != '\0'; j++) 21 | { 22 | if (s[i] == accept[j]) 23 | t = 1; 24 | } 25 | j = 0; 26 | if (t == 0) 27 | break; 28 | num++; 29 | i++; 30 | } 31 | return (i); 32 | } 33 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/101-print_comb4.c: -------------------------------------------------------------------------------- 1 | #include 2 | /** 3 | * main - program that prints all possible different combinations of 3 digits. 4 | * Return: 0 5 | */ 6 | int main(void) 7 | { 8 | int c = 0; 9 | int f_d; 10 | int m_d; 11 | int l_d; 12 | 13 | while (c <= 999) 14 | { 15 | f_d = (c / 100 + '0'); 16 | m_d = (c / 10 % 10 + '0'); 17 | l_d = (c % 10 + '0'); 18 | 19 | if ((f_d < m_d) && (m_d < l_d)) 20 | { 21 | putchar(f_d); 22 | putchar(m_d); 23 | putchar(l_d); 24 | 25 | if (c != 789) 26 | { 27 | putchar(','); 28 | putchar(' '); 29 | } 30 | } 31 | c++; 32 | } 33 | putchar('\n'); 34 | return (0); 35 | } 36 | -------------------------------------------------------------------------------- /0x07-recursion/6-is_prime_number.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * is_prime_number - func that returns 1 if a num is a prime num, 0 otherwise 4 | * @n: number for input 5 | * Return: 0 6 | */ 7 | int is_prime_number(int n) 8 | { 9 | return (helper_prime(n, 2, n / 2)); 10 | } 11 | 12 | /** 13 | * helper_prime - blank 14 | * @n: checkl 15 | * @i: for the increment 16 | * @limit: stop 17 | * Return: 0 18 | */ 19 | 20 | int helper_prime(int n, int i, int limit) 21 | { 22 | if ((n % i == 0 && i <= limit) || n < 0 || n == 1) 23 | return (0); 24 | else if (n % i != 0 && i <= limit) 25 | return (helper_prime(n, i + 1, limit)); 26 | else 27 | return (1); 28 | } 29 | -------------------------------------------------------------------------------- /0x00-hello_world/6-size.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /** 4 | * main - print the string in the put function 5 | * 6 | * Description: using the main function 7 | * this program prints "Programming is like building a multilingual puzzle 8 | * Return: 0 9 | */ 10 | int main(void) 11 | { 12 | char c; 13 | int i; 14 | long li; 15 | long long lli; 16 | float f; 17 | 18 | printf("Size of a char: %ld byte(s)\n", sizeof(c)); 19 | printf("Size of an int: %ld byte(s)\n", sizeof(i)); 20 | printf("Size of a long int: %ld byte(s)\n", sizeof(li)); 21 | printf("Size of a long long int: %ld byte(s)\n", sizeof(lli)); 22 | printf("Size of a float: %ld byte(s)\n", sizeof(f)); 23 | return (0); 24 | } 25 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/0-positive_or_negative.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | /** 6 | * main - print if the number is postive, zero, or negative 7 | * 8 | * Description: using the main function 9 | * this program prints "Programming is positive, zero, or negative 10 | * Return: 0 11 | */ 12 | int main(void) 13 | { 14 | int n; 15 | 16 | srand(time(0)); 17 | n = rand() - RAND_MAX / 2; 18 | /* your code goes there */ 19 | if (n > 0) 20 | { 21 | printf("%i is positive\n", n); 22 | } 23 | else if (n == 0) 24 | { 25 | printf("%i is zero\n", n); 26 | } 27 | else if (n < 0) 28 | { 29 | printf("%i is negative\n", n); 30 | } 31 | return (0); 32 | } 33 | -------------------------------------------------------------------------------- /0x07-recursion/6-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * main - check the code for Holberton School students. 6 | * 7 | * Return: Always 0. 8 | */ 9 | int main(void) 10 | { 11 | int r; 12 | 13 | r = is_prime_number(1); 14 | printf("%d\n", r); 15 | r = is_prime_number(1024); 16 | printf("%d\n", r); 17 | r = is_prime_number(16); 18 | printf("%d\n", r); 19 | r = is_prime_number(17); 20 | printf("%d\n", r); 21 | r = is_prime_number(25); 22 | printf("%d\n", r); 23 | r = is_prime_number(-1); 24 | printf("%d\n", r); 25 | r = is_prime_number(113); 26 | printf("%d\n", r); 27 | r = is_prime_number(7919); 28 | printf("%d\n", r); 29 | return (0); 30 | } 31 | -------------------------------------------------------------------------------- /0x07-recursion/5-sqrt_recursion.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | 3 | /** 4 | *_sqrt_recursion - func that returns the natural square root of a number. 5 | * @n: for number input 6 | * Return: 0 7 | */ 8 | 9 | int _sqrt_recursion(int n) 10 | { 11 | if (n == 0) 12 | return (0); 13 | else if (n == 1) 14 | return (1); 15 | else if (n < 0) 16 | return (-1); 17 | else 18 | return (helper(n, 1)); 19 | } 20 | 21 | /** 22 | * helper - blank 23 | * @n: number 24 | * @i: incrementor 25 | * Return: -1; 26 | */ 27 | 28 | int helper(int n, int i) 29 | { 30 | if (n == (i * i)) 31 | return (i); 32 | else if (n > (i * i)) 33 | return (helper(n, i + 1)); 34 | else 35 | return (-1); 36 | } 37 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/10-print_triangle.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * print_triangle - Function that prints a triangle, followed by a new line. 4 | * @size: the int for the paramaters of my function 5 | * Return: Always 0. 6 | */ 7 | void print_triangle(int size) 8 | { 9 | int x, y = 0; 10 | int space; 11 | 12 | if (size > 0) 13 | { 14 | while (y < size) 15 | { 16 | space = size - y - 1; 17 | while (x < size) 18 | { 19 | if (space > x) 20 | { 21 | _putchar(' '); 22 | } 23 | else 24 | { 25 | _putchar('#'); 26 | } 27 | x++; 28 | } 29 | y++; 30 | x = 0; 31 | _putchar ('\n'); 32 | } 33 | } 34 | else 35 | _putchar('\n'); 36 | } 37 | -------------------------------------------------------------------------------- /0x0A-malloc_free/2-str_concat.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * str_concat - function that concatenates two strings 5 | * @s1: paramater for string 1 6 | * @s2: parameter for string 2 7 | * Return: Always 0. 8 | */ 9 | char *str_concat(char *s1, char *s2) 10 | { 11 | int a, b, c; 12 | char *my_array; 13 | 14 | c = 0; 15 | my_array = malloc(sizeof(*s1 + *s2)); 16 | 17 | if (my_array == NULL) 18 | return (NULL); 19 | 20 | a = 0; 21 | while (s1[a] != '\0') 22 | { 23 | my_array[c] = s1[a]; 24 | a++; 25 | c++; 26 | } 27 | b = 0; 28 | while (s2[b] != '\0') 29 | { 30 | my_array[c] = s2[b]; 31 | b++; 32 | c++; 33 | } 34 | 35 | return (my_array); 36 | free(my_array); 37 | } 38 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * main - check the code for Holberton School students. 8 | * 9 | * Return: Always 0. 10 | */ 11 | int main(void) 12 | { 13 | char *c; 14 | int *i; 15 | float *f; 16 | double *d; 17 | 18 | c = malloc_checked(sizeof(char) * 1024); 19 | printf("%p\n", (void *)c); 20 | i = malloc_checked(sizeof(int) * 402); 21 | printf("%p\n", (void *)i); 22 | f = malloc_checked(sizeof(float) * 100000000); 23 | printf("%p\n", (void *)f); 24 | d = malloc_checked(INT_MAX); 25 | printf("%p\n", (void *)d); 26 | free(c); 27 | free(i); 28 | free(f); 29 | free(d); 30 | return (0); 31 | } 32 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/1-last_digit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | /** 5 | * main - print if the number is postive, zero, or negative 6 | * 7 | * Description: using the main function 8 | * this program prints "Programming is positive, zero, or negative 9 | * Return: 0 10 | */ 11 | int main(void) 12 | { 13 | int n; 14 | int l; 15 | 16 | srand(time(0)); 17 | n = rand() - RAND_MAX / 2; 18 | l = n % 10; 19 | 20 | if (l > 5) 21 | { 22 | printf("Last digit of %d is %d and is greater than 5\n", n, l); 23 | } 24 | else if (l == 0) 25 | { 26 | printf("Last digit of %d is %d and is 0\n", n, l); 27 | } 28 | else 29 | { 30 | printf("Last digit of %d is %d and is less than 6 and not 0\n", n, l); 31 | } 32 | return (0); 33 | } 34 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/7-puts_half.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * puts_half - function that prints half of a string, followed by a new line. 4 | * @str: declaration of n and paramters for the function 5 | * Return: Always 0. 6 | */ 7 | void puts_half(char *str) 8 | { 9 | int c, a; 10 | char l; 11 | 12 | for (c = 0; str[c] != 0; c++) 13 | { 14 | } 15 | if (c % 2 == 0) 16 | { 17 | for ((a = c / 2); str[a] != 0; a++) 18 | { 19 | l = str[a]; 20 | _putchar(l); 21 | } 22 | } 23 | else 24 | { 25 | for ((a = (c - 1) / 2); str[a] != 0; a++) 26 | { 27 | l = str[a]; 28 | _putchar(l); 29 | } 30 | } 31 | _putchar('\n'); 32 | } 33 | -------------------------------------------------------------------------------- /0x08-static_libraries/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strstr - finds the first occurence of the substring needle 5 | * in the string haystack 6 | * @haystack: paramter for haystack 7 | * @needle: paramter for needle 8 | * Return: pointer to the beginning of the located substring 9 | */ 10 | char *_strstr(char *haystack, char *needle) 11 | { 12 | 13 | while (*haystack != '\0') 14 | { 15 | char *beginning = haystack; 16 | char *pattern = needle; 17 | 18 | while (*pattern == *haystack && *pattern != '\0' 19 | && *haystack != '\0') 20 | { 21 | haystack++; 22 | pattern++; 23 | } 24 | if (*pattern == '\0') 25 | return (beginning); 26 | haystack = beginning + 1; 27 | } 28 | return ('\0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/5-strstr.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | /** 4 | * _strstr - finds the first occurence of the substring needle 5 | * in the string haystack 6 | * @haystack: paramter for haystack 7 | * @needle: paramter for needle 8 | * Return: pointer to the beginning of the located substring 9 | */ 10 | char *_strstr(char *haystack, char *needle) 11 | { 12 | 13 | while (*haystack != '\0') 14 | { 15 | char *beginning = haystack; 16 | char *pattern = needle; 17 | 18 | while (*pattern == *haystack && *pattern != '\0' 19 | && *haystack != '\0') 20 | { 21 | haystack++; 22 | pattern++; 23 | } 24 | if (*pattern == '\0') 25 | return (beginning); 26 | haystack = beginning + 1; 27 | } 28 | return ('\0'); 29 | } 30 | -------------------------------------------------------------------------------- /0x0F-variadic_functions/0-sum_them_all.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | /** 4 | * sum_them_all - function that returns the sum of all its parameters. 5 | * @n: resepresents the number of arguments 6 | * Return: Always 0. 7 | */ 8 | int sum_them_all(const unsigned int n, ...) 9 | { 10 | /* creating va_list to store the variable argument list */ 11 | va_list my_nums; 12 | unsigned int count; 13 | int sum; 14 | 15 | if (n == 0) 16 | return (0); 17 | sum = 0; 18 | 19 | /* init valist for the number of arguments */ 20 | va_start(my_nums, n); 21 | 22 | /* loop through/access all arguments stored in the valist */ 23 | for (count = 0; count < n; count++) 24 | sum += va_arg(my_nums, int); 25 | va_end(my_nums); 26 | return (sum); 27 | } 28 | -------------------------------------------------------------------------------- /0x09-argc_argv/4-add.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | /** 6 | * main - program that prints its name, followed by a new line 7 | * @argc: argument that counts argument input 8 | * @argv: argument that stores the strings in an array of char* (strings) 9 | * Return: 0 10 | */ 11 | int main(int argc, char *argv[]) 12 | { 13 | int sum, val, i; 14 | 15 | sum = 0; 16 | if (argc < 1) 17 | printf("%d\n", 0); 18 | while (argc-- && argc > 0) 19 | { 20 | for (i = 0; argv[argc][i] != '\0'; i++) 21 | { 22 | 23 | if (!(isdigit(argv[argc][i]))) 24 | { 25 | printf("Error\n"); 26 | return (1); 27 | } 28 | } 29 | val = atoi(argv[argc]); 30 | sum += val; 31 | } 32 | printf("%d\n", sum); 33 | return (0); 34 | } 35 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/8-24_hours.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * jack_bauer - func that prints every minute of the day of Jack Bauer, starti 4 | * n from 00:00 to 23:59, min loop counts mins, while hour loop counts hours 5 | * and resets mins 6 | * Return: 0 7 | */ 8 | void jack_bauer(void) 9 | { 10 | int hours = 0; 11 | int minutes = 0; 12 | int hours_remainder; 13 | int mins_remainder; 14 | 15 | while (hours <= 23) 16 | { 17 | while (minutes <= 59) 18 | { 19 | mins_remainder = minutes % 10; 20 | hours_remainder = hours % 10; 21 | _putchar(hours / 10 + '0'); 22 | _putchar(hours_remainder + '0'); 23 | _putchar(':'); 24 | _putchar(minutes / 10 + '0'); 25 | _putchar(mins_remainder + '0'); 26 | minutes++; 27 | _putchar('\n'); 28 | } 29 | hours++; 30 | minutes = 0; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /0x0E-function_pointers/1-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "function_pointers.h" 3 | 4 | /** 5 | * print_elem - prints an integer 6 | * @elem: the integer to print 7 | * 8 | * Return: Nothing. 9 | */ 10 | void print_elem(int elem) 11 | { 12 | printf("%d\n", elem); 13 | } 14 | 15 | /** 16 | * print_elem_hex - prints an integer, in hexadecimal 17 | * @elem: the integer to print 18 | * 19 | * Return: Nothing. 20 | */ 21 | void print_elem_hex(int elem) 22 | { 23 | printf("0x%x\n", elem); 24 | } 25 | 26 | /** 27 | * main - check the code for Holberton School students. 28 | * 29 | * Return: Always 0. 30 | */ 31 | int main(void) 32 | { 33 | int array[5] = {0, 98, 402, 1024, 4096}; 34 | 35 | array_iterator(array, 5, &print_elem); 36 | array_iterator(array, 5, &print_elem_hex); 37 | return (0); 38 | } 39 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/1-string_nconcat.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /** 5 | * string_nconcat - concatenates two strings 6 | * @s1:stirng 1 7 | * @s2:string 2 8 | * @n: n bytesofstring 2 9 | * Return: pointer 10 | */ 11 | 12 | char *string_nconcat(char *s1, char *s2, unsigned int n) 13 | { 14 | char *ptr, *empt; 15 | unsigned int i, k; 16 | 17 | empt = ""; 18 | if (s1 == NULL) 19 | s1 = empt; 20 | if (s2 == NULL) 21 | s2 = empt; 22 | for (i = 0; s1[i] != '\0'; i++) 23 | ; 24 | ptr = malloc((i + (n * sizeof(*s2) + 1) * sizeof(*ptr))); 25 | if (ptr == NULL) 26 | return (NULL); 27 | for (i = 0; s1[i] != '\0'; i++) 28 | ptr[i] = s1[i]; 29 | for (k = 0; s2[k] != '\0' && k < n; k++, i++) 30 | ptr[i] = s2[k]; 31 | ptr[i] = '\0'; 32 | return (ptr); 33 | } 34 | -------------------------------------------------------------------------------- /0x08-static_libraries/holberton.h: -------------------------------------------------------------------------------- 1 | #ifndef HOLBERTON_H_FILE 2 | #define HOLBERTON_H_FILE 3 | 4 | int _putchar(char c); 5 | int _islower(int c); 6 | int _isalpha(int c); 7 | int _abs(int n); 8 | int _isupper(int c); 9 | int _isdigit(int c); 10 | int _strlen(char *s); 11 | void _puts(char *s); 12 | char *_strcpy(char *dest, char *src); 13 | int _atoi(char *s); 14 | char *_strcat(char *dest, char *src); 15 | char *_strncat(char *dest, char *src, int n); 16 | char *_strncpy(char *dest, char *src, int n); 17 | int _strcmp(char *s1, char *s2); 18 | char *_memset(char *s, char b, unsigned int n); 19 | char *_memcpy(char *dest, char *src, unsigned int n); 20 | char *_strchr(char *s, char c); 21 | unsigned int _strspn(char *s, char *accept); 22 | char *_strpbrk(char *s, char *accept); 23 | char *_strstr(char *haystack, char *needle); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /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 s1[98]; 12 | char *p; 13 | int i; 14 | 15 | for (i = 0; i < 98 - 1; i++) 16 | { 17 | s1[i] = '*'; 18 | } 19 | s1[i] = '\0'; 20 | printf("%s\n", s1); 21 | p = _strncpy(s1, "First, solve the problem. Then, write the code\n", 5); 22 | printf("%s\n", s1); 23 | printf("%s\n", p); 24 | p = _strncpy(s1, "First, solve the problem. Then, write the code\n", 90); 25 | printf("%s", s1); 26 | printf("%s", p); 27 | for (i = 0; i < 98; i++) 28 | { 29 | if (i % 10) 30 | { 31 | printf(" "); 32 | } 33 | if (!(i % 10) && i) 34 | { 35 | printf("\n"); 36 | } 37 | printf("0x%02x", s1[i]); 38 | } 39 | printf("\n"); 40 | return (0); 41 | } 42 | -------------------------------------------------------------------------------- /0x00-hello_world/README.md: -------------------------------------------------------------------------------- 1 | # C - Hello, World 2 | * 0 - Write a script that runs a C file through the preprocessor and save the result into another file 3 | * 1 - Write a script that generates the assembly code of a C code and save it in an output file. 4 | * 2 - Write a script that compiles a C file but does not link. 5 | * 3 - Write a script that compiles a C file and creates an executable named cisfun. 6 | * 4 - Write a C program that prints exactly "Programming is like building a multilingual puzzle, followed by a new line. 7 | * 5 - Write a C program that prints exactly with proper grammar, but the outcome is a piece of art,, followed by a new line. 8 | * 6 - Write a C program that prints the size of various types on the computer it is compiled and run on. 9 | * 7 - (100 - Intel) Write a script that generates the assembly code (Intel syntax) of a C code and save it in an output file. 10 | -------------------------------------------------------------------------------- /0x0F-variadic_functions/1-print_numbers.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | #include 4 | /** 5 | * print_numbers - function that prints numbers. 6 | * @n: resepresents the number of arguments 7 | * @separator: resepresents the seperator b/w the numbers 8 | * Return: Always 0. 9 | */ 10 | void print_numbers(const char *separator, const unsigned int n, ...) 11 | { 12 | /* creating va_list to store the variable argument list */ 13 | va_list my_nums; 14 | unsigned int count; 15 | 16 | /* init valist for the number of arguments */ 17 | va_start(my_nums, n); 18 | 19 | /* loop through/access all arguments stored in the valist */ 20 | for (count = 0; count < n; count++) 21 | { 22 | printf("%d", va_arg(my_nums, unsigned int)); 23 | if (count < (n - 1) && separator != NULL) 24 | printf("%s", separator); 25 | } 26 | va_end(my_nums); 27 | printf("\n"); 28 | } 29 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/2-calloc.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "holberton.h" 4 | 5 | /** 6 | *_calloc - allocate memory for an array usingmalloc 7 | * @nmemb: number ofelements 8 | * @size: size of bytes 9 | * Return: pointer 10 | */ 11 | 12 | void *_calloc(unsigned int nmemb, unsigned int size) 13 | { 14 | void *ptr; 15 | 16 | if (nmemb == 0 || size == 0) 17 | return (NULL); 18 | ptr = malloc(nmemb * size); 19 | if (ptr == NULL) 20 | return (NULL); 21 | _memset(ptr, 0, (nmemb * size)); 22 | return (ptr); 23 | } 24 | 25 | /** 26 | *_memset - sets first n bytes of the memory area 27 | * @s: array to set 28 | * @b: what to set it to 29 | * @n: first n bytes 30 | * Return: s 31 | */ 32 | 33 | char *_memset(char *s, char b, unsigned int n) 34 | { 35 | unsigned int i; 36 | 37 | for (i = 0; i < n; i++) 38 | { 39 | s[i] = b; 40 | } 41 | return (s); 42 | } 43 | -------------------------------------------------------------------------------- /0x04-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | # C - pointers, arrays and strings 2 | * 0 - Write a function that takes a pointer to an int as parameter and updates the value it points to to 98. 3 | * 1 - Write a function that swaps the values of two integers. 4 | * 2 - Write a function that returns the length of a string. 5 | * 3 - Write a function that prints a string, followed by a new line, to stdout. 6 | * 4 - Write a function that prints a string, in reverse, followed by a new line. 7 | * 5 - Write a function that reverses a string. 8 | * 6 - Write a function that prints one char out of 2 of a string, followed by a new line. 9 | * 7 - Write a function that prints half of a string, followed by a new line. 10 | * 8 - Write a function that prints n elements of an array of integers, followed by a new line. 11 | * 9 - Write a function that copies the string pointed to by src, including the terminating null byte (\0), to the buffer pointed to by dest. 12 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/3-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * simple_print_buffer - prints buffer in hexa 8 | * @buffer: the address of memory to print 9 | * @size: the size of the memory to print 10 | * 11 | * Return: Nothing. 12 | */ 13 | void simple_print_buffer(int *buffer, unsigned int size) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | while (i < size) 19 | { 20 | if (i % 10) 21 | { 22 | printf(" "); 23 | } 24 | if (!(i % 10) && i) 25 | { 26 | printf("\n"); 27 | } 28 | printf("0x%02x", buffer[i]); 29 | i++; 30 | } 31 | printf("\n"); 32 | } 33 | 34 | /** 35 | * main - check the code for Holberton School students. 36 | * 37 | * Return: Always 0. 38 | */ 39 | int main(void) 40 | { 41 | int *a; 42 | 43 | a = array_range(0, 10); 44 | simple_print_buffer(a, 11); 45 | free(a); 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /0x02-functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | * 0 - Write a program that prints Holberton, followed by a new line. 2 | * 1 - Write a function that prints the alphabet, in lowercase, followed by a new line. 3 | * 2 - Write a function that prints 10 times the alphabet, in lowercase, followed by a new line. 4 | * 3 - Write a function that checks for lowercase character. 5 | * 4 - Write a function that checks for alphabetic character. 6 | * 5 - Write a function that prints the sign of a number. 7 | * 6 - There is no such thing as absolute value in this world. You can only estimate what a thing is worth to you mandatory 8 | * 7 - Write a function that prints the last digit of a number. 9 | * 8 - Write a function that prints every minute of the day of Jack Bauer, starting from 00:00 to 23:59. 10 | * 9 - Learn your times table mandatory 11 | * 10 - Write a function that adds two integer and returns the result. 12 | * 11 - Write a function that prints all natural numbers from n to 98, followed by a new line. 13 | -------------------------------------------------------------------------------- /0x0F-variadic_functions/2-print_strings.c: -------------------------------------------------------------------------------- 1 | #include "variadic_functions.h" 2 | #include 3 | #include 4 | /** 5 | * print_strings - function that prints strings. 6 | * @n: resepresents the number of arguments 7 | * @separator: resepresents the seperator b/w the numbers 8 | * Return: Always 0. 9 | */ 10 | void print_strings(const char *separator, const unsigned int n, ...) 11 | { 12 | /* creating va_list to store the variable argument list */ 13 | va_list strings; 14 | unsigned int count; 15 | char *str; 16 | 17 | /* init valist for the number of arguments */ 18 | va_start(strings, n); 19 | 20 | /* loop through/access all arguments stored in the valist */ 21 | for (count = 0; count < n; count++) 22 | { 23 | str = va_arg(strings, char *); 24 | if (str == NULL) 25 | printf("nil"); 26 | else 27 | { 28 | printf("%s", str); 29 | if (count < (n - 1) && separator != NULL) 30 | printf("%s", separator); 31 | } 32 | } 33 | va_end(strings); /* clean up the list */ 34 | printf("\n"); 35 | } 36 | -------------------------------------------------------------------------------- /0x0B-more_malloc_free/2-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | #include 5 | 6 | /** 7 | * simple_print_buffer - prints buffer in hexa 8 | * @buffer: the address of memory to print 9 | * @size: the size of the memory to print 10 | * 11 | * Return: Nothing. 12 | */ 13 | void simple_print_buffer(char *buffer, unsigned int size) 14 | { 15 | unsigned int i; 16 | 17 | i = 0; 18 | while (i < size) 19 | { 20 | if (i % 10) 21 | { 22 | printf(" "); 23 | } 24 | if (!(i % 10) && i) 25 | { 26 | printf("\n"); 27 | } 28 | printf("0x%02x", buffer[i]); 29 | i++; 30 | } 31 | printf("\n"); 32 | } 33 | 34 | /** 35 | * main - check the code for Holberton School students. 36 | * 37 | * Return: Always 0. 38 | */ 39 | int main(void) 40 | { 41 | char *a; 42 | 43 | a = _calloc(98, sizeof(char)); 44 | strcpy(a, "Holberton"); 45 | strcpy(a + 9, " School! :)\n"); 46 | a[97] = '!'; 47 | simple_print_buffer(a, 98); 48 | return (0); 49 | } 50 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/1-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * simple_print_buffer - prints buffer in hexa 6 | * @buffer: the address of memory to print 7 | * @size: the size of the memory to print 8 | * 9 | * Return: Nothing. 10 | */ 11 | void simple_print_buffer(char *buffer, unsigned int size) 12 | { 13 | unsigned int i; 14 | 15 | i = 0; 16 | while (i < size) 17 | { 18 | if (i % 10) 19 | { 20 | printf(" "); 21 | } 22 | if (!(i % 10) && i) 23 | { 24 | printf("\n"); 25 | } 26 | printf("0x%02x", buffer[i]); 27 | i++; 28 | } 29 | printf("\n"); 30 | } 31 | 32 | /** 33 | * main - check the code for Holberton School students. 34 | * 35 | * Return: Always 0. 36 | */ 37 | int main(void) 38 | { 39 | char buffer[98] = {0}; 40 | char buffer2[98] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 41 | 42 | simple_print_buffer(buffer, 98); 43 | _memcpy(buffer + 50, buffer2, 10); 44 | printf("-------------------------------------------------\n"); 45 | simple_print_buffer(buffer, 98); 46 | return (0); 47 | } 48 | -------------------------------------------------------------------------------- /0x07-recursion/7-is_palindrome.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | /** 3 | * _strlen_recursion - find length of string, recursively 4 | * @s: pointer to beginning of string 5 | * Return: int representing string length 6 | */ 7 | int _strlen_recursion(char *s) 8 | { 9 | if (*s) 10 | return (_strlen_recursion(s + 1) + 1); 11 | return (0); 12 | } 13 | /** 14 | * pal_check - recursively checks for palindrome 15 | * @a: for the start of string 16 | * @length: length of string 17 | * Return: 1 if pal, 0 otherwise 18 | */ 19 | int pal_check(char *a, int length) 20 | { 21 | if (length <= 1) 22 | return (1); 23 | else if (a[0] != a[length - 1]) 24 | return (0); 25 | else 26 | return (pal_check((a + 1), (length - 2))); 27 | } 28 | /** 29 | * is_palindrome - recursively checks for palindrome 30 | * @s: pointer to beginning of string, potential palindrome 31 | * Return: 1 if pal, 0 otherwise 32 | */ 33 | 34 | int is_palindrome(char *s) 35 | { 36 | int len; 37 | 38 | len = _strlen_recursion(s); 39 | if (len <= 1) 40 | return (1); 41 | return (pal_check(s, len)); 42 | } 43 | -------------------------------------------------------------------------------- /0x0E-function_pointers/0-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "function_pointers.h" 3 | 4 | /** 5 | * print_name_as_is - prints a name as is 6 | * @name: name of the person 7 | * 8 | * Return: Nothing. 9 | */ 10 | void print_name_as_is(char *name) 11 | { 12 | printf("Hello, my name is %s\n", name); 13 | } 14 | 15 | /** 16 | * print_name_uppercase - print a name in uppercase 17 | * @name: name of the person 18 | * 19 | * Return: Nothing. 20 | */ 21 | void print_name_uppercase(char *name) 22 | { 23 | unsigned int i; 24 | 25 | printf("Hello, my uppercase name is "); 26 | i = 0; 27 | while (name[i]) 28 | { 29 | if (name[i] >= 'a' && name[i] <= 'z') 30 | { 31 | putchar(name[i] + 'A' - 'a'); 32 | } 33 | else 34 | { 35 | putchar(name[i]); 36 | } 37 | i++; 38 | } 39 | } 40 | 41 | /** 42 | * main - check the code for Holberton School students. 43 | * 44 | * Return: Always 0. 45 | */ 46 | int main(void) 47 | { 48 | print_name("Danton", print_name_as_is); 49 | print_name("Rick Harris", print_name_uppercase); 50 | printf("\n"); 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /0x03-more_functions_nested_loops/README.md: -------------------------------------------------------------------------------- 1 | # C - more functions, more nested loops 2 | * 0 - Write a function that checks for uppercase character. 3 | * 1 - Write a function that checks for a digit (0 through 9). 4 | * 2 - Write a function that multiplies two integers. 5 | * 3 - Write a function that prints the numbers, from 0 to 9, followed by a new line. 6 | * 4 - Write a function that prints the numbers, from 0 to 9, followed by a new line. 7 | * 5 - Write a function that prints 10 times the numbers, from 0 to 14, followed by a new line. 8 | * 6 - Write a function that draws a straight line in the terminal. 9 | * 7 - Write a function that draws a diagonal line on the terminal. 10 | * 8 - Write a function that prints a square, followed by a new line. 11 | * 9 - Fizz-Buzz - Write a program that prints the numbers from 1 to 100, followed by a new line. But for multiples of three print Fizz instead of the number and for the multiples of five print Buzz. For numbers which are multiples of both three and five print FizzBuzz. 12 | * 10 - Write a function that prints a triangle, followed by a new line. 13 | -------------------------------------------------------------------------------- /0x0A-malloc_free/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | #include 4 | 5 | /** 6 | * simple_print_buffer - prints buffer in hexa 7 | * @buffer: the address of memory to print 8 | * @size: the size of the memory to print 9 | * 10 | * Return: Nothing. 11 | */ 12 | void simple_print_buffer(char *buffer, unsigned int size) 13 | { 14 | unsigned int i; 15 | 16 | i = 0; 17 | while (i < size) 18 | { 19 | if (i % 10) 20 | { 21 | printf(" "); 22 | } 23 | if (!(i % 10) && i) 24 | { 25 | printf("\n"); 26 | } 27 | printf("0x%02x", buffer[i]); 28 | i++; 29 | } 30 | printf("\n"); 31 | } 32 | 33 | /** 34 | * main - check the code for Holberton School students. 35 | * 36 | * Return: Always 0. 37 | */ 38 | int main(void) 39 | { 40 | char *buffer; 41 | 42 | buffer = create_array(98, 'H'); 43 | if (buffer == NULL) 44 | { 45 | printf("failed to allocate memory\n"); 46 | return (1); 47 | } 48 | simple_print_buffer(buffer, 98); 49 | free(buffer); 50 | return (0); 51 | } 52 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/0-main.c: -------------------------------------------------------------------------------- 1 | #include "holberton.h" 2 | #include 3 | 4 | /** 5 | * simple_print_buffer - prints buffer in hexa 6 | * @buffer: the address of memory to print 7 | * @size: the size of the memory to print 8 | * 9 | * Return: Nothing. 10 | */ 11 | void simple_print_buffer(char *buffer, unsigned int size) 12 | { 13 | unsigned int i; 14 | 15 | i = 0; 16 | while (i < size) 17 | { 18 | if (i % 10) 19 | { 20 | printf(" "); 21 | } 22 | if (!(i % 10) && i) 23 | { 24 | printf("\n"); 25 | } 26 | printf("0x%02x", buffer[i]); 27 | i++; 28 | } 29 | printf("\n"); 30 | } 31 | 32 | /** 33 | * main - check the code for Holberton School students. 34 | * 35 | * Return: Always 0. 36 | */ 37 | int main(void) 38 | { 39 | char buffer[98] = {0x00}; 40 | 41 | simple_print_buffer(buffer, 98); 42 | _memset(buffer, 0x01, 95); 43 | printf("-------------------------------------------------\n"); 44 | simple_print_buffer(buffer, 98); 45 | return (0); 46 | } 47 | -------------------------------------------------------------------------------- /0x08-static_libraries/README.md: -------------------------------------------------------------------------------- 1 | # C - Static libraries 2 | * 0 - Create the static library libholberton.a containing all the functions listed below: 3 | 4 | int _putchar(char c); 5 | int _islower(int c); 6 | int _isalpha(int c); 7 | int _abs(int n); 8 | int _isupper(int c); 9 | int _isdigit(int c); 10 | int _strlen(char *s); 11 | void _puts(char *s); 12 | char *_strcpy(char *dest, char *src); 13 | int _atoi(char *s); 14 | char *_strcat(char *dest, char *src); 15 | char *_strncat(char *dest, char *src, int n); 16 | char *_strncpy(char *dest, char *src, int n); 17 | int _strcmp(char *s1, char *s2); 18 | char *_memset(char *s, char b, unsigned int n); 19 | char *_memcpy(char *dest, char *src, unsigned int n); 20 | char *_strchr(char *s, char c); 21 | unsigned int _strspn(char *s, char *accept); 22 | char *_strpbrk(char *s, char *accept); 23 | char *_strstr(char *haystack, char *needle); 24 | 25 | If you haven't coded all of the above functions create empty ones, with the right prototype. 26 | Don't forget to include push your holberton.h file in your repository, containing at least all the prototypes of the above functions. 27 | 28 | * 1 - Create a script called create_static_lib.sh that creates a static library called liball.a from all the .c files that are in the current directory. 29 | -------------------------------------------------------------------------------- /0x0E-function_pointers/2-main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include "function_pointers.h" 3 | 4 | /** 5 | * is_98 - check if a number is equal to 98 6 | * @elem: the integer to check 7 | * 8 | * Return: 0 if false, something else otherwise. 9 | */ 10 | int is_98(int elem) 11 | { 12 | return (98 == elem); 13 | } 14 | 15 | /** 16 | * is_strictly_positive - check if a number is greater than 0 17 | * @elem: the integer to check 18 | * 19 | * Return: 0 if false, something else otherwise. 20 | */ 21 | int is_strictly_positive(int elem) 22 | { 23 | return (elem > 0); 24 | } 25 | 26 | 27 | /** 28 | * abs_is_98 - check if the absolute value of a number is 98 29 | * @elem: the integer to check 30 | * 31 | * Return: 0 if false, something else otherwise. 32 | */ 33 | int abs_is_98(int elem) 34 | { 35 | return (elem == 98 || -elem == 98); 36 | } 37 | 38 | /** 39 | * main - check the code for Holberton School students. 40 | * 41 | * Return: Always 0. 42 | */ 43 | int main(void) 44 | { 45 | int array[20] = {0, -98, 98, 402, 1024, 4096, -1024, -98, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 98}; 46 | int index; 47 | 48 | index = int_index(array, 20, is_98); 49 | printf("%d\n", index); 50 | index = int_index(array, 20, abs_is_98); 51 | printf("%d\n", index); 52 | index = int_index(array, 20, is_strictly_positive); 53 | printf("%d\n", index); 54 | return (0); 55 | } 56 | -------------------------------------------------------------------------------- /0x01-variables_if_else_while/README.md: -------------------------------------------------------------------------------- 1 | * 0 - This program will affect a random number to the variable n each time it is executed. Complete the source code in order to print whether the number stored in the variable n is positive or negative. [Source Code [here](https://github.com/holbertonschool/0x01.c/blob/master/1-last_digit_c)] 2 | * 1 - This program will affect a random number to the variable n each time it is executed. Complete the source code in order to print the last digit of the number stored in the variable n. [Source code [here](https://github.com/holbertonschool/0x01.c/blob/master/1-last_digit_c)] 3 | * 2 - Write a program that prints the alphabet, in lowercase, followed by a new line. 4 | * 3 - Write a program that prints the alphabet, in lowercase, and then in uppercase, followed by a new line. 5 | * 4 - Write a program that prints the alphabet, in lowercase, followed by a new line. 6 | * 5 - Write a program that prints all numbers of base 10, starting from 0, followed by a new line. 7 | * 6 - Write a program that prints all numbers of base 10, starting from 0, followed by a new line. 8 | * 7 - Write a program that prints the alphabet, in reverse order, in lowercase, followed by a new line. 9 | * 8 - Write a program that prints all the numbers of base 16, in lowercase, followed by a new line. 10 | * 9 - Write a program that prints all possible combinations of single-digit numbers. 11 | * 10 - Write a program that prints numbers from 0 to 99. 12 | -------------------------------------------------------------------------------- /0x07-recursion/README.md: -------------------------------------------------------------------------------- 1 | #C - Recursion 2 | Write a function that prints a string, followed by a new line. 3 | 4 | Prototype: void _puts_recursion(char *s); 5 | FYI: The standard library provides a similar function: puts. Run man puts to learn more. 6 | 7 | julien@ubuntu:~/0x07. Recursion$ cat 0-main.c 8 | #include "holberton.h" 9 | 10 | /** 11 | * main - check the code for Holberton School students. 12 | * 13 | * Return: Always 0. 14 | */ 15 | int main(void) 16 | { 17 | _puts_recursion("Betty Holberton"); 18 | return (0); 19 | } 20 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra _putchar.c 0-main.c 0-puts_recursion.c -o 0-puts_recursion 21 | julien@ubuntu:~/0x07. Recursion$ ./0-puts_recursion 22 | Betty Holberton 23 | julien@ubuntu:~/0x07. Recursion$ 24 | Repo: 25 | 26 | GitHub repository: holbertonschool-low_level_programming 27 | Directory: 0x07-recursion 28 | File: 0-puts_recursion.c 29 | Check your code? 30 | Done? 31 | Who is done? Help! 32 | 1. Why is it so important to dream? Because, in my dreams we are together mandatory 33 | 34 | Write a function that prints a string, in reverse. 35 | 36 | Prototype: void _print_rev_recursion(char *s); 37 | julien@ubuntu:~/0x07. Recursion$ cat 1-main.c 38 | #include "holberton.h" 39 | 40 | /** 41 | * main - check the code for Holberton School students. 42 | * 43 | * Return: Always 0. 44 | */ 45 | int main(void) 46 | { 47 | _print_rev_recursion("\nColton Walker"); 48 | return (0); 49 | } 50 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra _putchar.c 1-main.c 1-print_rev_recursion.c -o 1-print_rev_recursion 51 | julien@ubuntu:~/0x07. Recursion$ ./1-print_rev_recursion 52 | reklaW notloC 53 | julien@ubuntu:~/0x07. Recursion$ 54 | Repo: 55 | 56 | GitHub repository: holbertonschool-low_level_programming 57 | Directory: 0x07-recursion 58 | File: 1-print_rev_recursion.c 59 | Check your code? 60 | Done? 61 | Who is done? Help! 62 | 2. Dreams feel real while we're in them. It's only when we wake up that we realize something was actually strange mandatory 63 | 64 | Write a function that returns the length of a string. 65 | 66 | Prototype: int _strlen_recursion(char *s); 67 | FYI: The standard library provides a similar function: strlen. Run man strlen to learn more. 68 | 69 | julien@ubuntu:~/0x07. Recursion$ cat 2-main.c 70 | #include "holberton.h" 71 | #include 72 | 73 | /** 74 | * main - check the code for Holberton School students. 75 | * 76 | * Return: Always 0. 77 | */ 78 | int main(void) 79 | { 80 | int n; 81 | 82 | n = _strlen_recursion("Corbin Coleman"); 83 | printf("%d\n", n); 84 | return (0); 85 | } 86 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra 2-main.c 2-strlen_recursion.c -o 2-strlen_recursion 87 | julien@ubuntu:~/0x07. Recursion$ ./2-strlen_recursion 88 | 14 89 | julien@ubuntu:~/0x07. Recursion$ 90 | Repo: 91 | 92 | GitHub repository: holbertonschool-low_level_programming 93 | Directory: 0x07-recursion 94 | File: 2-strlen_recursion.c 95 | Check your code? 96 | Done? 97 | Who is done? Help! 98 | 3. You mustn't be afraid to dream a little bigger, darling mandatory 99 | 100 | Write a function that returns the factorial of a given number. 101 | 102 | Prototype: int factorial(int n); 103 | If n is lower than 0, the function should return -1 to indicate an error 104 | Factorial of 0 is 1 105 | julien@ubuntu:~/0x07. Recursion$ cat 3-main.c 106 | #include "holberton.h" 107 | #include 108 | 109 | /** 110 | * main - check the code for Holberton School students. 111 | * 112 | * Return: Always 0. 113 | */ 114 | int main(void) 115 | { 116 | int r; 117 | 118 | r = factorial(1); 119 | printf("%d\n", r); 120 | r = factorial(5); 121 | printf("%d\n", r); 122 | r = factorial(10); 123 | printf("%d\n", r); 124 | r = factorial(-1024); 125 | printf("%d\n", r); 126 | return (0); 127 | } 128 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra 3-main.c 3-factorial.c -o 3-factorial 129 | julien@ubuntu:~/0x07. Recursion$ ./3-factorial 130 | 1 131 | 120 132 | 3628800 133 | -1 134 | julien@ubuntu:~/0x07. Recursion$ 135 | Repo: 136 | 137 | GitHub repository: holbertonschool-low_level_programming 138 | Directory: 0x07-recursion 139 | File: 3-factorial.c 140 | Check your code? 141 | Done? 142 | Who is done? Help! 143 | 4. Once an idea has taken hold of the brain it's almost impossible to eradicate mandatory 144 | 145 | Write a function that returns the value of x raised to the power of y. 146 | 147 | Prototype: int _pow_recursion(int x, int y); 148 | If y is lower than 0, the function should return -1 149 | FYI: The standard library provides a different function: pow. Run man pow to learn more. 150 | 151 | julien@ubuntu:~/0x07. Recursion$ cat 4-main.c 152 | #include "holberton.h" 153 | #include 154 | 155 | /** 156 | * main - check the code for Holberton School students. 157 | * 158 | * Return: Always 0. 159 | */ 160 | int main(void) 161 | { 162 | int r; 163 | 164 | r = _pow_recursion(1, 10); 165 | printf("%d\n", r); 166 | r = _pow_recursion(1024, 0); 167 | printf("%d\n", r); 168 | r = _pow_recursion(2, 16); 169 | printf("%d\n", r); 170 | r = _pow_recursion(5, 2); 171 | printf("%d\n", r); 172 | r = _pow_recursion(5, -2); 173 | printf("%d\n", r); 174 | r = _pow_recursion(-5, 3); 175 | printf("%d\n", r); 176 | return (0); 177 | } 178 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra 4-main.c 4-pow_recursion.c -o 4-pow 179 | julien@ubuntu:~/0x07. Recursion$ ./4-pow 180 | 1 181 | 1 182 | 65536 183 | 25 184 | -1 185 | -125 186 | julien@ubuntu:~/0x07. Recursion$ 187 | Repo: 188 | 189 | GitHub repository: holbertonschool-low_level_programming 190 | Directory: 0x07-recursion 191 | File: 4-pow_recursion.c 192 | Check your code? 193 | Done? 194 | Who is done? Help! 195 | 5. Your subconscious is looking for the dreamer mandatory 196 | 197 | Write a function that returns the natural square root of a number. 198 | 199 | Prototype: int _sqrt_recursion(int n); 200 | If n does not have a natural square root, the function should return -1 201 | FYI: The standard library provides a different function: sqrt. Run man sqrt to learn more. 202 | 203 | julien@ubuntu:~/0x07. Recursion$ cat 5-main.c 204 | #include "holberton.h" 205 | #include 206 | 207 | /** 208 | * main - check the code for Holberton School students. 209 | * 210 | * Return: Always 0. 211 | */ 212 | int main(void) 213 | { 214 | int r; 215 | 216 | r = _sqrt_recursion(1); 217 | printf("%d\n", r); 218 | r = _sqrt_recursion(1024); 219 | printf("%d\n", r); 220 | r = _sqrt_recursion(16); 221 | printf("%d\n", r); 222 | r = _sqrt_recursion(17); 223 | printf("%d\n", r); 224 | r = _sqrt_recursion(25); 225 | printf("%d\n", r); 226 | r = _sqrt_recursion(-1); 227 | printf("%d\n", r); 228 | return (0); 229 | } 230 | julien@ubuntu:~/0x07. gcc -Wall -pedantic -Werror -Wextra 5-main.c 5-sqrt_recursion.c -o 5-sqrt 231 | julien@ubuntu:~/0x07. Recursion$ ./5-sqrt 232 | 1 233 | 32 234 | 4 235 | -1 236 | 5 237 | -1 238 | julien@ubuntu:~/0x07. Recursion$ 239 | Repo: 240 | 241 | GitHub repository: holbertonschool-low_level_programming 242 | Directory: 0x07-recursion 243 | File: 5-sqrt_recursion.c 244 | Check your code? 245 | Done? 246 | Who is done? Help! 247 | 6. Inception. Is it possible? mandatory 248 | 249 | Write a function that returns 1 if a number is a prime number, 0 otherwise. 250 | 251 | Prototype: int is_prime_number(int n); 252 | julien@ubuntu:~/0x07. Recursion$ cat 6-main.c 253 | #include "holberton.h" 254 | #include 255 | 256 | /** 257 | * main - check the code for Holberton School students. 258 | * 259 | * Return: Always 0. 260 | */ 261 | int main(void) 262 | { 263 | int r; 264 | 265 | r = is_prime_number(1); 266 | printf("%d\n", r); 267 | r = is_prime_number(1024); 268 | printf("%d\n", r); 269 | r = is_prime_number(16); 270 | printf("%d\n", r); 271 | r = is_prime_number(17); 272 | printf("%d\n", r); 273 | r = is_prime_number(25); 274 | printf("%d\n", r); 275 | r = is_prime_number(-1); 276 | printf("%d\n", r); 277 | r = is_prime_number(113); 278 | printf("%d\n", r); 279 | r = is_prime_number(7919); 280 | printf("%d\n", r); 281 | return (0); 282 | } 283 | julien@ubuntu:~/0x07. Recursion$ gcc -Wall -pedantic -Werror -Wextra 6-main.c 6-is_prime_number.c -o 6-prime 284 | julien@ubuntu:~/0x07. Recursion$ ./6-prime 285 | 0 286 | 0 287 | 0 288 | 1 289 | 0 290 | 0 291 | 1 292 | 1 293 | julien@ubuntu:~/0x07. Recursion$ 294 | Repo: 295 | 296 | GitHub repository: holbertonschool-low_level_programming 297 | Directory: 0x07-recursion 298 | File: 6-is_prime_number.c 299 | Check your code? 300 | Done? 301 | Who is done? Help! 302 | 7. They say we only use a fraction of our brain's true potential. Now that's when we're awake. When we're asleep, we can do almost anything mandatory 303 | 304 | Write a function that returns 1 if a string is a palindrome and 0 if not. -------------------------------------------------------------------------------- /0x08-static_libraries/liball.a: -------------------------------------------------------------------------------- 1 | ! 2 | 0-isupper.c/ 1478289987 1000 1000 100664 153 ` 3 | #include 4 | 5 | /** 6 | * _isupper - writes the character c to stdout 7 | * @c: The character to print 8 | * Return: 0 9 | */ 10 | int _isupper(int c) 11 | { 12 | return 0; 13 | } 14 | 0-memset.c/ 1478290687 1000 1000 100664 231 ` 15 | #include 16 | 17 | /** 18 | * _memset - function that fills memory with a constant byte. 19 | * @b: b character 20 | * @s: s character 21 | * @n: int n 22 | * Return: On success 1. 23 | */ 24 | char *_memset(char *s, char b, unsigned int n) 25 | { 26 | return (s); 27 | } 28 | 29 | 0-strcat.c/ 1478290914 1000 1000 100664 218 ` 30 | #include 31 | /** 32 | * _strcat - function that concatenates two strings. 33 | * @src: parameter to a src 34 | * @dest: parameter to append 35 | * Return: Always 0. 36 | */ 37 | char *_strcat(char *dest, char *src) 38 | { 39 | return (dest); 40 | } 41 | 100-atoi.c/ 1478291896 1000 1000 100664 164 ` 42 | #include 43 | 44 | /** 45 | * _atoi - function that convert a string to an integer 46 | * @s: The character to print 47 | * Return: 0 48 | */ 49 | int _atoi(char *s) 50 | { 51 | return (0); 52 | } 53 | 1-isdigit.c/ 1478291123 1000 1000 100664 187 ` 54 | #include 55 | /** 56 | * _isdigit - function that checks for uppercase character. 57 | * @c: the int for the paramaters of my function 58 | * Return: 0 59 | */ 60 | int _isdigit(int c) 61 | { 62 | return (0); 63 | } 64 | 65 | 1-memcpy.c/ 1478291470 1000 1000 100664 301 ` 66 | #include 67 | /** 68 | * _memcpy - copies n bytes form the memory area src 69 | * to memory area dest 70 | * @src: source code to copy 71 | * @dest: paramater for destination to copy to 72 | * @n: how many bytes to copy 73 | * Return: dest; 74 | */ 75 | char *_memcpy(char *dest, char *src, unsigned int n) 76 | { 77 | return (dest); 78 | } 79 | 80 | 1-strncat.c/ 1478294192 1000 1000 100664 258 ` 81 | #include 82 | /** 83 | * _strncat - function that concatenates two strings 84 | * @dest: parmater for dest to append to 85 | * @src: parameter for src 86 | * @n: parameter for n 87 | * Return: Always 0. 88 | */ 89 | char *_strncat(char *dest, char *src, int n) 90 | { 91 | return (dest); 92 | } 93 | 2-strchr.c/ 1478294235 1000 1000 100664 309 ` 94 | #include 95 | /** 96 | * _strchr - returns a pointer to the first occurence of the 97 | * character c in the string s 98 | * @c: parameter for c to return 99 | * @s: string to search character 100 | * Return: pointer to first occurence of character c or null if not found 101 | */ 102 | char *_strchr(char *s, char c) 103 | { 104 | return (s); 105 | } 106 | 107 | 2-strlen.c/ 1478292386 1000 1000 100664 254 ` 108 | #include 109 | /** 110 | * _strlen - check the code for Holberton School students. 111 | * @s: declaration of *s and paramters for the function _strlen 112 | * Return: Always 0. 113 | */ 114 | int _strlen(char *s) 115 | { 116 | int c; 117 | 118 | for (c = 0; s[c] != 0; c++) 119 | { 120 | } 121 | return (c); 122 | } 123 | 2-strncpy.c/ 1478292502 1000 1000 100664 414 ` 124 | /** 125 | * _strncpy - check the code for Holberton School students. 126 | * @src: parameter to a src to copy 127 | * @dest: parameter for dest 128 | * @n: parameter for number of bytes 129 | * Return: Always 0. 130 | */ 131 | 132 | char *_strncpy(char *dest, char *src, int n) 133 | { 134 | int a = 0; 135 | int b = 0; 136 | 137 | while (a != n) 138 | { 139 | dest[b] = src[a]; 140 | b++; 141 | a++; 142 | if (src[a] == '\0') 143 | { 144 | break; 145 | } 146 | } 147 | while (b != n) 148 | dest[b++] = '\0'; 149 | return (dest); 150 | } 151 | 3-islower.c/ 1478292572 1000 1000 100664 257 ` 152 | #include "holberton.h" 153 | /** 154 | * _islower - function to check for lowercase character 155 | * @c: is the int that will use for the argument of the function 156 | * Return: 0 157 | */ 158 | int _islower(int c) 159 | { 160 | if (c >= 'a' && c <= 'z') 161 | { 162 | return (1); 163 | } 164 | else 165 | return (0); 166 | } 167 | 168 | 3-puts.c/ 1478292704 1000 1000 100664 284 ` 169 | #include "holberton.h" 170 | /** 171 | * _puts - function that prints a string, followed by a new line 172 | * @s: declaration of *str and paramters for the function _puts 173 | * Return: Always 0. 174 | */ 175 | void _puts(char *s) 176 | { 177 | int c; 178 | 179 | for (c = 0; s[c] != 0; c++) 180 | { 181 | _putchar(s[c]); 182 | } 183 | _putchar('\n'); 184 | } 185 | 3-strcmp.c/ 1478292970 1000 1000 100664 356 ` 186 | #include "holberton.h" 187 | /** 188 | * _strcmp - function that compares two strings 189 | * @s2: paramater for string 2 190 | * @s1: paramater for string 1 191 | * Return: Always 0. 192 | */ 193 | int _strcmp(char *s1, char *s2) 194 | { 195 | int a = 0; 196 | 197 | while (s1[a] != '\0') 198 | { 199 | if (s1[a] < s2[a]) 200 | return (s1[a] - s2[a]); 201 | if (s1[a] > s2[a]) 202 | return (s1[a] - s2[a]); 203 | a++; 204 | } 205 | return (0); 206 | } 207 | 3-strspn.c/ 1478293136 1000 1000 100664 474 ` 208 | #include "holberton.h" 209 | #include 210 | 211 | /** 212 | * _strspn - returns number of bytes in the initial sengment s 213 | * @s: for the count action 214 | * @accept: parameter for char 215 | * Return: number of bytes; 216 | */ 217 | 218 | unsigned int _strspn(char *s, char *accept) 219 | { 220 | unsigned int num; 221 | int i, j, t; 222 | 223 | i = 0; 224 | while (s[i] != '\0') 225 | { 226 | t = 0; 227 | for (j = 0; accept[j] != '\0'; j++) 228 | { 229 | if (s[i] == accept[j]) 230 | t = 1; 231 | } 232 | j = 0; 233 | if (t == 0) 234 | break; 235 | num++; 236 | i++; 237 | } 238 | return (i); 239 | } 240 | 4-isalpha.c/ 1478293223 1000 1000 100664 301 ` 241 | #include "holberton.h" 242 | /** 243 | * _isalpha - function to check if c is a letter, lowercase or uppercase 244 | * @c: is the int that will use for the argument of the function 245 | * Return: 0 246 | */ 247 | int _isalpha(int c) 248 | { 249 | if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) 250 | { 251 | return (1); 252 | } 253 | else 254 | return (0); 255 | } 256 | 257 | 4-strpbrk.c/ 1478293345 1000 1000 100664 468 ` 258 | #include "holberton.h" 259 | 260 | /** 261 | * _strpbrk - locates the first occurrence in the string s of any 262 | * of the bytes in the string accept 263 | * @s: for the char 264 | * @accept: paramter for accept 265 | * Return: pointer to the byte s 266 | */ 267 | 268 | char *_strpbrk(char *s, char *accept) 269 | { 270 | int i, t, j; 271 | 272 | i = 0; 273 | while (s[i] != '\0') 274 | { 275 | t = 0; 276 | for (j = 0; accept[j] != '\0'; j++) 277 | { 278 | if (s[i] == accept[j]) 279 | t = 1; 280 | } 281 | j = 0; 282 | if (t == 1) 283 | return (s + i); 284 | i++; 285 | } 286 | return (0); 287 | } 288 | 5-strstr.c/ 1478293425 1000 1000 100664 617 ` 289 | #include "holberton.h" 290 | #include 291 | /** 292 | * _strstr - finds the first occurence of the substring needle 293 | * in the string haystack 294 | * @haystack: paramter for haystack 295 | * @needle: paramter for needle 296 | * Return: pointer to the beginning of the located substring 297 | */ 298 | char *_strstr(char *haystack, char *needle) 299 | { 300 | 301 | while (*haystack != '\0') 302 | { 303 | char *beginning = haystack; 304 | char *pattern = needle; 305 | 306 | while (*pattern == *haystack && *pattern != '\0' 307 | && *haystack != '\0') 308 | { 309 | haystack++; 310 | pattern++; 311 | } 312 | if (*pattern == '\0') 313 | return (beginning); 314 | haystack = beginning + 1; 315 | } 316 | return ('\0'); 317 | } 318 | 319 | 6-abs.c/ 1478294274 1000 1000 100664 282 ` 320 | #include "holberton.h" 321 | #include 322 | /** 323 | * _abs - function that computes the absolute value of an integer 324 | * @n: is the int that will use for the argument of the function 325 | * Return: 0 326 | */ 327 | int _abs(int n) 328 | { 329 | if (n > 0 || n == 0) 330 | { 331 | return (n); 332 | } 333 | else 334 | return (n * -1); 335 | } 336 | 9-strcpy.c/ 1478293854 1000 1000 100664 216 ` 337 | #include 338 | /** 339 | * _strcpy - function that copies the string pointed to by src 340 | * @dest: dest parameter 341 | * @src: src paramter 342 | * Return: dest char 343 | */ 344 | char *_strcpy(char *dest, char *src) 345 | { 346 | return (dest); 347 | } 348 | main.c/ 1478294436 1000 1000 100664 147 ` 349 | #include "holberton.h" 350 | 351 | int main(void) 352 | { 353 | _puts("\"At the end of the day, my goal was to be the best hacker\"\n\t- Kevin Mitnick"); 354 | return (0); 355 | } 356 | 357 | _putchar.c/ 1478289691 1000 1000 100664 247 ` 358 | #include 359 | 360 | /** 361 | * _putchar - writes the character c to stdout 362 | * @c: The character to print 363 | * 364 | * Return: On success 1. 365 | * On error, -1 is returned, and errno is set appropriately. 366 | */ 367 | int _putchar(char c) 368 | { 369 | return (write(1, &c, 1)); 370 | } 371 | 372 | -------------------------------------------------------------------------------- /0x06-pointers_arrays_strings/README.md: -------------------------------------------------------------------------------- 1 | Write a function that fills memory with a constant byte. 2 | 3 | Prototype: char *_memset(char *s, char b, unsigned int n); 4 | The _memset() function fills the first n bytes of the memory area pointed to by s with the constant byte b 5 | Returns a pointer to the memory area s 6 | FYI: The standard library provides a similar function: memset. Run man memset to learn more. 7 | 8 | julien@ubuntu:~/0x06$ cat 0-main.c 9 | #include "holberton.h" 10 | #include 11 | 12 | /** 13 | * simple_print_buffer - prints buffer in hexa 14 | * @buffer: the address of memory to print 15 | * @size: the size of the memory to print 16 | * 17 | * Return: Nothing. 18 | */ 19 | void simple_print_buffer(char *buffer, unsigned int size) 20 | { 21 | unsigned int i; 22 | 23 | i = 0; 24 | while (i < size) 25 | { 26 | if (i % 10) 27 | { 28 | printf(" "); 29 | } 30 | if (!(i % 10) && i) 31 | { 32 | printf("\n"); 33 | } 34 | printf("0x%02x", buffer[i]); 35 | i++; 36 | } 37 | printf("\n"); 38 | } 39 | 40 | /** 41 | * main - check the code for Holberton School students. 42 | * 43 | * Return: Always 0. 44 | */ 45 | int main(void) 46 | { 47 | char buffer[98] = {0x00}; 48 | 49 | simple_print_buffer(buffer, 98); 50 | _memset(buffer, 0x01, 95); 51 | printf("-------------------------------------------------\n"); 52 | simple_print_buffer(buffer, 98); 53 | return (0); 54 | } 55 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 0-main.c 0-memset.c -o 0-memset 56 | julien@ubuntu:~/0x06$ ./0-memset 57 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 58 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 59 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 60 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 61 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 62 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 63 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 64 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 65 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 66 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 67 | ------------------------------------------------- 68 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 69 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 70 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 71 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 72 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 73 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 74 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 75 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 76 | 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 77 | 0x01 0x01 0x01 0x01 0x01 0x00 0x00 0x00 78 | julien@ubuntu:~/0x06$ 79 | Repo: 80 | 81 | GitHub repository: holbertonschool-low_level_programming 82 | Directory: 0x06-pointers_arrays_strings 83 | File: 0-memset.c 84 | Check your code? 85 | Done? 86 | Who is done? Help! 87 | 1. memcpy mandatory 88 | 89 | Write a function that copies memory area. 90 | 91 | Prototype: char *_memcpy(char *dest, char *src, unsigned int n); 92 | The _memcpy() function copies n bytes from memory area src to memory area dest 93 | Returns a pointer to dest 94 | FYI: The standard library provides a similar function: memcpy. Run man memcpy to learn more. 95 | 96 | julien@ubuntu:~/0x06$ cat 1-main.c 97 | #include "holberton.h" 98 | #include 99 | 100 | /** 101 | * simple_print_buffer - prints buffer in hexa 102 | * @buffer: the address of memory to print 103 | * @size: the size of the memory to print 104 | * 105 | * Return: Nothing. 106 | */ 107 | void simple_print_buffer(char *buffer, unsigned int size) 108 | { 109 | unsigned int i; 110 | 111 | i = 0; 112 | while (i < size) 113 | { 114 | if (i % 10) 115 | { 116 | printf(" "); 117 | } 118 | if (!(i % 10) && i) 119 | { 120 | printf("\n"); 121 | } 122 | printf("0x%02x", buffer[i]); 123 | i++; 124 | } 125 | printf("\n"); 126 | } 127 | 128 | /** 129 | * main - check the code for Holberton School students. 130 | * 131 | * Return: Always 0. 132 | */ 133 | int main(void) 134 | { 135 | char buffer[98] = {0}; 136 | char buffer2[98] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; 137 | 138 | simple_print_buffer(buffer, 98); 139 | _memcpy(buffer + 50, buffer2, 10); 140 | printf("-------------------------------------------------\n"); 141 | simple_print_buffer(buffer, 98); 142 | return (0); 143 | } 144 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 1-main.c 1-memcpy.c -o 1-memcpy 145 | julien@ubuntu:~/0x06$ ./1-memcpy 146 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 147 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 148 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 149 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 150 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 151 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 152 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 153 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 154 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 155 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 156 | ------------------------------------------------- 157 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 158 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 159 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 160 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 161 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 162 | 0x01 0x02 0x03 0x04 0x05 0x06 0x07 0x08 0x09 0x0a 163 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 164 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 165 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 166 | 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 167 | julien@ubuntu:~/0x06$ 168 | Repo: 169 | 170 | GitHub repository: holbertonschool-low_level_programming 171 | Directory: 0x06-pointers_arrays_strings 172 | File: 1-memcpy.c 173 | Check your code? 174 | Done? 175 | Who is done? Help! 176 | 2. strchr mandatory 177 | 178 | Write a function that locates a character in a string. 179 | 180 | Prototype: char *_strchr(char *s, char c); 181 | Returns a pointer to the first occurrence of the character c in the string s, or NULL if the character is not found 182 | FYI: The standard library provides a similar function: strchr. Run man strchr to learn more. 183 | 184 | julien@ubuntu:~/0x06$ cat 2-main.c 185 | #include "holberton.h" 186 | #include 187 | 188 | /** 189 | * main - check the code for Holberton School students. 190 | * 191 | * Return: Always 0. 192 | */ 193 | int main(void) 194 | { 195 | char *s = "hello"; 196 | char *f; 197 | 198 | f = _strchr(s, 'l'); 199 | printf("%s\n", f); 200 | return (0); 201 | } 202 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 2-main.c 2-strchr.c -o 2-strchr 203 | julien@ubuntu:~/0x06$ ./2-strchr 204 | llo 205 | julien@ubuntu:~/0x06$ 206 | Repo: 207 | 208 | GitHub repository: holbertonschool-low_level_programming 209 | Directory: 0x06-pointers_arrays_strings 210 | File: 2-strchr.c 211 | Check your code? 212 | Done? 213 | Who is done? Help! 214 | 3. strspn mandatory 215 | 216 | Write a function that gets the length of a prefix substring. 217 | 218 | Prototype: unsigned int _strspn(char *s, char *accept); 219 | Returns the number of bytes in the initial segment of s which consist only of bytes from accept 220 | FYI: The standard library provides a similar function: strspn. Run man strspn to learn more. 221 | 222 | julien@ubuntu:~/0x06$ cat 3-main.c 223 | #include "holberton.h" 224 | #include 225 | 226 | /** 227 | * main - check the code for Holberton School students. 228 | * 229 | * Return: Always 0. 230 | */ 231 | int main(void) 232 | { 233 | char *s = "hello, world"; 234 | char *f = "oleh"; 235 | unsigned int n; 236 | 237 | n = _strspn(s, f); 238 | printf("%u\n", n); 239 | return (0); 240 | } 241 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 3-main.c 3-strspn.c -o 3-strspn 242 | julien@ubuntu:~/0x06$ ./3-strspn 243 | 5 244 | julien@ubuntu:~/0x06$ 245 | Repo: 246 | 247 | GitHub repository: holbertonschool-low_level_programming 248 | Directory: 0x06-pointers_arrays_strings 249 | File: 3-strspn.c 250 | Check your code? 251 | Done? 252 | Who is done? Help! 253 | 4. strpbrk mandatory 254 | 255 | Write a function that searches a string for any of a set of bytes. 256 | 257 | Prototype: char *_strpbrk(char *s, char *accept); 258 | The _strpbrk() function locates the first occurrence in the string s of any of the bytes in the string accept 259 | Returns a pointer to the byte in s that matches one of the bytes in accept, or NULL if no such byte is found 260 | FYI: The standard library provides a similar function: strpbrk. Run man strpbrk to learn more. 261 | 262 | julien@ubuntu:~/0x06$ cat 4-main.c 263 | #include "holberton.h" 264 | #include 265 | 266 | /** 267 | * main - check the code for Holberton School students. 268 | * 269 | * Return: Always 0. 270 | */ 271 | int main(void) 272 | { 273 | char *s = "hello, world"; 274 | char *f = "world"; 275 | char *t; 276 | 277 | t = _strpbrk(s, f); 278 | printf("%s\n", t); 279 | return (0); 280 | } 281 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 4-main.c 4-strpbrk.c -o 4-strpbrk 282 | julien@ubuntu:~/0x06$ ./4-strpbrk 283 | llo, world 284 | julien@ubuntu:~/0x06$ 285 | Repo: 286 | 287 | GitHub repository: holbertonschool-low_level_programming 288 | Directory: 0x06-pointers_arrays_strings 289 | File: 4-strpbrk.c 290 | Check your code? 291 | Done? 292 | Who is done? Help! 293 | 5. strstr mandatory 294 | 295 | Write a function that locates a substring. 296 | 297 | Prototype: char *_strstr(char *haystack, char *needle); 298 | The _strstr() function finds the first occurrence of the substring needle in the string haystack. The terminating null bytes (\0) are not compared 299 | Returns a pointer to the beginning of the located substring, or NULL if the substring is not found. 300 | FYI: The standard library provides a similar function: strstr. Run man strstr to learn more. 301 | 302 | julien@ubuntu:~/0x06$ cat 5-main.c 303 | #include "holberton.h" 304 | #include 305 | 306 | /** 307 | * main - check the code for Holberton School students. 308 | * 309 | * Return: Always 0. 310 | */ 311 | int main(void) 312 | { 313 | char *s = "hello, world"; 314 | char *f = "world"; 315 | char *t; 316 | 317 | t = _strstr(s, f); 318 | printf("%s\n", t); 319 | return (0); 320 | } 321 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 5-main.c 5-strstr.c -o 5-strstr 322 | julien@ubuntu:~/0x06$ ./5-strstr 323 | world 324 | julien@ubuntu:~/0x06$ 325 | 326 | Repo: 327 | 328 | GitHub repository: holbertonschool-low_level_programming 329 | Directory: 0x06-pointers_arrays_strings 330 | File: 5-strstr.c 331 | Check your code? 332 | Done? 333 | Who is done? Help! 334 | 6. Chess is mental torture mandatory 335 | 336 | Write a function that prints the chessboard. 337 | 338 | Prototype: void print_chessboard(char (*a)[8]); 339 | julien@ubuntu:~/0x06$ cat 7-main.c 340 | #include "holberton.h" 341 | #include 342 | 343 | /** 344 | * main - check the code for Holberton School students. 345 | * 346 | * Return: Always 0. 347 | */ 348 | int main(void) 349 | { 350 | char board[8][8] = { 351 | {'r', 'k', 'b', 'q', 'k', 'b', 'k', 'r'}, 352 | {'p', 'p', 'p', 'p', 'p', 'p', 'p', 'p'}, 353 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 354 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 355 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 356 | {' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '}, 357 | {'P', 'P', 'P', 'P', 'P', 'P', 'P', 'P'}, 358 | {'R', 'K', 'B', 'Q', 'K', 'B', 'K', 'R'}, 359 | }; 360 | print_chessboard(board); 361 | return (0); 362 | } 363 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra _putchar.c 7-main.c 7-print_chessboard.c -o 7-print_chessboard 364 | julien@ubuntu:~/0x06$ ./7-print_chessboard 365 | rkbqkbkr 366 | pppppppp 367 | 368 | 369 | 370 | 371 | PPPPPPPP 372 | RKBQKBKR 373 | julien@ubuntu:~/c/curriculum_by_julien/holbertonschool-low_level_programming/0x06$ 374 | Repo: 375 | 376 | GitHub repository: holbertonschool-low_level_programming 377 | Directory: 0x06-pointers_arrays_strings 378 | File: 7-print_chessboard.c 379 | Check your code? 380 | Done? 381 | Who is done? Help! 382 | 7. The line of life is a ragged diagonal between duty and desire mandatory 383 | 384 | Write a function that prints the sum of the two diagonals of a square matrix of integers. 385 | 386 | Prototype: void print_diagsums(int *a, int size); 387 | Format: see example 388 | You are allowed to use the standard library 389 | Note that in the following example we are casting an int[][] into an int*. This is not something you should do. The goal here is to make sure you understand how an array of array is stored in memory. 390 | 391 | julien@ubuntu:~/0x06$ cat 8-main.c 392 | #include "holberton.h" 393 | #include 394 | 395 | /** 396 | * main - check the code for Holberton School students. 397 | * 398 | * Return: Always 0. 399 | */ 400 | int main(void) 401 | { 402 | int c3[3][3] = { 403 | {0, 1, 5}, 404 | {10, 11, 12}, 405 | {1000, 101, 102}, 406 | }; 407 | int c5[5][5] = { 408 | {0, 1, 5, 12124, 1234}, 409 | {10, 11, 12, 123521, 12512}, 410 | {1000, 101, 102, 12545, 214543435}, 411 | {100, 1012451, 11102, 12545, 214543435}, 412 | {10, 12401, 10452, 11542545, 1214543435}, 413 | }; 414 | print_diagsums((int *)c3, 3); 415 | print_diagsums((int *)c5, 5); 416 | return (0); 417 | } 418 | julien@ubuntu:~/0x06$ gcc -Wall -pedantic -Werror -Wextra 8-main.c 8-print_diagsums.c -o 8-print_diagsums 419 | julien@ubuntu:~/0x06$ ./8-print_diagsums 420 | 113, 1016 421 | 1214556093, 1137318 422 | julien@ubuntu:~/0x06$ 423 | Repo: 424 | 425 | GitHub repository: holbertonschool-low_level_programming 426 | Directory: 0x06-pointers_arrays_strings 427 | File: 8-print_diagsums.c 428 | Check your code? 429 | Done? 430 | Who is done? Help! 431 | 8. Double pointer, double fun mandatory 432 | 433 | Write a function that sets the value of a pointer to a char. -------------------------------------------------------------------------------- /0x00-hello_world/c: -------------------------------------------------------------------------------- 1 | # 1 "main.c" 2 | # 1 "" 3 | # 1 "" 4 | # 1 "/usr/include/stdc-predef.h" 1 3 4 5 | # 1 "" 2 6 | # 1 "main.c" 7 | # 1 "/usr/include/stdio.h" 1 3 4 8 | # 27 "/usr/include/stdio.h" 3 4 9 | # 1 "/usr/include/features.h" 1 3 4 10 | # 374 "/usr/include/features.h" 3 4 11 | # 1 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 1 3 4 12 | # 385 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 3 4 13 | # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 14 | # 386 "/usr/include/x86_64-linux-gnu/sys/cdefs.h" 2 3 4 15 | # 375 "/usr/include/features.h" 2 3 4 16 | # 398 "/usr/include/features.h" 3 4 17 | # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 1 3 4 18 | # 10 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 3 4 19 | # 1 "/usr/include/x86_64-linux-gnu/gnu/stubs-64.h" 1 3 4 20 | # 11 "/usr/include/x86_64-linux-gnu/gnu/stubs.h" 2 3 4 21 | # 399 "/usr/include/features.h" 2 3 4 22 | # 28 "/usr/include/stdio.h" 2 3 4 23 | 24 | 25 | 26 | 27 | 28 | # 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4 29 | # 212 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 3 4 30 | typedef long unsigned int size_t; 31 | # 34 "/usr/include/stdio.h" 2 3 4 32 | 33 | # 1 "/usr/include/x86_64-linux-gnu/bits/types.h" 1 3 4 34 | # 27 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 35 | # 1 "/usr/include/x86_64-linux-gnu/bits/wordsize.h" 1 3 4 36 | # 28 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 37 | 38 | 39 | typedef unsigned char __u_char; 40 | typedef unsigned short int __u_short; 41 | typedef unsigned int __u_int; 42 | typedef unsigned long int __u_long; 43 | 44 | 45 | typedef signed char __int8_t; 46 | typedef unsigned char __uint8_t; 47 | typedef signed short int __int16_t; 48 | typedef unsigned short int __uint16_t; 49 | typedef signed int __int32_t; 50 | typedef unsigned int __uint32_t; 51 | 52 | typedef signed long int __int64_t; 53 | typedef unsigned long int __uint64_t; 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | typedef long int __quad_t; 62 | typedef unsigned long int __u_quad_t; 63 | # 121 "/usr/include/x86_64-linux-gnu/bits/types.h" 3 4 64 | # 1 "/usr/include/x86_64-linux-gnu/bits/typesizes.h" 1 3 4 65 | # 122 "/usr/include/x86_64-linux-gnu/bits/types.h" 2 3 4 66 | 67 | 68 | typedef unsigned long int __dev_t; 69 | typedef unsigned int __uid_t; 70 | typedef unsigned int __gid_t; 71 | typedef unsigned long int __ino_t; 72 | typedef unsigned long int __ino64_t; 73 | typedef unsigned int __mode_t; 74 | typedef unsigned long int __nlink_t; 75 | typedef long int __off_t; 76 | typedef long int __off64_t; 77 | typedef int __pid_t; 78 | typedef struct { int __val[2]; } __fsid_t; 79 | typedef long int __clock_t; 80 | typedef unsigned long int __rlim_t; 81 | typedef unsigned long int __rlim64_t; 82 | typedef unsigned int __id_t; 83 | typedef long int __time_t; 84 | typedef unsigned int __useconds_t; 85 | typedef long int __suseconds_t; 86 | 87 | typedef int __daddr_t; 88 | typedef int __key_t; 89 | 90 | 91 | typedef int __clockid_t; 92 | 93 | 94 | typedef void * __timer_t; 95 | 96 | 97 | typedef long int __blksize_t; 98 | 99 | 100 | 101 | 102 | typedef long int __blkcnt_t; 103 | typedef long int __blkcnt64_t; 104 | 105 | 106 | typedef unsigned long int __fsblkcnt_t; 107 | typedef unsigned long int __fsblkcnt64_t; 108 | 109 | 110 | typedef unsigned long int __fsfilcnt_t; 111 | typedef unsigned long int __fsfilcnt64_t; 112 | 113 | 114 | typedef long int __fsword_t; 115 | 116 | typedef long int __ssize_t; 117 | 118 | 119 | typedef long int __syscall_slong_t; 120 | 121 | typedef unsigned long int __syscall_ulong_t; 122 | 123 | 124 | 125 | typedef __off64_t __loff_t; 126 | typedef __quad_t *__qaddr_t; 127 | typedef char *__caddr_t; 128 | 129 | 130 | typedef long int __intptr_t; 131 | 132 | 133 | typedef unsigned int __socklen_t; 134 | # 36 "/usr/include/stdio.h" 2 3 4 135 | # 44 "/usr/include/stdio.h" 3 4 136 | struct _IO_FILE; 137 | 138 | 139 | 140 | typedef struct _IO_FILE FILE; 141 | 142 | 143 | 144 | 145 | 146 | # 64 "/usr/include/stdio.h" 3 4 147 | typedef struct _IO_FILE __FILE; 148 | # 74 "/usr/include/stdio.h" 3 4 149 | # 1 "/usr/include/libio.h" 1 3 4 150 | # 31 "/usr/include/libio.h" 3 4 151 | # 1 "/usr/include/_G_config.h" 1 3 4 152 | # 15 "/usr/include/_G_config.h" 3 4 153 | # 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h" 1 3 4 154 | # 16 "/usr/include/_G_config.h" 2 3 4 155 | 156 | 157 | 158 | 159 | # 1 "/usr/include/wchar.h" 1 3 4 160 | # 82 "/usr/include/wchar.h" 3 4 161 | typedef struct 162 | { 163 | int __count; 164 | union 165 | { 166 | 167 | unsigned int __wch; 168 | 169 | 170 | 171 | char __wchb[4]; 172 | } __value; 173 | } __mbstate_t; 174 | # 21 "/usr/include/_G_config.h" 2 3 4 175 | typedef struct 176 | { 177 | __off_t __pos; 178 | __mbstate_t __state; 179 | } _G_fpos_t; 180 | typedef struct 181 | { 182 | __off64_t __pos; 183 | __mbstate_t __state; 184 | } _G_fpos64_t; 185 | # 32 "/usr/include/libio.h" 2 3 4 186 | # 49 "/usr/include/libio.h" 3 4 187 | # 1 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h" 1 3 4 188 | # 40 "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h" 3 4 189 | typedef __builtin_va_list __gnuc_va_list; 190 | # 50 "/usr/include/libio.h" 2 3 4 191 | # 144 "/usr/include/libio.h" 3 4 192 | struct _IO_jump_t; struct _IO_FILE; 193 | # 154 "/usr/include/libio.h" 3 4 194 | typedef void _IO_lock_t; 195 | 196 | 197 | 198 | 199 | 200 | struct _IO_marker { 201 | struct _IO_marker *_next; 202 | struct _IO_FILE *_sbuf; 203 | 204 | 205 | 206 | int _pos; 207 | # 177 "/usr/include/libio.h" 3 4 208 | }; 209 | 210 | 211 | enum __codecvt_result 212 | { 213 | __codecvt_ok, 214 | __codecvt_partial, 215 | __codecvt_error, 216 | __codecvt_noconv 217 | }; 218 | # 245 "/usr/include/libio.h" 3 4 219 | struct _IO_FILE { 220 | int _flags; 221 | 222 | 223 | 224 | 225 | char* _IO_read_ptr; 226 | char* _IO_read_end; 227 | char* _IO_read_base; 228 | char* _IO_write_base; 229 | char* _IO_write_ptr; 230 | char* _IO_write_end; 231 | char* _IO_buf_base; 232 | char* _IO_buf_end; 233 | 234 | char *_IO_save_base; 235 | char *_IO_backup_base; 236 | char *_IO_save_end; 237 | 238 | struct _IO_marker *_markers; 239 | 240 | struct _IO_FILE *_chain; 241 | 242 | int _fileno; 243 | 244 | 245 | 246 | int _flags2; 247 | 248 | __off_t _old_offset; 249 | 250 | 251 | 252 | unsigned short _cur_column; 253 | signed char _vtable_offset; 254 | char _shortbuf[1]; 255 | 256 | 257 | 258 | _IO_lock_t *_lock; 259 | # 293 "/usr/include/libio.h" 3 4 260 | __off64_t _offset; 261 | # 302 "/usr/include/libio.h" 3 4 262 | void *__pad1; 263 | void *__pad2; 264 | void *__pad3; 265 | void *__pad4; 266 | size_t __pad5; 267 | 268 | int _mode; 269 | 270 | char _unused2[15 * sizeof (int) - 4 * sizeof (void *) - sizeof (size_t)]; 271 | 272 | }; 273 | 274 | 275 | typedef struct _IO_FILE _IO_FILE; 276 | 277 | 278 | struct _IO_FILE_plus; 279 | 280 | extern struct _IO_FILE_plus _IO_2_1_stdin_; 281 | extern struct _IO_FILE_plus _IO_2_1_stdout_; 282 | extern struct _IO_FILE_plus _IO_2_1_stderr_; 283 | # 338 "/usr/include/libio.h" 3 4 284 | typedef __ssize_t __io_read_fn (void *__cookie, char *__buf, size_t __nbytes); 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | typedef __ssize_t __io_write_fn (void *__cookie, const char *__buf, 293 | size_t __n); 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | typedef int __io_seek_fn (void *__cookie, __off64_t *__pos, int __w); 302 | 303 | 304 | typedef int __io_close_fn (void *__cookie); 305 | # 390 "/usr/include/libio.h" 3 4 306 | extern int __underflow (_IO_FILE *); 307 | extern int __uflow (_IO_FILE *); 308 | extern int __overflow (_IO_FILE *, int); 309 | # 434 "/usr/include/libio.h" 3 4 310 | extern int _IO_getc (_IO_FILE *__fp); 311 | extern int _IO_putc (int __c, _IO_FILE *__fp); 312 | extern int _IO_feof (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__)); 313 | extern int _IO_ferror (_IO_FILE *__fp) __attribute__ ((__nothrow__ , __leaf__)); 314 | 315 | extern int _IO_peekc_locked (_IO_FILE *__fp); 316 | 317 | 318 | 319 | 320 | 321 | extern void _IO_flockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__)); 322 | extern void _IO_funlockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__)); 323 | extern int _IO_ftrylockfile (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__)); 324 | # 464 "/usr/include/libio.h" 3 4 325 | extern int _IO_vfscanf (_IO_FILE * __restrict, const char * __restrict, 326 | __gnuc_va_list, int *__restrict); 327 | extern int _IO_vfprintf (_IO_FILE *__restrict, const char *__restrict, 328 | __gnuc_va_list); 329 | extern __ssize_t _IO_padn (_IO_FILE *, int, __ssize_t); 330 | extern size_t _IO_sgetn (_IO_FILE *, void *, size_t); 331 | 332 | extern __off64_t _IO_seekoff (_IO_FILE *, __off64_t, int, int); 333 | extern __off64_t _IO_seekpos (_IO_FILE *, __off64_t, int); 334 | 335 | extern void _IO_free_backup_area (_IO_FILE *) __attribute__ ((__nothrow__ , __leaf__)); 336 | # 75 "/usr/include/stdio.h" 2 3 4 337 | 338 | 339 | 340 | 341 | typedef __gnuc_va_list va_list; 342 | # 90 "/usr/include/stdio.h" 3 4 343 | typedef __off_t off_t; 344 | # 102 "/usr/include/stdio.h" 3 4 345 | typedef __ssize_t ssize_t; 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | typedef _G_fpos_t fpos_t; 354 | 355 | 356 | 357 | 358 | # 164 "/usr/include/stdio.h" 3 4 359 | # 1 "/usr/include/x86_64-linux-gnu/bits/stdio_lim.h" 1 3 4 360 | # 165 "/usr/include/stdio.h" 2 3 4 361 | 362 | 363 | 364 | extern struct _IO_FILE *stdin; 365 | extern struct _IO_FILE *stdout; 366 | extern struct _IO_FILE *stderr; 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | extern int remove (const char *__filename) __attribute__ ((__nothrow__ , __leaf__)); 375 | 376 | extern int rename (const char *__old, const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 377 | 378 | 379 | 380 | 381 | extern int renameat (int __oldfd, const char *__old, int __newfd, 382 | const char *__new) __attribute__ ((__nothrow__ , __leaf__)); 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | extern FILE *tmpfile (void) ; 392 | # 209 "/usr/include/stdio.h" 3 4 393 | extern char *tmpnam (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 394 | 395 | 396 | 397 | 398 | 399 | extern char *tmpnam_r (char *__s) __attribute__ ((__nothrow__ , __leaf__)) ; 400 | # 227 "/usr/include/stdio.h" 3 4 401 | extern char *tempnam (const char *__dir, const char *__pfx) 402 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__malloc__)) ; 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | extern int fclose (FILE *__stream); 412 | 413 | 414 | 415 | 416 | extern int fflush (FILE *__stream); 417 | 418 | # 252 "/usr/include/stdio.h" 3 4 419 | extern int fflush_unlocked (FILE *__stream); 420 | # 266 "/usr/include/stdio.h" 3 4 421 | 422 | 423 | 424 | 425 | 426 | 427 | extern FILE *fopen (const char *__restrict __filename, 428 | const char *__restrict __modes) ; 429 | 430 | 431 | 432 | 433 | extern FILE *freopen (const char *__restrict __filename, 434 | const char *__restrict __modes, 435 | FILE *__restrict __stream) ; 436 | # 295 "/usr/include/stdio.h" 3 4 437 | 438 | # 306 "/usr/include/stdio.h" 3 4 439 | extern FILE *fdopen (int __fd, const char *__modes) __attribute__ ((__nothrow__ , __leaf__)) ; 440 | # 319 "/usr/include/stdio.h" 3 4 441 | extern FILE *fmemopen (void *__s, size_t __len, const char *__modes) 442 | __attribute__ ((__nothrow__ , __leaf__)) ; 443 | 444 | 445 | 446 | 447 | extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __attribute__ ((__nothrow__ , __leaf__)) ; 448 | 449 | 450 | 451 | 452 | 453 | 454 | extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __attribute__ ((__nothrow__ , __leaf__)); 455 | 456 | 457 | 458 | extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf, 459 | int __modes, size_t __n) __attribute__ ((__nothrow__ , __leaf__)); 460 | 461 | 462 | 463 | 464 | 465 | extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf, 466 | size_t __size) __attribute__ ((__nothrow__ , __leaf__)); 467 | 468 | 469 | extern void setlinebuf (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | extern int fprintf (FILE *__restrict __stream, 479 | const char *__restrict __format, ...); 480 | 481 | 482 | 483 | 484 | extern int printf (const char *__restrict __format, ...); 485 | 486 | extern int sprintf (char *__restrict __s, 487 | const char *__restrict __format, ...) __attribute__ ((__nothrow__)); 488 | 489 | 490 | 491 | 492 | 493 | extern int vfprintf (FILE *__restrict __s, const char *__restrict __format, 494 | __gnuc_va_list __arg); 495 | 496 | 497 | 498 | 499 | extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg); 500 | 501 | extern int vsprintf (char *__restrict __s, const char *__restrict __format, 502 | __gnuc_va_list __arg) __attribute__ ((__nothrow__)); 503 | 504 | 505 | 506 | 507 | 508 | extern int snprintf (char *__restrict __s, size_t __maxlen, 509 | const char *__restrict __format, ...) 510 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 4))); 511 | 512 | extern int vsnprintf (char *__restrict __s, size_t __maxlen, 513 | const char *__restrict __format, __gnuc_va_list __arg) 514 | __attribute__ ((__nothrow__)) __attribute__ ((__format__ (__printf__, 3, 0))); 515 | 516 | # 412 "/usr/include/stdio.h" 3 4 517 | extern int vdprintf (int __fd, const char *__restrict __fmt, 518 | __gnuc_va_list __arg) 519 | __attribute__ ((__format__ (__printf__, 2, 0))); 520 | extern int dprintf (int __fd, const char *__restrict __fmt, ...) 521 | __attribute__ ((__format__ (__printf__, 2, 3))); 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | extern int fscanf (FILE *__restrict __stream, 531 | const char *__restrict __format, ...) ; 532 | 533 | 534 | 535 | 536 | extern int scanf (const char *__restrict __format, ...) ; 537 | 538 | extern int sscanf (const char *__restrict __s, 539 | const char *__restrict __format, ...) __attribute__ ((__nothrow__ , __leaf__)); 540 | # 443 "/usr/include/stdio.h" 3 4 541 | extern int fscanf (FILE *__restrict __stream, const char *__restrict __format, ...) __asm__ ("" "__isoc99_fscanf") 542 | 543 | ; 544 | extern int scanf (const char *__restrict __format, ...) __asm__ ("" "__isoc99_scanf") 545 | ; 546 | extern int sscanf (const char *__restrict __s, const char *__restrict __format, ...) __asm__ ("" "__isoc99_sscanf") __attribute__ ((__nothrow__ , __leaf__)) 547 | 548 | ; 549 | # 463 "/usr/include/stdio.h" 3 4 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, 559 | __gnuc_va_list __arg) 560 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 561 | 562 | 563 | 564 | 565 | 566 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) 567 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 568 | 569 | 570 | extern int vsscanf (const char *__restrict __s, 571 | const char *__restrict __format, __gnuc_va_list __arg) 572 | __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__format__ (__scanf__, 2, 0))); 573 | # 494 "/usr/include/stdio.h" 3 4 574 | extern int vfscanf (FILE *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vfscanf") 575 | 576 | 577 | 578 | __attribute__ ((__format__ (__scanf__, 2, 0))) ; 579 | extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vscanf") 580 | 581 | __attribute__ ((__format__ (__scanf__, 1, 0))) ; 582 | extern int vsscanf (const char *__restrict __s, const char *__restrict __format, __gnuc_va_list __arg) __asm__ ("" "__isoc99_vsscanf") __attribute__ ((__nothrow__ , __leaf__)) 583 | 584 | 585 | 586 | __attribute__ ((__format__ (__scanf__, 2, 0))); 587 | # 522 "/usr/include/stdio.h" 3 4 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | extern int fgetc (FILE *__stream); 598 | extern int getc (FILE *__stream); 599 | 600 | 601 | 602 | 603 | 604 | extern int getchar (void); 605 | 606 | # 550 "/usr/include/stdio.h" 3 4 607 | extern int getc_unlocked (FILE *__stream); 608 | extern int getchar_unlocked (void); 609 | # 561 "/usr/include/stdio.h" 3 4 610 | extern int fgetc_unlocked (FILE *__stream); 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | extern int fputc (int __c, FILE *__stream); 623 | extern int putc (int __c, FILE *__stream); 624 | 625 | 626 | 627 | 628 | 629 | extern int putchar (int __c); 630 | 631 | # 594 "/usr/include/stdio.h" 3 4 632 | extern int fputc_unlocked (int __c, FILE *__stream); 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | extern int putc_unlocked (int __c, FILE *__stream); 641 | extern int putchar_unlocked (int __c); 642 | 643 | 644 | 645 | 646 | 647 | 648 | extern int getw (FILE *__stream); 649 | 650 | 651 | extern int putw (int __w, FILE *__stream); 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream) 661 | ; 662 | # 638 "/usr/include/stdio.h" 3 4 663 | extern char *gets (char *__s) __attribute__ ((__deprecated__)); 664 | 665 | 666 | # 665 "/usr/include/stdio.h" 3 4 667 | extern __ssize_t __getdelim (char **__restrict __lineptr, 668 | size_t *__restrict __n, int __delimiter, 669 | FILE *__restrict __stream) ; 670 | extern __ssize_t getdelim (char **__restrict __lineptr, 671 | size_t *__restrict __n, int __delimiter, 672 | FILE *__restrict __stream) ; 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | extern __ssize_t getline (char **__restrict __lineptr, 681 | size_t *__restrict __n, 682 | FILE *__restrict __stream) ; 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | extern int fputs (const char *__restrict __s, FILE *__restrict __stream); 692 | 693 | 694 | 695 | 696 | 697 | extern int puts (const char *__s); 698 | 699 | 700 | 701 | 702 | 703 | 704 | extern int ungetc (int __c, FILE *__stream); 705 | 706 | 707 | 708 | 709 | 710 | 711 | extern size_t fread (void *__restrict __ptr, size_t __size, 712 | size_t __n, FILE *__restrict __stream) ; 713 | 714 | 715 | 716 | 717 | extern size_t fwrite (const void *__restrict __ptr, size_t __size, 718 | size_t __n, FILE *__restrict __s); 719 | 720 | # 737 "/usr/include/stdio.h" 3 4 721 | extern size_t fread_unlocked (void *__restrict __ptr, size_t __size, 722 | size_t __n, FILE *__restrict __stream) ; 723 | extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size, 724 | size_t __n, FILE *__restrict __stream); 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | extern int fseek (FILE *__stream, long int __off, int __whence); 734 | 735 | 736 | 737 | 738 | extern long int ftell (FILE *__stream) ; 739 | 740 | 741 | 742 | 743 | extern void rewind (FILE *__stream); 744 | 745 | # 773 "/usr/include/stdio.h" 3 4 746 | extern int fseeko (FILE *__stream, __off_t __off, int __whence); 747 | 748 | 749 | 750 | 751 | extern __off_t ftello (FILE *__stream) ; 752 | # 792 "/usr/include/stdio.h" 3 4 753 | 754 | 755 | 756 | 757 | 758 | 759 | extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos); 760 | 761 | 762 | 763 | 764 | extern int fsetpos (FILE *__stream, const fpos_t *__pos); 765 | # 815 "/usr/include/stdio.h" 3 4 766 | 767 | # 824 "/usr/include/stdio.h" 3 4 768 | 769 | 770 | extern void clearerr (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 771 | 772 | extern int feof (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 773 | 774 | extern int ferror (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 775 | 776 | 777 | 778 | 779 | extern void clearerr_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 780 | extern int feof_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 781 | extern int ferror_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | extern void perror (const char *__s); 791 | 792 | 793 | 794 | 795 | 796 | 797 | # 1 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 1 3 4 798 | # 26 "/usr/include/x86_64-linux-gnu/bits/sys_errlist.h" 3 4 799 | extern int sys_nerr; 800 | extern const char *const sys_errlist[]; 801 | # 854 "/usr/include/stdio.h" 2 3 4 802 | 803 | 804 | 805 | 806 | extern int fileno (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 807 | 808 | 809 | 810 | 811 | extern int fileno_unlocked (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 812 | # 873 "/usr/include/stdio.h" 3 4 813 | extern FILE *popen (const char *__command, const char *__modes) ; 814 | 815 | 816 | 817 | 818 | 819 | extern int pclose (FILE *__stream); 820 | 821 | 822 | 823 | 824 | 825 | extern char *ctermid (char *__s) __attribute__ ((__nothrow__ , __leaf__)); 826 | # 913 "/usr/include/stdio.h" 3 4 827 | extern void flockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 828 | 829 | 830 | 831 | extern int ftrylockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)) ; 832 | 833 | 834 | extern void funlockfile (FILE *__stream) __attribute__ ((__nothrow__ , __leaf__)); 835 | # 943 "/usr/include/stdio.h" 3 4 836 | 837 | # 2 "main.c" 2 838 | 839 | int main(void) 840 | { 841 | return (0); 842 | } 843 | --------------------------------------------------------------------------------