Modify the program so that some normally legitimate character is bad.
Do this by altering the if
statement.
if ( (isprint( ch ) || ch == '\t' || ch == '\n' || ch == '\r') && ch != '%' )
Now, the character %
will be regarded as bad.
Create a test file and insert some %
characters into it.
Better testing could be done by creating a program, similar to the above, that inserts bad characters using the hex value. Do something like
putchar( 0xFF )
to put a non-ascii value into a file. Use file redirection to create a bad file from a good text file.
#include <stdio.h> /* Replace '@' in a text file with byte not allowed in text files */ void main( void ) { int ch; while ( (ch = getchar()) != EOF ) { if ( ch == '@' ) putchar( 0xFF ); else putchar( ch ); } }
Often to test a program you have to write additional programs that produce testing data.