Untested initial version of code for visibility.
This commit is contained in:
parent
635a8300a3
commit
2638922bbe
1 changed files with 34 additions and 0 deletions
34
KNR C/ex1_10_goto.c
Normal file
34
KNR C/ex1_10_goto.c
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/*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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue