1
0
Fork 0
mirror of https://github.com/tailix/libkernaux.git synced 2024-12-11 11:35:27 -05:00

Improve examples

This commit is contained in:
Alex Kotov 2020-12-07 05:28:44 +05:00
parent de6e1a02d4
commit 75a573a9e0
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 2 additions and 10 deletions

View file

@ -8,7 +8,7 @@
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
static char buffer[BUFFER_SIZE]; static char buffer[BUFFER_SIZE];
static unsigned int buffer_index; static unsigned int buffer_index = 0;
static void my_putchar(const char chr) static void my_putchar(const char chr)
{ {
@ -18,12 +18,8 @@ static void my_putchar(const char chr)
int main() int main()
{ {
memset(buffer, '\0', sizeof(buffer));
buffer_index = 0;
kernaux_printf(my_putchar, "Hello, %s! Session ID: %u.", "Alex", 123); kernaux_printf(my_putchar, "Hello, %s! Session ID: %u.", "Alex", 123);
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0); assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
printf("OK!\n"); printf("OK!\n");
return 0; return 0;
} }

View file

@ -8,7 +8,7 @@
#define BUFFER_SIZE 1024 #define BUFFER_SIZE 1024
static char buffer[BUFFER_SIZE]; static char buffer[BUFFER_SIZE];
static unsigned int buffer_index; static unsigned int buffer_index = 0;
static void my_putchar(const char chr) static void my_putchar(const char chr)
{ {
@ -26,12 +26,8 @@ static void my_printf(const char *const format, ...)
int main() int main()
{ {
memset(buffer, '\0', sizeof(buffer));
buffer_index = 0;
my_printf("Hello, %s! Session ID: %u.", "Alex", 123); my_printf("Hello, %s! Session ID: %u.", "Alex", 123);
assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0); assert(strcmp(buffer, "Hello, Alex! Session ID: 123.") == 0);
printf("OK!\n"); printf("OK!\n");
return 0; return 0;
} }