My second Project in 42 is to replicate the printf function in C.
In this project is required to use the variadic functions.
Variadic functions are functions that may be called with different numbers of arguments.
When a variadic function is called, all parameters are stored on the stack by the compiler and initialized with macros:
- The necessary information is stored in va_list
- Initialise parameter access with va_start
- Get a new parameter with each call to va_arg
- Finish with va_end
Is required to use the library <stdarg.h>
When it finds the '%' character, it calls the conversion function and formats it according to the corresponding conversion specifier (the character after the `'%').
This project consists of duplicating the behavior of the C function printf().
int ft_printf(const char *, ...);The printf function returns the number of characters printed, or a negative value if an error occurs.
Supported conversions:
%c - Prints a single character
%s - Prints a string
%p - Prints a pointer address
%d or %i - Prints a signed integer
%u - Prints an unsigned integer
%x or %X - Prints an unsigned integer in hexadecimal format ("0123456789abcdef")
ft_putchar
ft_putstr
ft_ptr
ft_putnbr
ft_unsigned
ft_hex