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.

GitHub
0
0
0

Laatst bijgewerkt

april 07, 2026

ft_printf

ft_printf is a project developed as part of the curriculum at 42 School, aimed at recreating a simplified version of the C standard library’s 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.

sh
git clone https://github.com/milandekruijf/ft_printf.git && cd ft_printf

Compiling

In order to build the library, run the following command in the project root directory.

sh
make

Builds 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):

sh
gcc -Wall -Wextra -Werror your_program.c libftprintf.a -o your_program

The function writes to standard output (file descriptor 1) and returns the number of characters printed, like printf.

Cleaning

Remove object files:

sh
make clean

Remove object files and libftprintf.a:

sh
make fclean

Rebuild from scratch:

sh
make re

Features

This implementation supports the following conversion specifiers and behavior.

Conversion specifiers

  • %c: Prints a single character.
  • %s: Prints a string.
  • %p: Prints a void pointer as lowercase hexadecimal with a 0x prefix (non-NULL addresses).
  • %d: Prints a signed decimal integer.
  • %i: Prints a signed decimal integer (same bases as %d here).
  • %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 NULL pointer passed for %s is printed as (null).
  • A NULL pointer passed for %p is 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.

Acknowledgements

  • libft: Utility functions in libft/ used as the foundation for this project.
  • 42: The educational institution that inspired and supported the development of this project.
  • Codam: The partner school of 42 in the Netherlands, where the project was developed.