tgrekov-ft_printf
HIVE printf Feb 2024
|
Definition in file ft_printf.h.
#include <stdarg.h>
Go to the source code of this file.
Functions | |
int | ft_printf (const char *format,...) |
Prints and formats a variable set of arguments. | |
int ft_printf | ( | const char * | format, |
... | |||
) |
Prints and formats a variable set of arguments.
The format for a specifier is as follows:
%[flags][width][precision][length]specifier
Specifier | Function | Example |
---|---|---|
d or i | Signed decimal integer | -42 |
u | Unsigned decimal integer | 42 |
o | Unsigned octal | 52 |
x | Unsigned hexadecimal integer | 2a |
X | Unsigned uppercase hexadecimal integer | 2A |
c | Character | * |
s | String of characters | Forty-two |
p | Pointer address | 0x2a |
% | A % chracter | % |
n | Nothing is printed. The corresponding argument must be a pointer to a signed integer, which will be set to the number of characters written so far. | |
> | Nothing is printed. The corresponding argument must be a signed integer representing the file descriptor to redirect any remaining output during this call to. |
Flag | Specifiers | Description |
---|---|---|
- | All 1 | Left-justify padding instead of right-justifying. |
+ | d i | Preceed numbers with a + sign if they are not negative. |
(space) | d i | Preceed numbers with a space if no sign is to be written. |
# | o x X | If non-zero, preceed values for o, x, or X specifiers with 0, 0x, or 0X respectively. |
0 | All 1 | Pad with zeroes instead of spaces. Cannot be mixed with precision or left-justification. |
_ | All 1 | Pad with custom string, the address of which is provided in the next function argument. Cannot be mixed with precision or left-justification if used on used with d, i, o, u, x, or X. |
1 With the exception of the n and > specfiers, as they do not print anything.
Width | Description |
---|---|
(number) | Minimum number of characters to print. Pads to reach this number. |
* | The minimum width should be retrieved from the next function argument. |
.precision | Description |
---|---|
.number | For d, i, o, u, x, or X, the minimum number of digits to write. If the value is shorter than this number, it is padded with leading zeros. For a precision of 0, nothing is written if the value is 0. For s, the maximum number of characters to be printed. |
* | The precision should be retrieved from the next function argument. |
Specifiers | |||||||
---|---|---|---|---|---|---|---|
Length | d i | u o x X | c | s | p | n | > |
(none) | int | unsigned int | int | char * | void * | int * | int |
hh | char | unsigned char | signed char * | ||||
h | short | unsigned short | short * | ||||
l | long | unsigned long | long * | ||||
ll | long long | unsigned long long | long long * | ||||
j | intmax_t | uintmax_t | intmax_t * | ||||
z | size_t | size_t * | |||||
t | ptrdiff_t | ptrdiff_t * |
[in] | format | Null terminated string containing text to print and, optionally, conversion specifiers and subspecifiers. See extended description. |
[in,out] | ... | Variable amount of arguments of various types, dependent on the format . |
int | Number of characters printed, or -1 if an error occurs. |
Definition at line 252 of file ft_printf.c.
References do_segment().