home *** CD-ROM | disk | FTP | other *** search
/ C by Discovery (4th Edition) / C_By_Discovery_4th_Edition.tar / C_By_Discovery_4th_Edition / _DISK_ / ch8 / classify.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  40 lines

  1. /*                           classify.c
  2.  *
  3.  *   Synopsis  - Reads through English sentence input and counts
  4.  *               each sentence that ends with '.', '?', or '!'
  5.  *               as a statement, a question, or an exclamation.
  6.  *
  7.  *   Objective - To illustrate checking the return value of a 
  8.  *               function as well as the value of a parameter.
  9.  */
  10.  
  11. /* Include Files */
  12. #include <stdio.h>
  13.  
  14. /* Function Prototypes */
  15. extern int endofsen( int *punctptr );
  16.  
  17. int main( void )
  18. {
  19.      int punct;
  20.      int statementcounter = 0,
  21.          questioncounter  = 0,
  22.          exclaimcounter   = 0;
  23.  
  24.      printf( "Enter English sentences as input.  " );
  25.      printf( "Terminate input with an End of File mark.\n" );
  26.  
  27.      while ( endofsen( &punct )) {                           /* Note 1 */
  28.           if ( punct == '.' )                                /* Note 2 */
  29.                statementcounter++;
  30.           else if ( punct == '?' )
  31.                questioncounter++;
  32.           else if ( punct == '!' )
  33.                exclaimcounter++;
  34.      }
  35.      printf( "\n%d statements, %d questions, ", 
  36.                                         statementcounter, questioncounter );
  37.      printf( "and %d exclamations.\n",  exclaimcounter );
  38.      return 0;
  39. }
  40.