This printf project is a collaboration between Samuel Iwelumo and Aina Jesulayomi, students of Software Engineering at ALX Africa, where a function named "_printf" imitates the actual "printf" command located in the stdio.h library. It contains some of the basic features and functions found in the manual 3 of "printf" as well as some custom specifiers..
_printf() is a function that performs formatted output conversion and print data. Its prototype is the following:
int _printf(const char *format, ...);
Where format contains the string that is printed. As _printf() is variadic function, it can receive n arguments that replace by n tags written inside the string.
The format tags prototype is the following:
%[flags][length]specifier
If the program runs successfully, the return value is the amount of chars printed.
| Specifier | Output |
|---|---|
| c | Character |
| d or i | Signed decimal integer |
| s | String of characters |
| b | Signed binary |
| o | Signed octal |
| u | Unsigned integer |
| x | Unsigned hexadecimal |
| X | Unsigned hexadecimal (uppercase) |
| p | Pointer address |
| r | Reverse string of characters |
| R | ROT13 translation of string |
| S | String with special chars replaced by their ASCII value |
| % | Character |
| Flags | Description | Specifiers |
|---|---|---|
| + | Prints a plus sign (+) when the argument is a positive number. In other case, prints a minus sign (-). | i, d |
| (space) | Prints a blank space if the argument is a positive number | i, d |
| # | Prints 0, 0x and 0X for o, x and X specifiers, respectively. It doesn't print anything if the argument is zero | o, x, X |
| Length | Description | Specifiers |
|---|---|---|
| l | Prints a long int or unsigned long int | i, d, o, u, x and X |
| h | Prints a short int or unsigned short int | i, d, o, u, x and X |
-
Printing the string of chars "Hello, Holberton":
- Use:
_printf("Hello Wo%s.", "rld"); - Output:
Hello World.
- Use:
-
Printing an integer number:
- Use:
_printf("10 + 10 is equal to %d.", 20); - Output:
10 + 10 is equal to 20.
- Use:
-
Printing a binary, octal and hexadecimal:
- Use:
_printf("10 in binary is [%b], in octal is [%o] and in hexadecimal is [%x]", 5, 5, 5); - Output:
10 in binary is [1010], in octal is [12] and in hexadecimal is [A]
- Use:
-
Printing a string codified in ROT13:
- Use:
_printf("Hello in ROT13 is %R", "Hello"); - Output:
Hello in ROT13 is Urybb
- Use:
Using flags and length tags:
-
Printing the string of chars "Hello, World":
- Use:
_printf("2 * 2 = %+d and 5 * -5 = %+i", 4, -25); - Output:
2 * 2 = +4 and 5 * -5 = -25
- Use:
-
Printing a long integer number and short integer number:
- Use:
_printf("1 million as a long int is %ld, but as a short int is %hd", 1000000, 1000000); - Output:
1 million as a long int is 1000000, but as a short int is 16960
- Use:
int print_addr(va_list);
int print_bin(va_list);
int print_char(va_list);
int print_hash_HEX(va_list);
int print_hash_hex(va_list);
int print_hash_octal(va_list);
int print_HEX(long int, unsigned int, unsigned int);
int print_long_number(va_list);
int print_long_octal(va_list);
int print_long_unsigned_HEX(va_list);
int print_long_unsigned_dec(va_list);
int print_long_unsigned_hex(va_list);
int print_number(va_list);
int print_octal(va_list);
int print_percent(va_list);
int print_plus_number(va_list);
int print_rev(va_list);
int print_rot13(va_list);
int print_short_number(va_list);
int print_short_octal(va_list);
int print_short_unsigned_HEX(va_list);
int print_short_unsigned_dec(va_list);
int print_short_unsigned_hex(va_list);
int print_space_number(va_list);
int print_str(va_list);
int print_STR(va_list);
int print_unsigned_HEX(va_list);
int print_unsigned_dec(va_list);
int print_unsigned_hex(va_list);Own Printf Function Tha Performs Formatted Output Conversion And Print Data.
Header File Were All Prototypes Are Saved.
Pointer To A Function That Selects The Correct Function To Perform The Operation.
Function That writes a single character to stdout
Function That Writes The Character C To Stdout.
/* Identifier : %c */Function That Writes The String To Stdout.
/* Identifier : %s */Function That Prints An Integer.
/* Identifier : %i or %d */Function That Prints Decimal In Binary.
/* Identifier : %b */Function That Prints Decimal In Octal.
/* Identifier : %o */Function That Prints Decimal In Hexadecimal.
/* Identifier : %x */Function That Prints Decimal In Uppercase Hexadecimal.
/* Identifier : %X */Function That Prints A String And Values Of Non-Printed Chars.
/* Identifier : %S */Function That Prints An Unsigned Integer.
/* Identifier : %u */Function That Writes The String To Stdout In Reverse.
/* Identifier : %r */Function That Writes The String To Stdout In Rot13.
/* Identifier : %R */Function That Prints The Address Of An Input Variable.
/* Identifier : %p */Function That Prints Long Decimal Number In Octal.
/* Identifier : %lo */Function That Prints Long Decimal Number In Hexadecimal.
/* Identifier : %lx */Function That Prints A Long Integer.
/* Identifier : %li */Function That Prints A Long Decimal In Uppercase Hexadecimal.
/* Identifier : %lX */Function That Prints A Long Unsigned Integer.
/* Identifier : %lu */Function That Prints Short Decimal Number In Octal.
/* Identifier : %ho */Function That Prints Short Decimal Number In Hexadecimal.
/* Identifier : %hx */Function That Prints A Short Integer.
/* Identifier : %hi */Function That Prints A Short Decimal In Uppercase Hexadecimal.
/* Identifier : %hX */Function That Prints A Short Unsigned Integer.
/* Identifier : %hu */Function That Print A Number In Hexadecimal Begining With 0 And x.
/* Identifier : %#x */Function That Prints A Number In Octal Begining With 0 And o.
/* Identifier : %#o */Function That Prints A Number In Uppercase Hexadecimal.
/* Identifier : %#X */Function That Prints An Integer With Plus Symbol.
/* Identifier : %+i */Function That Prints An Integer Begining With 0 And u.
/* Identifier : % i */Function That Returns The Amount Of Identifiers.
Samuel Iwelumo and Aina Jesulayomi