tgrekov-ft_printf
HIVE printf Feb 2024
Loading...
Searching...
No Matches
ft_printf.h File Reference

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/31 23:08:39 by tgrekov #+# #+# */
/* Updated: 2024/02/13 09:06:38 by tgrekov ### ########.fr */
/* */
/* ************************************************************************** */

Definition in file ft_printf.h.

#include <stdarg.h>
Include dependency graph for ft_printf.h:

Go to the source code of this file.

Functions

int ft_printf (const char *format,...)
 Prints and formats a variable set of arguments.
 

Function Documentation

◆ ft_printf()

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 charsigned char *
h short unsigned shortshort *
l long unsigned longlong *
ll long long unsigned long long

long long *
j intmax_t uintmax_tintmax_t *
zsize_tsize_t *
tptrdiff_tptrdiff_t *
Parameters
[in]formatNull 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.
Return values
intNumber of characters printed, or -1 if an error occurs.

Definition at line 252 of file ft_printf.c.

References do_segment().

Here is the call graph for this function: