Temporary implementation of %s formatter

This commit is contained in:
Alex Kotov 2020-12-07 03:30:15 +05:00
parent d3f6951dbe
commit a1b373e49a
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 17 additions and 3 deletions

View File

@ -19,8 +19,8 @@ int main()
{
memset(buffer, '\0', sizeof(buffer));
buffer_index = 0;
kernaux_printf(my_putchar, "Hello, World!");
assert(strcmp(buffer, "Hello, World!") == 0);
kernaux_printf(my_putchar, "Hello, %s!", "Alex");
assert(strcmp(buffer, "Hello, Alex!") == 0);
return 0;
}

View File

@ -19,7 +19,21 @@ void kernaux_printf_va(
for (const char *current_ptr = format; *current_ptr; ++current_ptr) {
const char current = *current_ptr;
putchar(current);
if (current != '%') {
putchar(current);
continue;
}
if (*(++current_ptr) == 's') {
const char *const arg = va_arg(va, const char*);
for (const char *arg_ptr = arg; *arg_ptr; ++arg_ptr) {
putchar(*arg_ptr);
}
}
else {
break;
}
}
putchar('\0');