recode printf 😲
The versatility of the printf function in C represents a great exercise in programming for us. This project is of moderate difficulty. It will enable you to discover variadic functions in C. The key to a successful ft_printf is a well-structured and good extensible code.
First of all, I wrote this little program just to understand the subject and printf's flags.
Those are the format identifier's I nedd to recode:
% | type |
---|---|
%c | character |
%s | string |
%p | pointer |
%d | decimal signed integer |
%i | integer |
%u | unsigned integer |
%x | hex integer (lowercase) |
%X | hex integer (uppercase) |
%% | just the % |
And those are the flags:
flag | ? |
---|---|
num | (number between % and the identifier) minimum field width |
'-' | left justify |
'0' | field padded with 0's instead of blanks |
'.' | precision |
'*' | indicates that the maximum or minimum field width will be passed as parameter |
For %d and %i, the precision is the minimum number of digits to print.
For %s, the precision is the maximum field width.
To be aware:
- flag '0' is ignored when flag '-' is present
- flag '0' is ignored when flag '.' is present (%d e %i)
- flag '0' results in undefined behavior with '%c', '%s' and '%p'
- flag '.' results in undefined behavior with '%c' and '%p'
(due my researches and empirical tests, 'undefined behavior' means the flags will be ignored, just as the '0' with '-')
Format tags prototype is %|flags| |width| |.precision| |length| |specifier|
The width specification never causes a value to be truncated. If the number of characters in the output value is greater than the specified width, or if width isn't provided, all characters of the value are output.
- printf overview
- secrets of printf
- variadic functions -intro
- va-arg
- layout of directories
- format specification syntax
- %p versus %x
- decimal to hex conversion
clone this repository
git clone https://github.com/paulahemsi/ft_printf.git
and
comand | result |
---|---|
make | compile ftprintf library |
make test | compile and run tests edit your own test here |
make flags | compile and run printf flags example |
make clean | clean .o |
make fclean | clean .o and .a |