This project has been created as part of the 42 curriculum by ibcolak.
ft_printf is a simplified reimplementation of the C standard library printf function.
The project uses variadic functions to print formatted output and returns the number of characters written.
Supported conversions:
%c— character%s— string%p— pointer address in hexadecimal%d/%i— signed decimal integer%u— unsigned decimal integer%x/%X— hexadecimal integer%%— percent sign
Build the static library:
makeThis creates:
libftprintf.a
Use it in a program:
#include "ft_printf.h"
int main(void)
{
ft_printf("Hello %s: %d\n", "42", 42);
return (0);
}Compile your program with the library:
cc main.c -L. -lftprintf -o test
./testUseful Makefile rules:
make # Build libftprintf.a
make clean # Remove object files
make fclean # Remove object files and library
make re # Rebuild everythingft_printf reads the format string from left to right.
- Normal characters are printed directly with
write. - When
%is found, the next character selects the matching conversion. - Variadic arguments are read with
va_list,va_start,va_arg, andva_end. - Each conversion function returns its number of written characters.
ft_printfadds these values and returns the final count.- If a
writeoperation fails, the error is propagated as-1.
For numeric conversions, the number is repeatedly divided by its base (10 for decimal and 16 for hexadecimal). The remainder gives the last digit, so digits are stored temporarily and printed in reverse order.
AI was used as a learning assistant to explain variadic functions, format conversions, error handling, Norminette feedback, and to review code structure. The implementation was reviewed and understood by the author before use.