ft_printf
My ft_printf notes.
ft_printf
This will just be a thought collection or code snippet storage. Not a detailed walkthrough or example of ft_printf.
Your implementation will be evaluated against the behavior of the original printf().
inputs
int ft_printf(const char *, …);
check if the const char * is not NULL.
This needs to be handled by variatic functions.
You have to implement the following conversions:
- %c Prints a single character.
- %s Prints a string (as defined by the common C convention).
- %p The void * pointer argument has to be printed in hexadecimal format.
- %d Prints a decimal (base 10) number.
- %i Prints an integer in base 10.
- %u Prints an unsigned decimal (base 10) number.
- %x Prints a number in hexadecimal (base 16) lowercase format.
- %X Prints a number in hexadecimal (base 16) uppercase format.
- %% Prints a percent sign.
handle the functions
%c Prints a single character.
- The int argument is converted to an unsigned char, and the resulting character is written.
%s Prints a string (as defined by the common C convention).
- The const char * argument is expected to be a pointer to an array of character type (pointer to a string). Characters from the array are written up to (but not including) a terminating null byte (‘\0’);
- If the precision is not specified, or is greater than the size of the array, the array must contain a terminating null byte.
- if NULL print (null)
%p The void * pointer argument has to be printed in hexadecimal format.
- The void * pointer argument is printed in hexadecimal.
- if NULL print (nil)
%d Prints a decimal (base 10) number.
- The int argument is converted to signed decimal notation.
%i Prints an integer in base 10.
- The int argument is converted to signed decimal notation.
%u Prints an unsigned decimal (base 10) number.
- The unsigned int argument is converted to an unsigned decimal.
%x Prints a number in hexadecimal (base 16) lowercase format.
- The unsigned int argument is converted to unsigned hexadecimal.
- The letters abcdef are used for x conversions.
%X Prints a number in hexadecimal (base 16) uppercase format.
- The unsigned int argument is converted to unsigned hexadecimal.
- The letters ABCDEF are used for x conversions.
%% Prints a percent sign.
- A ‘%’ is written. No argument is converted.
return value
Upon successful return, these functions return the number of characters printed (excluding the null byte used to end output to strings).
If an output error is encountered, a negative value is returned.