summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2019-04-27 01:33:02 -0400
committerMalf Furious <m@lfurio.us>2019-04-27 01:33:02 -0400
commit18b4e87be5dde74b8f789332f81aad61e47e79f9 (patch)
tree2906f10376b26d225fe5ddf6d6602caaf23b83d4
parentad7743dfc1dc3f35a664545c827f362e45dbe073 (diff)
downloadlib-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.c6
1 files changed, 1 insertions, 5 deletions
diff --git a/hexbin.c b/hexbin.c
index d312438..9356fff 100644
--- a/hexbin.c
+++ b/hexbin.c
@@ -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);
}