-
Notifications
You must be signed in to change notification settings - Fork 0
ft_Printf
Iva edited this page Sep 27, 2024
·
2 revisions
Mimics
printf
function in C:
Prints a formatted string to stdout, supporting various format specifiers like%d
,%s
, and%x
.
Library | <stdio.h> |
---|---|
Signature | int ft_printf(const char *format, ...); |
Parameters |
format : A format string containing plain text and format specifiers to indicate the type of the variadic arguments. |
Return | The total number of characters printed. |
int len = ft_printf("Text: %s, Number: %d\n", "Hello", 42); // Prints "Text: Hello, Number: 42"
Loops through the
format
string and prints characters until it finds a format specifier (%
).
Theck_format
function handles the format specifier and prints the corresponding argument from the variadic list.
Handles and processes format specifiers in
ft_printf
:
Processes each format specifier (e.g.,%d
,%s
,%x
) and prints the corresponding argument from the variadic list.
Library | None (Internal helper function) |
---|---|
Signature | int ck_format(va_list args, char specifier); |
Parameters |
args : A va_list containing the variadic arguments passed to ft_printf . |
specifier : The format specifier indicating the type of argument to be processed (e.g., d , s , x ). |
|
Return | The number of characters printed for the argument. |
int printed = ck_format(args, 'd'); // Processes and prints the integer from the variadic arguments.
Supports format specifiers for integers (
%d
), characters (%c
), strings (%s
), unsigned integers (%u
), pointers (%p
), and hexadecimal (%x
and%X
).
Previous ⬅️ • Top ⬆️ • Next ➡️