diff --git a/examples/printf.c b/examples/printf.c index 7f16b3f..54a4f08 100644 --- a/examples/printf.c +++ b/examples/printf.c @@ -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; } diff --git a/src/printf.c b/src/printf.c index 22c7014..278b49a 100644 --- a/src/printf.c +++ b/src/printf.c @@ -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');