Printf stands for printf formatted
. It is a function used to send formatted output to the screen. The format is defined by the conversion specifier passed.
In this project, we'll create a program that closely simulates the printf function in c.
This is an include guarded file that contains function prototypes of the different functions used to make this program.
- Usage:
man ./man_3_printf
.
Contains the _printf function.
- Prototype:
int _printf(const char *format , ...);
.- Returns the number of characters written to string.
- Returns -1 on failure.
a function that returns a pointer to a function based on the format specifier.
- Prototype:
int (*get_print_func(char c))(va_list, int);
.- If format specifier doe not exist, it returns NULL. Otherwise, it returns a function pointer.
Contains two functions handling format specifier
%s and %c
.
- print_ch() - A function that writes characters to stdout.
- print_str() - Function that writes strings to stdout.
- Prototype:
int print_ch(va_list args, int len);
int print_str(va_list args, int len)
.- Return:
- number of characters written.
Contains four functions all handling format specifiers
%d and %i
.
- print_int() - A function that checks for signed integers.
- _putchar_int() - A fuunction that writes signed integers to stdout.
- print_numbers() - A function that checks for numbers larger than INT_MAX.
- find_length() - A function that counts the digits in a numer.
- Prototypes:
int print_int(va_list args, int len)
int _putchar_int(int n, int len)
int print_numbers(unsigned long n, unsigned int base, const char *digits)
unsigned int find_length(unsigned int n, int base)
.
- Return:
- An unsigned long integer and the current length of the number.
- Length of number written to stdout.
- A call to findlength.
- Number of digits in a number.
Contains two functions handling the custom format specifier
%b
.
- print_binary() - A funtction that converts an int to binary.
- print_b() - Initializes the arg to an unsigned int and calls print_binary().
- Prototype:
int print_b(va_list args, int len);
.
int print_binary(unsigned int n, int len);
.
- Return:
- Length of printed binary.
- The value returned by print_binary
Contains two functions handling the format specifiers
%x and %X
.
- print_hex() - A function that converts integer inputs to lowercase hexadecimal numbers.
- print_heX() - A function that converts integer inputs to uppercase hexadecimal numbers.
- Prototype:
int print_hex(va_list args, int len);
.
int print_heX(va_list args, int len);
.
- Return:
- number of hexadecimal characters written.
Contains a function that handles the format specifier
%o
.
- print_octal() - A function that coverts integer inputs to octal values.
- Prototype:
int print_octal(va_list args, int len);
.
- Return:
- Number of cotal character written to stdout.
Contains a function that handles the format specifier
%R
.
- print_rot13() - A function that prints a string encrypted using ROT13.
- Prototype:
int print_rot13(va_list args, int len);
.
- Return:
- Number of characters written to stdout.
Contains a function that handles the format specifier
%S
.
- print_Str() - prints the unprintable characters in their hexadecimal equivalent preceded with
\x0
for on digit characters and\x
for charcters with more than one digit.
- Prototype:
int print_Str(va_list args, int len);
.
- Return:
- Number of characters written to stdout.