1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2026-08-15 11:00:07 -04:00

Add "examples/snprintf[_va].c"

This commit is contained in:
Alex Kotov 2022-01-20 15:28:24 +05:00
parent b3aed09ce9
commit d1105f1cc6
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
5 changed files with 61 additions and 3 deletions

22
examples/snprintf.c Normal file
View file

@ -0,0 +1,22 @@
#include <kernaux/printf.h>
#include <assert.h>
#include <string.h>
#define BUFFER_SIZE 1024
static char buffer[BUFFER_SIZE];
int main()
{
const int result = kernaux_snprintf(
buffer,
sizeof(buffer),
"Hello, %s! Session ID: %u.",
"Alex",
123
);
assert((size_t)result == strlen(buffer));
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
return 0;
}