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

  1. /*               return1.c
  2.  *
  3.  *   Synopsis  - Positions input stream to either the character
  4.  *               after '#' or at the end of the input line.
  5.  *
  6.  *   Objective - To illustrate the simplest form of the
  7.  *               return statement.
  8.  */
  9.  
  10. /* Include Files */
  11. #include <stdio.h>
  12.  
  13. /* Constant Definitions */
  14. #define END_OF_LINE  '\n'
  15. #define DELIMITER    '#'
  16.  
  17. /* Function Prototypes */
  18. void look_for_delimiter( char delimiter, char end_of_line );
  19. /*   PRECONDITION:  delimiter and end_of_line can be any character 
  20.  *                  variables.
  21.  *
  22.  *   POSTCONDITION: Reads a line of text, character by character. 
  23.  *                  Returns when delimiter is found in the input.
  24.  */
  25.  
  26. int main( void )
  27. {
  28.                                                      /* Note 1 */
  29.      printf( "Enter a line of text with a %c.\n> ", DELIMITER );
  30.      look_for_delimiter( DELIMITER, END_OF_LINE );
  31.      printf( "Done looking!\n" );                    /* Note 1 */
  32.      return 0;
  33. }
  34.  
  35. /*******************************look_for_delimiter()************/
  36.  
  37. void look_for_delimiter( char delimiter, char end_of_line )
  38. {
  39.      int iochar;
  40.  
  41.      while ( ( iochar = getchar() ) != end_of_line ) {
  42.           if ( iochar == delimiter )
  43.                return;                               /* Note 2 */
  44.      }
  45.      printf( "At end of line\n" );                   /* Note 3 */
  46. }
  47.