A custom implementation of printf developed as part of the 42 curriculum.
ft_printf is a small formatted output library that reproduces the core behavior of printf with the conversions required by the subject.
It was a good way to build solid foundations in formatted output, function decomposition and variadic argument handling in C.
- Reimplementation of a simplified
printf - Support for variadic arguments through
stdarg.h - Handling of the mandatory 42 format specifiers
- Static library build with
make
ft_printf.h— header file with function prototypesft_printf.c— main formatted output dispatcherft_putchar.c— character output helperft_putstr.c— string output helperft_putnbr.c— signed integer output helperft_puthex.c— hexadecimal output helperft_putptr.c— pointer output helperMakefile— builds thelibftprintf.astatic library
The mandatory part focuses on the conversions and helper functions needed to reproduce the expected printf behavior.
ft_printf— parses the format string, reads variadic arguments, dispatches each conversion and returns the total number of printed characters
%c— prints a single character%s— prints a string%p— prints a pointer address in hexadecimal form%d— prints a signed decimal number%i— prints an integer in base 10%u— prints an unsigned decimal number%x— prints a hexadecimal number using lowercase letters%X— prints a hexadecimal number using uppercase letters%%— prints a literal percent sign
ft_putchar— writes one character and returns the number of printed charactersft_putstr— writes a string and returns the number of printed charactersft_putnbr— writes a signed number and returns the printed lengthft_puthex— writes a number in hexadecimal format and returns the printed lengthft_putptr— writes a pointer value in hexadecimal format and returns the printed length
Build the library:
makeClean object files:
make cleanRemove object files and library:
make fcleanRebuild everything:
make reThis project was my first real introduction to variadic functions and formatted output in C. It helped build solid foundations in:
- variadic argument handling with
va_start,va_argandva_end - output formatting logic
- recursive or decomposed number printing
- hexadecimal conversion
- return value tracking
- modular code organization