Project-Scylla/KNR C/ex1_10.c

30 lines
692 B
C
Raw Permalink Normal View History

#include <stdio.h>
int main(){
int a = 0; /*Initializing a as zero; this doesn't matter because getchar is called at the top of the loop */
while (a != EOF){
a = getchar();
if (a == '\b' || a == '\t' || a == '\\'){ /*Test whether the currently selected character is a tab, backspace, or backslash */
if (a == '\b'){
printf("\\b");
continue;
}
if (a == '\t'){
printf("\\t");
continue;
} else { /*There are only three possible cases here, and by the time we get here, we've tested two, hence an else statement is more efficient than doing another entire if statement*/
printf("\\\\");
continue;
}
} else {
putchar (a);
}
}
return 0;
}