diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2018-02-24 02:04:45 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2018-02-24 02:04:45 +1300 |
commit | f79b4417537c189b12f3aad25cde7c51da50944a (patch) | |
tree | 75735387daaca85ef14ee8147b56a16a2a2e2610 | |
parent | Terser while loop (diff) | |
download | wtf8-f79b4417537c189b12f3aad25cde7c51da50944a.tar.gz wtf8-f79b4417537c189b12f3aad25cde7c51da50944a.zip |
Refactor print_octets to avoid awkward cast
-rw-r--r-- | wtf8.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -13,19 +13,15 @@ int is_utf8_cont(char c) { * trailing space, ending with a newline */ void print_octets(char *s) { + unsigned char c; /* - * Iterate through the string, printing each octet - */ - for (; *s; s++) { - putchar(is_utf8_cont(*s) ? '-' : ' '); - printf("%02x", (unsigned char) *s); - } - - /* - * End with a newline + * Iterate through the string, printing each octet, ending with a newline */ + while (c = *s++) + printf("%c%02x", (is_utf8_cont(c) ? '-' : ' '), c); putchar('\n'); + return; } |