mirror of https://github.com/tailix/libkernaux.git
Temporary implementation of %s formatter
This commit is contained in:
parent
d3f6951dbe
commit
a1b373e49a
|
@ -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;
|
||||
}
|
||||
|
|
14
src/printf.c
14
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;
|
||||
|
||||
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');
|
||||
|
|
Loading…
Reference in New Issue