This project has been created as part of the 42 curriculum by alauer.
Description
The ft_printf project of the 42 curriculum asks of students to recode the printf function of the classic C library, without its buffer management. Flag, field and precision management is also considered a bonus. The main goal is deepen the students knowledge of C fundamentals, library management and project management. Furthermore it gives an introduction to the topic of variadic functions and deepens knowledge about different base systems and type promotion.
Instructions
make - compiles the library make re - cleans object files and compiles the library make test - you can copy my rudimentary testing main and use this to compile it :) especially useful if you quickly want to add tests of your own
I recommend using Tripouille/printfTester or xicodomingues/francinette from Github for testing.
All functions are fully documented. You check libft.h/ ft_printf.h for Doxygen comments (clangd should read them automatically for nvim/vim).
Resources
Variadic Functions https://en.cppreference.com/w/c/variadic.html https://www.geeksforgeeks.org/c/variadic-functions-in-c/ https://onepunchcoder.medium.com/variadic-functions-explained-fd3b4ab6fd84
Shift State ttps://www.gnu.org/software/libc/manual/html_node/Shift-State.html
Hexadecimal conversions & Bases https://www.geeksforgeeks.org/c/number-system-conversion-in-c/ https://www.shadecoder.com/de/topics/what-is-integer-division-a-practical-guide-for-2025 https://www.cs.cornell.edu/courses/cs2800/2015fa/lectures/lec17-division.html
Type promotion Kernighan & Ritchie, The C Programming Language, Second Edition (1988) Gustedt, Modern C, Third Edition (2025) Seacord, Effective C, Second Edition (2024)
AI, specifically Google Gemini was utilized in this project as a last resort resource if peer-to-peer contact or Googling didn't lead me to closer to a solution. It was never used to write code.
Algorithm & Data structure
As for algorithm I chose a simple string iteration, during which the program discerned between valid conversion specifiers and normal characters. The arguments for the conversion specifiers are stored in a va_list and the return value in an out variable. For convenience reasons I decided to only write helper functions for those specifier cases in which additional input validation was needed (pointer retrieval with %s and %p). For all other specifiers I rewrote common libft put and print functions to return an integer with the characters printed and added it to my out.