diff --git a/KNR C/ex1_10_goto.c b/KNR C/ex1_10_goto.c new file mode 100644 index 0000000..8a2d38e --- /dev/null +++ b/KNR C/ex1_10_goto.c @@ -0,0 +1,34 @@ +#include +#include + +/*A really silly way to complete exercise 1-10 of KNR C*/ + +int main(){ + + int a = getchar(); + + if (a == EOF){ /*Check whether first character is EOF*/ + printf ("No data to parse."); + EXIT_FAILURE; + } + +loop_start: + if (a == '\t' || a == '\b' || a == '\\'){ + if (a == '\t') + printf("\\t"); + if (a == '\b') + printf("\\b"); + if (a == '\\') + printf ("\\\\"); + } else { + putchar(a); + } + + a = getchar(); + + if (a != EOF) + goto loop_start; + + + return 0; +}