https://github.com/llefranc/42_ft_printf
School project: reimplement printf in C (with all the bonuses, including the floats and Dragon4 algorithm).
https://github.com/llefranc/42_ft_printf
42 42born2code 42paris 42school dragon4-algorithm float floating-point ft-printf printf printf-42
Last synced: 10 months ago
JSON representation
School project: reimplement printf in C (with all the bonuses, including the floats and Dragon4 algorithm).
- Host: GitHub
- URL: https://github.com/llefranc/42_ft_printf
- Owner: llefranc
- Created: 2020-11-25T12:57:36.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-01-04T12:51:29.000Z (almost 5 years ago)
- Last Synced: 2025-01-16T21:40:29.021Z (11 months ago)
- Topics: 42, 42born2code, 42paris, 42school, dragon4-algorithm, float, floating-point, ft-printf, printf, printf-42
- Language: C
- Homepage:
- Size: 1.26 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ft_printf (@42Paris)
"Because putnbr and putstr aren’t enough"

## About
Ft_printf is a project of the mandatory part of the 42cursus.
The main goal is to recreate the printf function in C.
In this case we had to understand how the different parameters in printf works (width, height...).
This ft_printf handles all the bonuses from the subject.
- Ft_printf will be able to work with :
- Flags : -, 0, ., *
- Conversions : %c, %s, %p, %d, %i, %u, %x, %X, %%
- Bonus flags : l, ll, h, hh, #, +, and space
- Bonus conversions : %n, %f, %e, %g
You can do combination between width / heigh / flags and conversions like the real printf.
For the bonus flag l, I had to implement the wide_char conversion for ls and lc combination.
My ft_printf can so print unicode characters.
For the bonuses %f %e and %g (float conversion), I implemented the Dragon4 algorithm.
My implementation of the Dragon4 algorithm works like the real printf, so this ft_printf is able to print all the possible floats :
from DBL_MAX (max double) to DBL_MIN (which will print 1024 numbers after the dot !).
In this case, I created a library (called BIG_INT library) that can do calculation on strings filled with number.
This was necessary because floats algorithm needs to represent bigger number than possible with a long long int.
The BIG_INT library is able to perfom addition, subtraction, multiplication, division and pow.
- Here is the [subject][1]
`This project was code for MACOS`
### Building and running the project
1. Download/Clone this repo
git clone https://github.com/lucaslefrancq/42_ft_printf
2. `cd` into the root directory, and run `make`
cd 42_ft_printf
make
3. Compile your `main.c` with the lib `libftprintf.a` created
gcc -Wall -Werror -Wextra main.c libftprintf.a
## Sources
- [Format specification syntax for printf][2]
- [Printing floating point numbers][3]
- [Comprendre les encodages et unicode (FR)][4]
- [Understanding unicode][5]
[1]: https://github.com/lucaslefrancq/42_ft_printf/blob/main/ft_printf.en.subject.pdf
[2]: https://docs.microsoft.com/fr-fr/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?view=msvc-160
[3]: http://www.ryanjuckett.com/programming/printing-floating-point-numbers/
[4]: https://zestedesavoir.com/tutoriels/1114/comprendre-les-encodages/
[5]: https://betterexplained.com/articles/unicode/