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 / continue.c < prev    next >
C/C++ Source or Header  |  2005-06-16  |  1KB  |  44 lines

  1. /*              continue.c
  2.  *
  3.  *   Synopsis  - Echoes its input to its output with each tab
  4.  *               character replaced with '\t'.
  5.  *
  6.  *   Objective - To illustrate the continue statement.
  7.  */
  8.  
  9. /* Include Files */
  10. #include <stdio.h>
  11.  
  12. /* Function Prototypes */
  13. void showtabsinline( void );
  14. /*   PRECONDITION:  none
  15.  *
  16.  *   POSTCONDITION: Reads and echoes a line of text from standard 
  17.  *                  input. Every tab character in the input is replaced 
  18.  *                  by the two characters '\' and 't'.
  19.  */
  20.  
  21. int main( void )
  22. {
  23.      printf( "Enter a line with tab characters in it.\n\n" );
  24.      showtabsinline();
  25.      return 0;
  26. }
  27.  
  28. /*******************************showtabsinline()****************/
  29.  
  30. void showtabsinline( void )
  31. {
  32.      int iochar;
  33.  
  34.      while ( ( iochar = getchar() ) != '\n' ) {
  35.           if ( iochar == '\t' ) {
  36.                putchar( '\\' );
  37.                putchar( 't' );
  38.                continue;                          /* Note 1 */
  39.           }
  40.           putchar( iochar );                      /* Note 2 */
  41.      }
  42.      putchar( '\n' );
  43. }
  44.