1
0
Fork 0
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:
Alex Kotov 2020-12-07 05:04:24 +05:00
parent 771d0336ca
commit 0ce7f19b49
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
2 changed files with 11 additions and 0 deletions

View file

@ -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*);

View file

@ -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;
}