go to previous page   go to home page   go to next page

Answer:

Probably best to pass it as an argument.


Complete Program

Here is the complete program. Legal characters for this program are all printable characters, and selected whitespace (tab, newline, and carriage return.) This allows in some characters that are not in legal C, but might be in comments.

#include <stdio.h>

void putBad( char *msg )
{
  int j;
  for ( j=0; msg[j]; j++ )
    putchar( msg[j] );
}

void main( void )
{
  int ch;

  while ( (ch = getchar()) != EOF )
  {
    if ( isprint( ch ) || ch == '\t' || ch == '\n' || ch == '\r' )
    {
      putchar( ch );
    }
    else
    {
      putBad( "/* BAD */");
    }
  }
}

QUESTION 17:

How can this program be tested? What if you have no files with bad characters?