A project that consists on creating a replica of the printf
function.
Well... A very limited version of it.
First, let's see the general instructions that apply to ft_printf:
- The Makefile must not relink (Unnecesary recompilations).
- The function must never crash nor have undefined behavior (This project has an exception to this rule).
- The code must be written following norminette requirements.
- Memory leaks are an issue, so no leaks are allowed, even if the function fails.
Now, the specific instructions for ft_printf:
- The only allowed to use functions are
malloc
,free
,write
,va_start
,va_arg
,va_copy
andva_end
. - The behavior of
printf
must be replicated, so ifprintf
crashes, this function should crash too, the return value must also be the same. - The use of libft is allowed. But I decided to use new functions.
- ONLY the following conversions must be handled: %c, %s, %p, %d, %i, %u, %x, %X and %%
This project teaches us how to use variable arguments with
va_start
, va_arg
, va_copy
and va_end
.
Even though I didn't need to use va_copy
.
This project includes a test file, test_printf.c
. You can compile all
files with something like gcc *.c
and run the executable to see if this
project behaves exactly as the printf
function. This cannot be compiled
with error flags as it intentionally uses weird values.
~ This file is ignored by Codacy, as it has intentionally bad code quality. This was a fast solution, a proper tester is preferred over it.