ft_printf
ft_printf is a project developed as part of the curriculum at 42 School, aimed at creating a custom implementation of the C printf function. This project serves as a practical exercise in variadic functions, format string parsing, and output handling, enabling students to deepen their understanding of low-level C programming concepts.
Last updated
ft_printf
printf function. The implementation is provided as a static library in C and builds on a companion libft collection.Usage
Prerequisites
Clone the repository to your local machine using the following command in the terminal.
git clone https://github.com/milandekruijf/ft_printf.git && cd ft_printfCompiling
In order to build the library, run the following command in the project root directory.
makeBuilds libftprintf.a in the project root using gcc with the flags -Wall, -Wextra, and -Werror. The bundled libft in libft/ is compiled first, then object files from this directory are archived into libftprintf.a.
Using the library
ft_printf is not a standalone program: link your code against libftprintf.a and include ft_printf.h. Example from the project root (adjust paths if your source lives elsewhere):
gcc -Wall -Wextra -Werror your_program.c libftprintf.a -o your_programThe function writes to standard output (file descriptor 1) and returns the number of characters printed, like printf.
Cleaning
Remove object files:
make cleanRemove object files and libftprintf.a:
make fcleanRebuild from scratch:
make reFeatures
This implementation supports the following conversion specifiers and behavior.
Conversion specifiers
%c: Prints a single character.%s: Prints a string.%p: Prints avoidpointer as lowercase hexadecimal with a0xprefix (non-NULLaddresses).%d: Prints a signed decimal integer.%i: Prints a signed decimal integer (same bases as%dhere).%u: Prints an unsigned decimal integer.%x: Prints an unsigned integer in lowercase hexadecimal.%X: Prints an unsigned integer in uppercase hexadecimal.%%: Prints a literal percent sign.
Edge cases
- A
NULLpointer passed for%sis printed as(null). - A
NULLpointer passed for%pis printed as(nil).
Limitations
This is a teaching subset of printf. It does not implement field width, precision, flags (0, -, +, space, #), length modifiers (l, ll, z, etc.), or additional conversions such as %n, %f, or %o unless you extend the project yourself.