├── .gitignore ├── README.md ├── _printf.c ├── _putchar.c ├── binary_helper.c ├── format_reciever.c ├── main.h ├── man_3_printf ├── print_HEX.c ├── print_String.c ├── print_binary.c ├── print_char.c ├── print_hex.c ├── print_hex_aux.c ├── print_integer.c ├── print_octal.c ├── print_percent.c ├── print_pointer.c ├── print_rev.c ├── print_rot13.c ├── print_string.c └── print_unsigned_integer.c /.gitignore: -------------------------------------------------------------------------------- 1 | main.c 2 | a.out 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # 0x011 .C Printf 3 | The aim of the project is to understand the concept of team work and therefore, demisifying the concept of printf 4 | 5 | --- 6 | # Tasks 7 | 8 | These are all the tasks of this project, the ones that are completed link to the corresponding files. 9 | 10 | ### 0. I'm not going anywhere. You can print that wherever you want to. I'm here and I'm a Spur for life] 11 | * Write a function that produces output according to format. 12 | - c : converts input into a character 13 | - s : converts input into a string 14 | 15 | ### 1. Education is when you read the fine print. Experience is what you get if you don't 16 | * Handle the following conversion specifiers: 17 | - d : converts input into a base 10 integer 18 | - i : converts input into an integer 19 | 20 | ### 2. Just because it's in print doesn't mean it's the gospel 21 | * Create a man page for your function 22 | 23 | ### 3. With a face like mine, I do better in print 24 | * Handle the following conversion specifiers: 25 | - b : the unsigned int argument is converted to binary 26 | 27 | ### 4. What one has not experienced, one will never understand in print 28 | * Handle the following conversion specifiers: 29 | - u : converts the input into an unsigned integer 30 | - o : converts the input into an octal number 31 | - x : converts the input into a hexadecimal number 32 | - X : converts the input into a hexadecimal number with capital letters 33 | 34 | ### 5. Nothing in fine print is ever good news 35 | * Use a local buffer of 1024 chars in order to call write as little as possible. 36 | 37 | ### 6. My weakness is wearing too much leopard print 38 | * Handle the following custom conversion specifier: 39 | - S : prints the string 40 | - Non printable characters (0 < ASCII value < 32 or >= 127) are printed this way: \x, followed by the ASCII code value in hexadecimal (upper case - always 2 characters) 41 | 42 | ### 7. How is the world ruled and led to war? Diplomats lie to journalists and believe these lies when they see them in print 43 | * Handle the following conversion specifier: 44 | - p : int input is converted to a pointer address 45 | 46 | ### 8. The big print gives and the small print takes away 47 | * Handle the following flag characters for non-custom conversion specifiers: 48 | - \+ : adds a \+ in front of signed positive numbers and a \- in front of signed negative numbers 49 | - space : same as \+, but adds a space (is overwritten by \+) 50 | - \# : adds a 0 in front of octal conversions that don't begin with one, and a 0x or 0X for x or X conversions 51 | 52 | ### 9. Sarcasm is lost in print 53 | * Handle the following length modifiers for non-custom conversion specifiers: 54 | - l : converts d, i, u, o, x, X conversions in short signed or unsigned ints 55 | - h : converts d, i, u, o, x, X conversions in long signed or unsigned ints 56 | 57 | ### 10. Print some money and give it to us for the rain forests 58 | * Handle the field width for non-custom conversion specifiers. 59 | 60 | ### 11. The negative is the equivalent of the composer's score, and the print the performance 61 | * Handle the precision for non-custom conversion specifiers. 62 | 63 | ### 12. It's depressing when you're still around and your albums are out of print 64 | * Handle the 0 flag character for non-custom conversion specifiers. 65 | 66 | ### 13. Every time that I wanted to give up, if I saw an interesting textile, print what ever, suddenly I would see a collection] 67 | * Handle the - flag character for non-custom conversion specifiers. 68 | 69 | ### 14. Print is the sharpest and the strongest weapon of our party 70 | * Handle the following custom conversion specifier: 71 | - r : prints the reversed string 72 | 73 | ### 15. The flood of print has turned reading into a process of gulping rather than savoring 74 | * Handle the following custom conversion specifier: 75 | - R : prints the rot13'ed string 76 | 77 | ### 16. * 78 | * All the above options work well together. 79 | 80 | --- 81 | # Author: 82 | [Oluwatimilehin Bello](https://github.com/Timilehin-bello) and [Nicole Adeyemi](https://github.com/adenicole) 83 | -------------------------------------------------------------------------------- /_printf.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _printf - Receives the main string and all the necessary parameters to 5 | * print a formated string 6 | * @format: A string containing all the desired characters 7 | * Return: A total count of the characters printed 8 | */ 9 | 10 | int _printf(const char *format, ...) 11 | { 12 | int printed_chars; 13 | conver_t f_list[] = { 14 | {"%", print_percent}, 15 | {"d", print_integer}, 16 | {"i", print_integer}, 17 | {"c", print_char}, 18 | {"s", print_string}, 19 | {"b", print_binary}, 20 | {"u", print_unsigned_integer}, 21 | {"o", print_octal}, 22 | {"x", print_hex}, 23 | {"X", print_HEX}, 24 | {"S", print_String}, 25 | {"p", print_pointer}, 26 | {"r", print_rev}, 27 | {"R", print_rot13}, 28 | {NULL, NULL}, 29 | }; 30 | va_list arg_list; 31 | 32 | if (format == NULL) 33 | return (-1); 34 | 35 | va_start(arg_list, format); 36 | printed_chars = format_reciever(format, f_list, arg_list); 37 | va_end(arg_list); 38 | return (printed_chars); 39 | } 40 | 41 | -------------------------------------------------------------------------------- /_putchar.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * _putchar - writes the character c to stdout 5 | * @c: The character to print 6 | * 7 | * Return: On success 1. 8 | * On error, -1 is returned, and errno is set appropriately. 9 | */ 10 | int _putchar(char c) 11 | { 12 | return (write(1, &c, 1)); 13 | } 14 | 15 | 16 | /** 17 | * _puts - prints a string to stdout 18 | * @str: pointer to the string to print 19 | * Return: number of chars written 20 | */ 21 | int _puts(char *str) 22 | { 23 | register short i; 24 | 25 | for (i = 0; str[i]; i++) 26 | _putchar(str[i]); 27 | return (i); 28 | } 29 | -------------------------------------------------------------------------------- /binary_helper.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * base_len - Calculates the length for an octal number 5 | * @num: The number for which the length is being calculated 6 | * @base: Base to be calculated by 7 | * Return: An integer representing the length of a number 8 | */ 9 | 10 | unsigned int base_len(unsigned int num, int base) 11 | { 12 | unsigned int i; 13 | 14 | for (i = 0; num > 0; i++) 15 | { 16 | num = num / base; 17 | } 18 | return (i); 19 | } 20 | 21 | 22 | /** 23 | * rev_string - reverses a string in place 24 | * 25 | * @s: string to reverse 26 | * Return: A pointer to a character 27 | */ 28 | 29 | char *rev_string(char *s) 30 | { 31 | int len; 32 | int head; 33 | char tmp; 34 | char *dest; 35 | 36 | for (len = 0; s[len] != '\0'; len++) 37 | {} 38 | 39 | dest = malloc(sizeof(char) * len + 1); 40 | if (dest == NULL) 41 | return (NULL); 42 | 43 | _memcpy(dest, s, len); 44 | for (head = 0; head < len; head++, len--) 45 | { 46 | tmp = dest[len - 1]; 47 | dest[len - 1] = dest[head]; 48 | dest[head] = tmp; 49 | } 50 | return (dest); 51 | } 52 | 53 | 54 | /** 55 | * write_base - sends characters to be written on standard output 56 | * @str: String to parse 57 | */ 58 | 59 | void write_base(char *str) 60 | { 61 | int i; 62 | 63 | for (i = 0; str[i] != '\0'; i++) 64 | _putchar(str[i]); 65 | } 66 | 67 | 68 | /** 69 | * _memcpy - copy memory area 70 | * @dest: Destination for copying 71 | * @src: Source to copy from 72 | * @n: The number of bytes to copy 73 | * Return: The _memcpy() function returns a pointer to dest. 74 | */ 75 | 76 | char *_memcpy(char *dest, char *src, unsigned int n) 77 | { 78 | unsigned int i; 79 | 80 | for (i = 0; i < n; i++) 81 | dest[i] = src[i]; 82 | dest[i] = '\0'; 83 | return (dest); 84 | } 85 | 86 | 87 | /** 88 | * hex_check - Checks which hex function is calling it 89 | * @num: Number to convert into letter 90 | * @x: Tells which hex function is calling it 91 | * Return: Ascii value for a letter 92 | */ 93 | 94 | int hex_check(int num, char x) 95 | { 96 | char *hex = "abcdef"; 97 | char *Hex = "ABCDEF"; 98 | 99 | num = num - 10; 100 | if (x == 'x') 101 | return (hex[num]); 102 | else 103 | return (Hex[num]); 104 | return (0); 105 | } 106 | -------------------------------------------------------------------------------- /format_reciever.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * format_reciever - Receives the main string and all the 5 | * necessary parameters to print a formated string. 6 | * @format: A string containing all the desired characters. 7 | * @f_list: A list of all the posible functions. 8 | * @arg_list: A list containing all the argumentents passed to the program. 9 | * Return: A total count of the characters printed. 10 | */ 11 | 12 | int format_reciever(const char *format, conver_t f_list[], va_list arg_list) 13 | { 14 | int i, j, r_val, printed_chars; 15 | 16 | printed_chars = 0; 17 | for (i = 0; format[i] != '\0'; i++) 18 | { 19 | if (format[i] == '%') 20 | { 21 | for (j = 0; f_list[j].sym != NULL; j++) 22 | { 23 | if (format[i + 1] == f_list[j].sym[0]) 24 | { 25 | r_val = f_list[j].f(arg_list); 26 | if (r_val == -1) 27 | return (-1); 28 | printed_chars += r_val; 29 | break; 30 | } 31 | } 32 | if (f_list[j].sym == NULL && format[i + 1] != ' ') 33 | { 34 | if (format[i + 1] != '\0') 35 | { 36 | _putchar(format[i]); 37 | _putchar(format[i + 1]); 38 | printed_chars = printed_chars + 2; 39 | } 40 | else 41 | return (-1); 42 | } 43 | i = i + 1; 44 | } 45 | else 46 | { 47 | _putchar(format[i]); 48 | printed_chars++; 49 | } 50 | } 51 | return (printed_chars); 52 | } 53 | 54 | -------------------------------------------------------------------------------- /main.h: -------------------------------------------------------------------------------- 1 | #ifndef MAIN_H 2 | #define MAIN_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define NULL_STRING "(null)" 11 | #define NUL '\0' 12 | 13 | /** 14 | * struct convert - defines a structure for symbols and functions 15 | * 16 | * @sym: The operator 17 | * @f: The function associated 18 | */ 19 | 20 | struct convert 21 | { 22 | char *sym; 23 | int (*f)(va_list); 24 | }; 25 | typedef struct convert conver_t; 26 | 27 | 28 | int _printf(const char *format, ...); 29 | int _putchar(char c); 30 | int format_reciever(const char *format, conver_t f_list[], va_list arg_list); 31 | int print_percent(va_list); 32 | int print_integer(va_list); 33 | int print_char(va_list); 34 | int print_string(va_list); 35 | int print_binary(va_list); 36 | int print_unsigned_integer(va_list); 37 | int print_octal(va_list list); 38 | int print_hex(va_list list); 39 | int print_HEX(va_list list); 40 | int print_String(va_list val); 41 | int print_pointer(va_list val); 42 | int print_rev(va_list l); 43 | int print_rot13(va_list list); 44 | 45 | int print_number(va_list args); 46 | unsigned int base_len(unsigned int, int); 47 | char *rev_string(char *); 48 | void write_base(char *str); 49 | char *_memcpy(char *dest, char *src, unsigned int n); 50 | int print_unsgined_number(unsigned int n); 51 | int hex_check(int num, char x); 52 | int print_hex_aux(unsigned long int num); 53 | int isNonAlphaNumeric(char c); 54 | int _puts(char *str); 55 | char *convert(unsigned long int num, int base, int lowercase); 56 | #endif 57 | -------------------------------------------------------------------------------- /man_3_printf: -------------------------------------------------------------------------------- 1 | _PRINTF(3) 2 | 3 | NAME 4 | _printf - prints supplied string with certain operators for substitution and formatting 5 | 6 | SYNOPSIS 7 | _printf FORMAT [ARGUMENTS] ... 8 | 9 | DESCRIPTION 10 | Print ARGUMENT(s) according to OPTION within the supplied FORMAT string 11 | 12 | FORMAT controls the output to STDOUT including OPERATORS 13 | 14 | EXAMPLES 15 | _print("Alx Project %d", n); 16 | 17 | REPORTING BUGS 18 | Report _printf bugs to https://www.github.com/adenicole/printf 19 | 20 | AUTHORS 21 | Made by Adeyemi Nicole and Timilehin Bello -------------------------------------------------------------------------------- /print_HEX.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_HEX - Prints a representation of a decimal number on base16 Uppercase 5 | * @list: List of the arguments passed to the function 6 | * Return: Number of characters printed 7 | */ 8 | 9 | int print_HEX(va_list list) 10 | { 11 | unsigned int num; 12 | int len; 13 | int rem_num; 14 | char *hex_rep; 15 | char *rev_hex; 16 | 17 | num = va_arg(list, unsigned int); 18 | 19 | if (num == 0) 20 | return (_putchar('0')); 21 | if (num < 1) 22 | return (-1); 23 | len = base_len(num, 16); 24 | hex_rep = malloc(sizeof(char) * len + 1); 25 | if (hex_rep == NULL) 26 | return (-1); 27 | for (len = 0; num > 0; len++) 28 | { 29 | rem_num = num % 16; 30 | if (rem_num > 9) 31 | { 32 | rem_num = hex_check(rem_num, 'X'); 33 | hex_rep[len] = rem_num; 34 | } 35 | else 36 | hex_rep[len] = rem_num + 48; 37 | num = num / 16; 38 | } 39 | hex_rep[len] = '\0'; 40 | rev_hex = rev_string(hex_rep); 41 | if (rev_hex == NULL) 42 | return (-1); 43 | write_base(rev_hex); 44 | free(hex_rep); 45 | free(rev_hex); 46 | return (len); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /print_String.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_String - print exclusuives string. 5 | * @val: argumen t. 6 | * Return: the length of the string. 7 | */ 8 | 9 | int print_String(va_list l) 10 | { 11 | register short len = 0; 12 | char *res, *s = va_arg(l, char *); 13 | int count; 14 | 15 | if (!s) 16 | return (_puts(NULL_STRING)); 17 | for (; *s; s++) 18 | { 19 | if (isNonAlphaNumeric(*s)) 20 | { 21 | count += _puts("\\x"); 22 | res = convert(*s, 16, 0); 23 | if (!res[1]) 24 | len += _putchar('0'); 25 | len += _puts(res); 26 | } 27 | else 28 | len += _putchar(*s); 29 | } 30 | return (len); 31 | } 32 | 33 | /** 34 | * isNonAlphaNumeric - determines if char is a non- 35 | * alphanumeric char on ASCII table 36 | * @c: input char 37 | * Return: true or false 38 | */ 39 | 40 | int isNonAlphaNumeric(char c) 41 | { 42 | return ((c > 0 && c < 32) || c >= 127); 43 | } 44 | 45 | /** 46 | * convert - converts number and base into string 47 | * @num: input number 48 | * @base: input base 49 | * @lowercase: flag if hexa values need to be lowercase 50 | * Return: result string 51 | */ 52 | 53 | char *convert(unsigned long int num, int base, int lowercase) 54 | { 55 | static char *rep; 56 | static char buffer[50]; 57 | char *ptr; 58 | 59 | rep = (lowercase) 60 | ? "0123456789abcdef" 61 | : "0123456789ABCDEF"; 62 | ptr = &buffer[49]; 63 | *ptr = NUL; 64 | do { 65 | *--ptr = rep[num % base]; 66 | num /= base; 67 | } while (num); 68 | 69 | return (ptr); 70 | } 71 | -------------------------------------------------------------------------------- /print_binary.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_binary - Converts a number from base 10 to binary 5 | * @list: List of arguments passed to this function 6 | * Return: The length of the number printed 7 | */ 8 | 9 | int print_binary(va_list list) 10 | { 11 | unsigned int num; 12 | int i, len; 13 | char *str; 14 | char *rev_str; 15 | 16 | num = va_arg(list, unsigned int); 17 | if (num == 0) 18 | return (_putchar('0')); 19 | if (num < 1) 20 | return (-1); 21 | len = base_len(num, 2); 22 | str = malloc(sizeof(char) * len + 1); 23 | if (str == NULL) 24 | return (-1); 25 | 26 | for (i = 0; num > 0; i++) 27 | { 28 | if (num % 2 == 0) 29 | str[i] = '0'; 30 | else 31 | str[i] = '1'; 32 | num = num / 2; 33 | } 34 | str[i] = '\0'; 35 | rev_str = rev_string(str); 36 | if (rev_str == NULL) 37 | return (-1); 38 | write_base(rev_str); 39 | free(str); 40 | free(rev_str); 41 | return (len); 42 | } 43 | -------------------------------------------------------------------------------- /print_char.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_char - Prints character 5 | * @list: list of arguments 6 | * Return: Will return the amount of characters printed. 7 | */ 8 | 9 | int print_char(va_list list) 10 | { 11 | _putchar(va_arg(list, int)); 12 | return (1); 13 | } 14 | -------------------------------------------------------------------------------- /print_hex.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_hex - Prints a representation of a decimal number on base16 lowercase 5 | * @list: List of the arguments passed to the function 6 | * Return: Number of characters printed 7 | */ 8 | 9 | int print_hex(va_list list) 10 | { 11 | unsigned int num; 12 | int len; 13 | int rem_num; 14 | char *hex_rep; 15 | char *rev_hex; 16 | 17 | num = va_arg(list, unsigned int); 18 | 19 | if (num == 0) 20 | return (_putchar('0')); 21 | if (num < 1) 22 | return (-1); 23 | len = base_len(num, 16); 24 | hex_rep = malloc(sizeof(char) * len + 1); 25 | if (hex_rep == NULL) 26 | return (-1); 27 | for (len = 0; num > 0; len++) 28 | { 29 | rem_num = num % 16; 30 | if (rem_num > 9) 31 | { 32 | rem_num = hex_check(rem_num, 'x'); 33 | hex_rep[len] = rem_num; 34 | } 35 | else 36 | hex_rep[len] = rem_num + 48; 37 | num = num / 16; 38 | } 39 | hex_rep[len] = '\0'; 40 | rev_hex = rev_string(hex_rep); 41 | if (rev_hex == NULL) 42 | return (-1); 43 | write_base(rev_hex); 44 | free(hex_rep); 45 | free(rev_hex); 46 | return (len); 47 | } 48 | -------------------------------------------------------------------------------- /print_hex_aux.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_hex_aux - prints an hexgecimal number. 5 | * @num: arguments. 6 | * Return: counter. 7 | */ 8 | 9 | int print_hex_aux(unsigned long int num) 10 | { 11 | long int i; 12 | long int *array; 13 | long int counter = 0; 14 | unsigned long int temp = num; 15 | 16 | while (num / 16 != 0) 17 | { 18 | num /= 16; 19 | counter++; 20 | } 21 | counter++; 22 | array = malloc(counter * sizeof(long int)); 23 | 24 | for (i = 0; i < counter; i++) 25 | { 26 | array[i] = temp % 16; 27 | temp /= 16; 28 | } 29 | for (i = counter - 1; i >= 0; i--) 30 | { 31 | if (array[i] > 9) 32 | array[i] = array[i] + 39; 33 | _putchar(array[i] + '0'); 34 | } 35 | free(array); 36 | return (counter); 37 | } 38 | -------------------------------------------------------------------------------- /print_integer.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_integer - Prints an integer 5 | * @list: list of arguments 6 | * Return: Will return the amount of characters printed. 7 | */ 8 | 9 | int print_integer(va_list list) 10 | { 11 | int num_length; 12 | 13 | num_length = print_number(list); 14 | return (num_length); 15 | } 16 | 17 | 18 | /** 19 | * print_number - prints a number send to this function 20 | * @args: List of arguments 21 | * Return: The number of arguments printed 22 | */ 23 | 24 | int print_number(va_list args) 25 | { 26 | int n; 27 | int div; 28 | int len; 29 | unsigned int num; 30 | 31 | n = va_arg(args, int); 32 | div = 1; 33 | len = 0; 34 | 35 | if (n < 0) 36 | { 37 | len += _putchar('-'); 38 | num = n * -1; 39 | } 40 | else 41 | num = n; 42 | 43 | for (; num / div > 9; ) 44 | div *= 10; 45 | 46 | for (; div != 0; ) 47 | { 48 | len += _putchar('0' + num / div); 49 | num %= div; 50 | div /= 10; 51 | } 52 | 53 | return (len); 54 | } 55 | 56 | 57 | -------------------------------------------------------------------------------- /print_octal.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_octal - Prints the numeric representation of a number in octal base 5 | * @list: List of all the arguments passed to the program 6 | * Return: Number of symbols printed to stdout 7 | */ 8 | 9 | int print_octal(va_list list) 10 | { 11 | unsigned int num; 12 | int len; 13 | char *octal_rep; 14 | char *rev_str; 15 | 16 | num = va_arg(list, unsigned int); 17 | 18 | if (num == 0) 19 | return (_putchar('0')); 20 | if (num < 1) 21 | return (-1); 22 | len = base_len(num, 8); 23 | 24 | octal_rep = malloc(sizeof(char) * len + 1); 25 | if (octal_rep == NULL) 26 | return (-1); 27 | for (len = 0; num > 0; len++) 28 | { 29 | octal_rep[len] = (num % 8) + 48; 30 | num = num / 8; 31 | 32 | } 33 | octal_rep[len] = '\0'; 34 | rev_str = rev_string(octal_rep); 35 | if (rev_str == NULL) 36 | return (-1); 37 | 38 | write_base(rev_str); 39 | free(octal_rep); 40 | free(rev_str); 41 | return (len); 42 | } 43 | 44 | -------------------------------------------------------------------------------- /print_percent.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_percent - Prints a percent symbol 5 | * @list: list of arguments 6 | * Return: Will return the amount of characters printed. 7 | */ 8 | int print_percent(__attribute__((unused))va_list list) 9 | { 10 | _putchar('%'); 11 | return (1); 12 | } 13 | 14 | -------------------------------------------------------------------------------- /print_pointer.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_pointer - prints an hexgecimal number. 5 | * @val: arguments. 6 | * Return: counter. 7 | */ 8 | 9 | int print_pointer(va_list val) 10 | { 11 | void *p; 12 | char *s = "(nil)"; 13 | long int a; 14 | int b; 15 | int i; 16 | 17 | p = va_arg(val, void*); 18 | if (p == NULL) 19 | { 20 | for (i = 0; s[i] != '\0'; i++) 21 | { 22 | _putchar(s[i]); 23 | } 24 | return (i); 25 | } 26 | 27 | a = (unsigned long int)p; 28 | _putchar('0'); 29 | _putchar('x'); 30 | b = print_hex_aux(a); 31 | return (b + 2); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /print_rev.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_rev - prints a string in reverse 5 | * @l: argument from _printf 6 | * Return: length of the printed string 7 | */ 8 | 9 | int print_rev(va_list l) 10 | { 11 | int i = 0, j; 12 | char *s = va_arg(l, char *); 13 | 14 | if (!s) 15 | s = "(null)"; 16 | 17 | while (s[i]) 18 | i++; 19 | 20 | for (j = i - 1; j >= 0; j--) 21 | _putchar(s[j]); 22 | 23 | return (i); 24 | } 25 | -------------------------------------------------------------------------------- /print_rot13.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_rot13 - prints a string using rot13 5 | * @list: list of arguments from _printf 6 | * Return: length of the printed string 7 | */ 8 | 9 | int print_rot13(va_list list) 10 | { 11 | int i; 12 | int x; 13 | char *str; 14 | char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; 15 | char u[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"; 16 | 17 | str = va_arg(list, char *); 18 | if (str == NULL) 19 | return (-1); 20 | for (i = 0; str[i] != '\0'; i++) 21 | { 22 | for (x = 0; x <= 52; x++) 23 | { 24 | if (str[i] == s[x]) 25 | { 26 | _putchar(u[x]); 27 | break; 28 | } 29 | } 30 | if (x == 53) 31 | _putchar(str[i]); 32 | } 33 | return (i); 34 | } 35 | -------------------------------------------------------------------------------- /print_string.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_string - Prints a string 5 | * @list: list of arguments 6 | * Return: Will return the amount of characters printed. 7 | */ 8 | 9 | int print_string(va_list list) 10 | { 11 | int i; 12 | char *str; 13 | 14 | str = va_arg(list, char *); 15 | if (str == NULL) 16 | str = "(null)"; 17 | for (i = 0; str[i] != '\0'; i++) 18 | _putchar(str[i]); 19 | return (i); 20 | } 21 | -------------------------------------------------------------------------------- /print_unsigned_integer.c: -------------------------------------------------------------------------------- 1 | #include "main.h" 2 | 3 | /** 4 | * print_unsigned_integer - Prints Unsigned integers 5 | * @list: List of all of the argumets 6 | * Return: a count of the numbers 7 | */ 8 | 9 | int print_unsigned_integer(va_list list) 10 | { 11 | unsigned int num; 12 | 13 | num = va_arg(list, unsigned int); 14 | 15 | if (num == 0) 16 | return (print_unsgined_number(num)); 17 | 18 | if (num < 1) 19 | return (-1); 20 | return (print_unsgined_number(num)); 21 | } 22 | 23 | 24 | /** 25 | * print_unsgined_number - Prints an unsigned number 26 | * @n: unsigned integer to be printed 27 | * Return: The amount of numbers printed 28 | */ 29 | 30 | int print_unsgined_number(unsigned int n) 31 | { 32 | int div; 33 | int len; 34 | unsigned int num; 35 | 36 | div = 1; 37 | len = 0; 38 | 39 | num = n; 40 | 41 | for (; num / div > 9; ) 42 | div *= 10; 43 | 44 | for (; div != 0; ) 45 | { 46 | len += _putchar('0' + num / div); 47 | num %= div; 48 | div /= 10; 49 | } 50 | 51 | return (len); 52 | } 53 | --------------------------------------------------------------------------------