home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 171_01 / addlf.c < prev    next >
Text File  |  1983-10-27  |  640b  |  25 lines

  1. /* addlf -- copy input to output; add line-feeds only if necessary.
  2.  *        WHRauser   10-4-83           a better mouse trap.
  3.  */
  4. #include <stdio.h>       /* Microsoft C  Ver 1.04 */
  5.  
  6. #define  CR  0x000D       /* carriage return */
  7. #define  LF  0x000A       /* line feed */
  8. #define  TRUE      1
  9. #define  FALSE      0
  10.  
  11. main()        /* copy input to output and add line-feeds only if needed. */
  12. {
  13.     int  c;
  14.     int  addlf = FALSE;
  15.  
  16.     while ((c = getchar()) != EOF) {
  17.      if (addlf  &  c != LF) {
  18.           putchar(LF);
  19.           addlf = FALSE;
  20.      }
  21.      putchar(c);
  22.      if (c == CR)  addlf = TRUE;
  23.     }
  24. }
  25.