A C reimplementation of
printf, built as part of the 42 School curriculum.This project explores variadic functions, format parsing, and writing formatted output while returning the number of characters printed.
ft_printf reads a format string, retrieves each matching argument with stdarg.h, prints the value, and returns the total output length. The implementation is packaged as the reusable static library libftprintf.a.
| Conversion | Output |
|---|---|
%c |
A character |
%s |
A string ((null) for a null pointer) |
%p |
A pointer address in hexadecimal with a 0x prefix |
%d, %i |
A signed integer |
%u |
An unsigned integer |
%x, %X |
A lowercase or uppercase hexadecimal integer |
%% |
A literal percent sign |
- 🎭 Variadic arguments with
va_list,va_start,va_arg, andva_end - 🔎 Parsing a format string and dispatching to conversion functions
- 🔢 Converting signed, unsigned, hexadecimal, and pointer values to text
- 📏 Counting the characters written and returning the total
- 📦 Building a reusable static library with Make
- A C compiler such as
ccorgcc make
git clone <repository-url>
cd printf
makeThe build creates libftprintf.a in the project directory.
#include "ft_printf.h"
int main(void)
{
int printed;
printed = ft_printf("Hello, %s! Number: %d\n", "world", 42);
return (printed < 0);
}Compile your program with the library:
cc -Wall -Wextra -Werror -I/path/to/printf \
main.c /path/to/printf/libftprintf.a -o appReplace /path/to/printf with the directory containing ft_printf.h and libftprintf.a.
| Command | Description |
|---|---|
make |
Build libftprintf.a |
make clean |
Remove object files |
make fclean |
Remove object files and the library |
make re |
Clean and rebuild |
The project received a successful score of 104/100. The evaluation summary is included below.
Sedef Akkaya
GitHub · LinkedIn
✨ Parse the format. Print the value. Count every character.
