This project is pretty straightforward. It asks students to recode printf()
in order to make them learn about how a variadic function works. It also aims to make students think about how they are going to implement the project. After all, the key to a successful ft_printf
is a well-structured and extensible code.
Inside the folder ft-printf-studies
there is a file that test all the possible combinations of printf
flags.
- ✅ The function has to implement the following conversions:
cspdiuxX%
Conversion | Description |
---|---|
c |
Prints a single character. |
s |
Prints a string (as defined by the common C convention). |
p |
The void * pointer argument has to be printed in hexadecimal format. |
d |
Prints a decimal (base 10) number. |
i |
Prints an integer in base 10. |
u |
Prints an unsigned decimal (base 10) number. |
x |
Prints a number in hexadecimal (base 16) lowercase format. |
X |
Prints a number in hexadecimal (base 16) uppercase format. |
% |
Prints a percent sign. |
- ❌ Manage any combination of the following flags:
-0.
and the field minimum width under all conversions.
Flag | Description |
---|---|
- |
Left aligns the argument passed. |
0 |
Add '0' as a padding character in numeric conversions (single space is default). |
. |
Precision definition, followed by a number. |
- ✅ Manage all the following flags:
# +
(Yes, one of them is a space).
Flag | Description |
---|---|
' ' |
Adds a single space (' ' ) in the front of positive numeric conversions. |
# |
Adds the corresponding prefix in front of x and X conversions. |
+ |
Adds a plus sign (+ ) in the front of positive numeric conversions. |
Run make
or make bonus
if you want to compile the mandatory project or the bonus project respectively.
After that, to use the ft_printf()
in your project it's necessary to include the library libftprintf.a
and the header as follows:
#include "ft_printf.h"
If you want to include the bonus version, use:
#include "ft_printf_bonus.h"
Don't forget to add the following flags when compiling your project:
gcc ... -lftprintf -L path/to/libftprintf.a -I path/to/libftprintf.h
-
Criando Funções Com Número Variável De Argumentos Em C by Daemonio Labs.
-
Formatted output in 12. Input/Output on Streams by The GNU C Library Reference Manual.
-
COLTON, Don. Secrets of “printf”. Brigham Young University Hawaii, 2014.
-
To test the project features, I used the ft_printf_tester made by Paulo Santana.