From 635a8300a35b7f7b8dfe6191ecc2a2ba050d1963 Mon Sep 17 00:00:00 2001 From: Reina Harrington-Affine Date: Thu, 14 Aug 2025 20:02:00 +0000 Subject: [PATCH] Implemented suggestions from affine. Considerably simplified the program by removing initialization for 'a' prior to loop entry; 'a' is now declared as the initialization expression for the loop, performing a getchar at the same time and preventing a null byte from being printed as the first character (even though this was not visible to the user). --- KNR C/ex1_10_improved.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/KNR C/ex1_10_improved.c b/KNR C/ex1_10_improved.c index 3b0cbbc..2b4ed2d 100644 --- a/KNR C/ex1_10_improved.c +++ b/KNR C/ex1_10_improved.c @@ -4,9 +4,8 @@ * as opposed to a series of if statements*/ int main(){ -int a = 0; /*Initialized as 0 becasue getchar is called both on loop entry, and after every successful execution*/ - for (a = 0; a != EOF; a = getchar()){ + for (int a = getchar(); a != EOF; a = getchar()){ switch (a){ case '\t': printf ("\\t");