Replicated functional of
int printf(const char *format, ...);
Using just 6 standard C library functions
ssize_t write(int fd, const void *buf, size_t count);
void *malloc(size_t size);
void free(void *ptr);
void va_start(va_list ap, argN);
argT va_arg(va_list ap, argT);
void va_end(va_list ap);
- conversions
i
d
o
u
x
f
c
s
p
%
- more conversions
D
F
X
S
C
O
U
- flags
+
space
-
#
- length modifiers
hh
h
l
ll
L
q
j
z
t
- precision and field width. Value of which replaced with
*
will be taken from arguments list, just as inptintf
r
requires (char*), outputs it with unprintable symbols
ft_printf("the true symbols of %r", " new line \012, tab \011, start of text \002");
b
requires (unsigned int), outputs it in binary
ft_printf("5 in binary looks like %#b, and 9999 is definitely %b", 5, 9999);
- available colors
white
black
red
green
yellow
blue
magenta
cyan
- available text transformations
bold
Use [color
[colorb
[trsf
to specify text, background color and text transformation accordingly. Color should not be followed by lowercase letters. Specify the end of formatting with ~]
ft_printf("[blueb[white Ukra~][yellowb[whiteIne ~][green,[red[bold %s~]", "yep");
ft_printf("unspecified conversion %ll", 123);
ft_printf("multiple specifications %+++.1.6.f", 99.5556);
ft_printf("wrong specifications %+X", 775);
ft_printf("wrong order of specification %hh3ll17S", L"¥ ¢ £ ¤ ¶");
My implementation is easily modifiable. To add new functionality, just add a symbol to the categorizing defines and corresponding function pointer to the array of functions
Those are the only places, that have to be modified to add new functionality (conversions, length modifiers, and flags)
Download and run withclang main.c libftprintf.a
Tested for compatibility with MacOS 10.12, Ubuntu 18.04.1