2025-08-14 21:54:38 +00:00
# include <stdio.h>
# include <stdlib.h>
/*A really silly way to complete exercise 1-10 of KNR C*/
int main ( ) {
2025-08-14 22:05:46 +00:00
int a = getchar ( ) ; /*There is, unfortuately, no immediately obvious way to avoid repeating this since we need to initialize 'a' in order to have valid data for everything beyond this line*/
2025-08-14 21:54:38 +00:00
if ( a = = EOF ) { /*Check whether first character is EOF*/
2025-08-14 22:05:46 +00:00
printf ( " Error: No data to parse. \n Exiting. " ) ;
EXIT_FAILURE ; /*Exit if there is no data to parse.*/
2025-08-14 21:54:38 +00:00
}
2025-08-14 22:05:46 +00:00
loop_start : /*Goto will circle back to the next line if a != EOF*/
2025-08-14 21:54:38 +00:00
if ( a = = ' \t ' | | a = = ' \b ' | | a = = ' \\ ' ) {
if ( a = = ' \t ' )
printf ( " \\ t " ) ;
2025-08-14 22:05:46 +00:00
if ( a = = ' \b ' ) {
2025-08-14 21:54:38 +00:00
printf ( " \\ b " ) ;
2025-08-14 22:05:46 +00:00
}
2025-08-14 21:54:38 +00:00
if ( a = = ' \\ ' )
printf ( " \\ \\ " ) ;
} else {
putchar ( a ) ;
}
a = getchar ( ) ;
2025-08-14 22:05:46 +00:00
if ( a ! = EOF ) /*Only trigger next loop if 'a' contains valid data.*/
2025-08-14 21:54:38 +00:00
goto loop_start ;
return 0 ;
}