Project-Scylla/KNR C/ex1_10_improved.c

26 lines
515 B
C
Raw Normal View History

#include <stdio.h>
/*Alternative (challenge) implementation of exercise 1-10 using a switch statement
* 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()){
switch (a){
case '\t':
printf ("\\t");
break;
case '\\':
printf ("\\\\");
break;
case '\b':
printf ("\\b");
break;
default:
putchar (a);
}
}
return 0;
}