ft_printf is a project from the 42 São Paulo Common Core curriculum. It recreates a simplified version of the C standard library’s printf()
function, leveraging variadic arguments to handle diverse format specifiers.
42 São Paulo is a tuition-free, global coding school focused on peer-to-peer learning and project-based education. This project enhances C programming skills by implementing a versatile, extensible function.
ft_printf delivers a library (libftprintf.a
) containing the ft_printf()
function, which mimics the original printf()
. It’s split into two parts:
- Mandatory Part: Handles basic conversions (
cspdiuxX%
). - Bonus Part: Adds support for additional formatting flags.
- Supports specifiers:
%c
(char),%s
(string),%p
(pointer),%d
(decimal),%i
(integer),%u
(unsigned),%x
/%X
(hex lowercase/uppercase),%%
(percent). - Uses variadic arguments for flexible input handling.
- Bonus includes:
- Management of flags
#
,+
, and space (implemented). - Management of flags
-0.
with minimum field width (not implemented).
- Management of flags
- Produces output identical to the standard
printf()
for supported features.
- Written in C, compliant with the 42 Norm.
- No unexpected crashes (e.g., segmentation faults).
- No memory leaks from heap allocations.
- Compiled with
-Wall -Wextra -Werror
. - No buffer management from the original
printf()
.
- C compiler (e.g.,
clang
). make
utility.
-
Clone the repository:
git clone https://github.com/LuizGandra/ft-printf-42.git cd ft-printf-42
-
Build the mandatory part:
make
-
Build the bonus part (optional):
make bonus
-
Link the library to a C project:
clang -o program program.c -L<libftprintf.a directory> -lftprintf
make clean
: remove object files.make fclean
: remove the program and object files.make re
: rebuild everything.
ft_printf.h
: header with function prototype.ft_printf.c
: core logic for ft_printf().ft_putaddress.c
: logic for printing pointers.ft_putchar.c
: logic for printing characters.ft_puthex.c
: logic for hexadecimal output.ft_putnbr.c
: logic for integers (signed/unsigned).ft_putstr.c
: logic for strings.utils.c
: auxiliary functions.Bonus files (e.g., ft_printf_bonus.c)
: additional flag support.Makefile
: compilation automation.
This project is part of the 42 curriculum and intended for educational use.