From 18b4e87be5dde74b8f789332f81aad61e47e79f9 Mon Sep 17 00:00:00 2001 From: Malf Furious Date: Sat, 27 Apr 2019 01:33:02 -0400 Subject: 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 --- hexbin.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'hexbin.c') 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); } -- cgit v1.2.3