#include #include "mylib.h" /* Description: Write a program to copy its input to its output, replacing each tab by \t, each backspace by \b, each backslash by \\, and each strinf of one or more blanks by a single blank. This makes tabs and backspaces visible in an unambiguous way. Author : ****************** Date : September 3, 2006 */ /* count lines in input */ int main( int argv, char *argc[] ) { /* * Variables declarations */ sh_int last_c; /* ascii value of the last character */ sh_int curr_c; /* ascii value of the current character */ sh_int state; /* state, do we have a special character or not? */ printf( "Enter the text you wish to convert to a printf string and hit ctrl+d to see\n theoutput\n" ); printf( "-------------------------------------------------------------------------------\n" ); while( ( curr_c = getchar( ) ) != EOF ) { state = 0; if( curr_c == '\\' ) { state = 1; putchar( '\\' ); putchar( '\\' ); } if( curr_c == '\t' ) { state = 1; putchar( '\\' ); putchar( 't' ); } if( curr_c == '\b' ) { state = 1; putchar( '\\' ); putchar( 'b' ); } if( curr_c == '\n' ) { state = 1; putchar( '\\' ); putchar( 'n' ); } if( curr_c == ' ' ) { if( last_c == ' ' ) { state = 1; } last_c = ' '; } if( !state ) { putchar( curr_c ); } } printf( "\n-------------------------------------------------------------------------------\n" ); printf( "Your printf string is above\n" ); return 0; }