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

  1. /*                            listit.c
  2.  *
  3.  *   Synopsis  - Masks out the high bit on characters
  4.  *               WP_LINEFEED and WP_CARRETURN and deletes other
  5.  *               characters with the high bit set while copying
  6.  *               input to output.
  7.  *
  8.  *   Objective - Illustrates use of masks with bit operations.
  9.  */
  10.  
  11. /*  Include Files */
  12. #include <stdio.h>
  13.  
  14. /* Constant Definitions */
  15. #define HIGHBIT                         128          /* Note 1 */
  16. #define NOHIGHBIT                    127
  17. #define WP_LINEFEED                  138
  18. #define WP_CARRETURN                 141
  19. int main( void )
  20. {
  21.      int iochar;
  22.  
  23.      while ( ( iochar = getchar() ) != EOF ) {
  24.           if ( HIGHBIT & iochar ) {               /* Note 2 */
  25.                if ( ( iochar == WP_LINEFEED ) ||
  26.                               ( iochar == WP_CARRETURN ) )
  27.                                                   /* Note 3 */
  28.                     putchar( iochar & NOHIGHBIT );
  29.           }                                       /* Note 4 */
  30.           else
  31.                     putchar( iochar );
  32.      }
  33.      return 0;
  34. }
  35.