A recreation of the standard C library's printf function.
int ft_printf(const char *format, ...)
char *ft_sprintf(char *s, const char *format, ...)
int ft_dprintf(int fd, const char *format, ...)
Run make, which results in library called libftprintf.a. In your source file, use ft_printf() function just as you would use printf(). Furthermore, compile your source code with libftprintf.a to use ft_printf() function. So libftprint.a includes the ft_printf() function.
gcc main.c libftprintf.a
%[flags][width][.precision][length]type
This implementation of printf supports the following:
|
|
|
|
|
The format specifiers %b
is custom. They print binary, respectively.
#include "ft_printf.h"
int main(void)
{
int i;
setlocale(LC_ALL, "");
ft_printf("Hello World!\n");
ft_printf("%s", "This is ");
ft_printf("%.*s\n", 9, "ft_printf and ft_dprintf");
ft_printf("%d\n", 123);
ft_printf("%05d\n", 42);
ft_printf("%+09d\n", 42);
ft_printf("%u\n", UINT_MAX);
ft_printf("%#b\n", 256);
ft_printf("%#o\n", 1039);
ft_printf("%#X\n", 16417188);
ft_printf("%p\n", &i);
return (0);
}
Output:
Hello World!
This is ft_printf
123
00042
+00000042
4294967295
0b100000000
02017
0XFA81A4
0x7fff5c7159e8