A custom implementation of
printf()from the C standard library
Reimplementation of printf() as a static library (libftprintf.a), built from scratch using variadic functions (stdarg.h). Handles formatted output with type-safe argument parsing.
| Specifier | Output |
|---|---|
%c |
Single character |
%s |
String |
%p |
Pointer address (hex) |
%d |
Signed decimal integer |
%i |
Signed integer (base 10) |
%u |
Unsigned decimal integer |
%x |
Hexadecimal (lowercase) |
%X |
Hexadecimal (uppercase) |
%% |
Literal % |
make # compiles libftprintf.a
make clean # removes .o files
make fclean # removes .o and .a files
make re # full recompile#include "ft_printf.h"
int main(void)
{
ft_printf("Hello %s, you are %d years old\n", "world", 42);
ft_printf("Pointer: %p\n", &main);
ft_printf("Hex: %x | Upper: %X\n", 255, 255);
return (0);
}Compile with the library:
cc -Wall -Wextra -Werror main.c -L. -lftprintf -o my_programft_printf/
├── ft_printf.c # Core dispatcher — parses format string and routes to handlers
├── ft_printf.h # Header with prototypes
├── ft_print_char.c # %c handler
├── ft_print_string.c # %s handler
├── ft_print_number.c # %d / %i handler
├── ft_print_unsigned.c # %u handler
├── ft_print_hex.c # %x / %X handler
├── ft_print_pointer.c # %p handler
└── Makefile
ft_printfiterates through the format string character by character- When
%is found, it reads the next character to determine the conversion - The appropriate handler is called, which writes to stdout using
write() - Each handler returns the number of characters printed
- The total count is returned (matching
printfbehavior)
Developed as part of the 42 Madrid curriculum. The project focuses on variadic functions, formatted output, and modular C programming.