Project-Scylla/KNR C/ex1_10_improved.c

24 lines
412 B
C

#include <stdio.h>
/*Alternative (challenge) implementation of exercise 1-10 using a switch statement
* as opposed to a series of if statements*/
int main(){
for (int a = getchar(); a != EOF; a = getchar()){
switch (a){
case '\t':
printf ("\\t");
break;
case '\\':
printf ("\\\\");
break;
case '\b':
printf ("\\b");
break;
default:
putchar (a);
}
}
return 0;
}