ft_printf
A custom implementation of the standard C printf function, managing variadic arguments and complex string formatting.
2021-06-01
low-levelOpen GitHub

ft_printf
A reimplementation of printf in C without touching any formatted-output functions. It walks the format string character by character, and when it finds a % it dispatches to the right handler for that specifier.
Supported conversions
| Specifier | Output |
|---|---|
| %c | Single character |
| %s | String (prints (null) for NULL pointers) |
| %p | Pointer in hex |
| %d / %i | Signed decimal integer |
| %u | Unsigned decimal integer |
| %x | Hex lowercase |
| %X | Hex uppercase |
| %% | Literal percent sign |
Signature
int ft_printf(const char *format, ...);Returns the number of characters written, or -1 on error. Same contract as the real printf.
How it works
ft_printf("Dec: %d | Hex: %x\n", 42, 42)
| |
| ft_hexalow(42) -> "2a"
ft_putnbr(42) -> "42"
Usage
#include "ft_printf.h"
ft_printf("Hello, %s!\n", "world");
ft_printf("Dec: %d | Hex: %x | Ptr: %p\n", 255, 255, &main);make
gcc main.c libftprintf.a -o programSCREENSHOTS // 01 FRAMES

01 / 01