An open API service indexing awesome lists of open source software.

https://github.com/xdec0de/42printf

[42] My own (Very limited) version of printf
https://github.com/xdec0de/42printf

42 42born2code 42cursus 42school c ftprintf ftprintf42 printf printf42

Last synced: about 1 month ago
JSON representation

[42] My own (Very limited) version of printf

Awesome Lists containing this project

README

        

# 42 - ft_printf

A project that consists on creating a replica of the `printf` function.
Well... A very limited version of it.



CodeFactor


Codacy

## Project instructions

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](https://github.com/42School/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` and `va_end`.
- The behavior of `printf` must be replicated, so if `printf` crashes,
this function should crash too, the return value must also be the same.
- The use of [libft](https://github.com/xDec0de/42libft) 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 %%

## What I learned

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`.

## Testing the project

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.