Because
ft_putnbr()andft_putstr()arenβt enough π
The ft_printf project is about re-implementing the famous C function printf().
It teaches you how to handle a variable number of arguments using variadic functions in C.
Once completed, youβll have your own version of printf() ready to use in future projects β
and youβll understand one of the most powerful formatting tools in C.
- Discover and understand variadic functions (
va_start,va_arg, etc.) - Learn to format and print data of various types.
- Strengthen your skills in modular code design, memory management, and error handling.
- Build a static library (
libftprintf.a) that can be reused in other projects.
| Program name | libftprintf.a |
|---|---|
| Turn in files | Makefile, *.h, *.c, and subfolder equivalents |
| Makefile rules | NAME, all, clean, fclean, re |
| External functions | malloc, free, write, va_start, va_arg, va_copy, va_end |
| Libft allowed | β Yes |
| Bonus included? | β No (mandatory part only) |
int ft_printf(const char *format, ...);Your implementation must handle the following format specifier:
| Specifier | Description |
|---|---|
%c |
Prints a single character |
%s |
Prints a string |
%p |
Prints a pointer address in hexadecimal |
%d |
Prints a signed decimal integer |
%i |
Prints a signed integer (same as %d) |
%u |
Prints an unsigned decimal integer |
%x |
Prints a number in lowercase hexadecimal |
%X |
Prints a number in uppercase hexadecimal |
%% |
Prints a literal percent sign |
βββ π includes
β βββ β‘ ft_printf.h
βββ π libft
β βββ π Makefile
β βββ π *.c
β βββ β‘ libft.h
βββ π src
β βββ π ft_check_is_find.c
β βββ π ft_print_base.c
β βββ π ft_print_p.c
β βββ π ft_printf.c
β βββ π ft_printux_x.c
β βββ π ft_putchar.c
β βββ π ft_putstr.c
βββ π Makefile
βββ π README.md
βββ π en.subject.pdfπ§© Structure may vary depending on your implementation β keep it modular and readable!
Your Makefile must:
- Compile source files with the following flags:
cc -Wall -Wextra -Werror- Create a static library called
libftprintf.a - Avoid unnecessary relinking
| Command | Description |
|---|---|
make |
Compile and build the library |
make clean |
Remove object files |
make fclean |
Remove object files and the library |
make re |
Rebuild everything from scratch |
Example test program:
#include "includes/ft_printf.h"
#include <stdio.h>
int main(void)
{
int n1 = ft_printf("My ft_printf: %d %s %p %x %%\n", 42, "Hello", (void *)0x1234, 255);
int n2 = printf("Original printf: %d %s %p %x %%\n", 42, "Hello", (void *)0x1234, 255);
printf("Returned: ft_printf=%d | printf=%d\n", n1, n2);
}Compile with:
cc main.c libftprintf.aExpected output:
My ft_printf: 42 Hello 0x1234 ff %
Original printf: 42 Hello 0x1234 ff %
Returned: ft_printf=35 | printf=38- Code must comply with the 42 Norm π§Ύ
- No memory leaks or unexpected crashes (segfaults, double frees, etc.)
- Every allocated memory must be properly freed when necessary
β Handles all mandatory conversions
β Correctly returns the number of printed characters
β
Works identically to printf in standard cases
β
Compiles with -Wall -Wextra -Werror
β Passes Norminette checks
β No memory leaks or crashes
β
Library correctly created using ar
Ayoub Sadouri
42 Network β ft_printf project
βA good printf is not about printing β itβs about precision.β
If youβre looking to build robust, scalable C applications or integrate low-level components into your web projects β letβs connect and collaborate!
β Donβt forget to star the repo if you find it helpful!