libkernaux/examples/printf.c

24 lines
482 B
C
Raw Normal View History

2020-12-06 22:24:43 +00:00
#include <kernaux/printf.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 1024
static char buffer[BUFFER_SIZE];
2020-12-07 00:28:44 +00:00
static unsigned int buffer_index = 0;
2020-12-06 22:24:43 +00:00
static void my_putchar(const char chr)
{
if (buffer_index >= BUFFER_SIZE) abort();
buffer[buffer_index++] = chr;
}
int main()
{
2020-12-07 00:22:52 +00:00
kernaux_printf(my_putchar, "Hello, %s! Session ID: %u.", "Alex", 123);
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
2020-12-06 22:24:43 +00:00
return 0;
}