Rewrote while loop as a for loop to reduce overall program size.

This commit is contained in:
Reina Harrington-Affine 2025-08-14 19:52:12 +00:00
parent d6f81778ef
commit abc0ac1660

View file

@ -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);
}