diff options
author | Malf Furious <m@lfurio.us> | 2019-04-27 01:33:02 -0400 |
---|---|---|
committer | Malf Furious <m@lfurio.us> | 2019-04-27 01:33:02 -0400 |
commit | 18b4e87be5dde74b8f789332f81aad61e47e79f9 (patch) | |
tree | 2906f10376b26d225fe5ddf6d6602caaf23b83d4 | |
parent | ad7743dfc1dc3f35a664545c827f362e45dbe073 (diff) | |
download | lib-des-gnux-18b4e87be5dde74b8f789332f81aad61e47e79f9.tar.gz lib-des-gnux-18b4e87be5dde74b8f789332f81aad61e47e79f9.zip |
More robust hexbin program
Removed the intermediate char buffer, just scanf() stdin directly. This
handles newlines and arbitrary formatting/whitespace much better than
the previous version.
Signed-off-by: Malf Furious <m@lfurio.us>
-rw-r--r-- | hexbin.c | 6 |
1 files changed, 1 insertions, 5 deletions
@@ -11,16 +11,12 @@ int main() { uint8_t b; - char ip[3] = {0}; while (1) { - fread(ip, 1, 2, stdin); - + scanf("%hhx", &b); if (feof(stdin)) break; - - sscanf(ip, "%hhx", &b); fwrite(&b, 1, 1, stdout); } |