diff --git a/KNR C/ex1_10_improved.c b/KNR C/ex1_10_improved.c index acfdb64..3b0cbbc 100644 --- a/KNR C/ex1_10_improved.c +++ b/KNR C/ex1_10_improved.c @@ -4,12 +4,9 @@ * as opposed to a series of if statements*/ int main(){ -int a = 0; /*Initializing a as zero; this doesn't matter because getchar is called at the top of the loop */ +int a = 0; /*Initialized as 0 becasue getchar is called both on loop entry, and after every successful execution*/ - while (a != EOF){ - - a = getchar(); - + for (a = 0; a != EOF; a = getchar()){ switch (a){ case '\t': printf ("\\t"); @@ -20,8 +17,6 @@ int a = 0; /*Initializing a as zero; this doesn't matter because getchar is call case '\b': printf ("\\b"); break; - case EOF: /*Required case for checking if a is EOF, since the loop actually tests whether a = EOF before refreshing a, thus allowing us to enter the loop with the value of a set to EOF */ - break; default: putchar (a); }