1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-11-13 11:04:27 -05:00
libkernaux/examples/printf.c

25 lines
537 B
C
Raw Normal View History

2020-12-06 17:24:43 -05:00
#include <kernaux/printf.h>
#include <assert.h>
2022-01-19 07:01:21 -05:00
#include <stddef.h>
2020-12-06 17:24:43 -05:00
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 1024
static char buffer[BUFFER_SIZE];
2021-12-16 10:26:16 -05:00
static size_t buffer_index = 0;
2020-12-06 17:24:43 -05:00
2022-01-19 17:19:14 -05:00
static void my_putchar(const char chr, void *arg __attribute__((unused)))
2020-12-06 17:24:43 -05:00
{
if (buffer_index >= BUFFER_SIZE) abort();
buffer[buffer_index++] = chr;
}
int main()
{
2022-01-19 07:01:21 -05:00
kernaux_printf(my_putchar, NULL, "Hello, %s! Session ID: %u.", "Alex", 123);
2020-12-06 19:22:52 -05:00
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
2020-12-06 17:24:43 -05:00
return 0;
}