Skip to content

ft_Printf

Iva edited this page Sep 27, 2024 · 2 revisions

ft_printf

Mimics printf function in C:
Prints a formatted string to stdout, supporting various format specifiers like %d, %s, and %x.

Original Function:

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.

Usage Example:

int len = ft_printf("Text: %s, Number: %d\n", "Hello", 42); // Prints "Text: Hello, Number: 42"

Specifics:

Loops through the format string and prints characters until it finds a format specifier (%).
The ck_format function handles the format specifier and prints the corresponding argument from the variadic list.


ck_format

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.

Original Function:

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.

Usage Example:

int printed = ck_format(args, 'd'); // Processes and prints the integer from the variadic arguments.

Specifics:

Supports format specifiers for integers (%d), characters (%c), strings (%s), unsigned integers (%u), pointers (%p), and hexadecimal (%x and %X).

Previous ⬅️ Top ⬆️ Next ➡️

Clone this wiki locally