aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2018-02-24 02:04:45 +1300
committerTom Ryder <tom@sanctum.geek.nz>2018-02-24 02:04:45 +1300
commitf79b4417537c189b12f3aad25cde7c51da50944a (patch)
tree75735387daaca85ef14ee8147b56a16a2a2e2610
parentTerser while loop (diff)
downloadwtf8-f79b4417537c189b12f3aad25cde7c51da50944a.tar.gz
wtf8-f79b4417537c189b12f3aad25cde7c51da50944a.zip
Refactor print_octets to avoid awkward cast
-rw-r--r--wtf8.c14
1 files changed, 5 insertions, 9 deletions
diff --git a/wtf8.c b/wtf8.c
index 40db322..b8839ce 100644
--- a/wtf8.c
+++ b/wtf8.c
@@ -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;
}