mirror of
https://github.com/tailix/libkernaux.git
synced 2024-10-30 11:54:01 -04:00
Implement %u formatter
This commit is contained in:
parent
771d0336ca
commit
0ce7f19b49
2 changed files with 11 additions and 0 deletions
10
src/printf.c
10
src/printf.c
|
@ -195,6 +195,16 @@ void kernaux_printf_va(
|
|||
if (formatter.type == TYPE_PERCENT) {
|
||||
putchar('%');
|
||||
}
|
||||
else if (formatter.type == TYPE_u) {
|
||||
const unsigned int arg = va_arg(va, unsigned int);
|
||||
|
||||
char buf[20];
|
||||
kernaux_itoa(arg, buf, 'd');
|
||||
|
||||
for (const char *arg_ptr = buf; *arg_ptr; ++arg_ptr) {
|
||||
putchar(*arg_ptr);
|
||||
}
|
||||
}
|
||||
else if (formatter.type == TYPE_s) {
|
||||
const char *const arg = va_arg(va, char*);
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ int main()
|
|||
test("Hello, Alex!", "Hello, %s!", "Alex");
|
||||
test("Hello, Alex!", "Hello, %c%c%c%c!", 'A', 'l', 'e', 'x');
|
||||
test("%", "%%");
|
||||
test("123", "%u", 123);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue