home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 357_01 / cstar1.exe / STRIP.C < prev    next >
C/C++ Source or Header  |  1991-06-18  |  2KB  |  100 lines

  1. /*
  2.     Program to strip extra '\r' characters from a file.
  3.  
  4.     
  5.     PUBLIC DOMAIN SOFTWARE
  6.  
  7.     This program was placed in    the public domain on June 15, 1991,
  8.     by its author and sole owner,
  9.  
  10.         Edward K. Ream
  11.         1617 Monroe Street
  12.         Madison, WI 53711
  13.         (608) 257-0802
  14.  
  15.     This program may be used for any commercial or non-commercial purpose.
  16.  
  17.     DISCLAIMER OF WARRANTIES
  18.  
  19.     Edward K. Ream (Ream) specifically disclaims all warranties,
  20.     expressed or implied, with respect to this computer software,
  21.     including but not limited to implied warranties of merchantability
  22.     and fitness for a particular purpose.  In no event shall Ream be
  23.     liable for any loss of profit or any commercial damage, including
  24.     but not limited to special, incidental consequential or other damages.
  25. */
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28.  
  29. main(argc, argv)
  30. int argc;
  31. char **argv;
  32. {
  33.     char *in = NULL, *out = NULL, *arg;
  34.     FILE * in_file, *out_file;
  35.  
  36.     printf("strip: March 8, 1989\n");
  37.  
  38.     if (argc < 3) {
  39.         printf("strip in out\n");
  40.         exit(0);
  41.     }
  42.  
  43.     /* Process all the arguments on the command line. */
  44.     argc--;
  45.     argv++;
  46.     while (argc-- > 0) {
  47.         arg = *argv++;
  48.         if (in == NULL) {
  49.             in = arg;
  50.         }
  51.         else if (out == NULL) {
  52.             out = arg;
  53.         }
  54.         else {
  55.             printf("Extra file argument: %s\n", arg);
  56.             exit(0);
  57.         }
  58.     }
  59.  
  60.     /* Make sure that both file arguments were provided. */
  61.     if (in == NULL) {
  62.         printf("Missing input, output file arguments.\n");
  63.         exit(0);
  64.     }
  65.     else if (out == NULL) {
  66.         printf("Missing output file argument.\n");
  67.         exit(0);
  68.     }
  69.     
  70.     /* Open the files. */
  71.     in_file = fopen(in, "r");    
  72.     if (in_file == NULL) {
  73.         printf("Can not open %s\n", in);
  74.         exit(0);
  75.     }
  76.  
  77.     out_file = fopen(out, "w");
  78.     if (out_file == NULL) {
  79.         printf("Can not create %s\n", out);
  80.         exit(0);
  81.     }
  82.  
  83.     /* Copy the file. */
  84.     for(;;) {
  85.         int c;
  86.         c = fgetc(in_file);
  87.         if (c == EOF) {
  88.             break;
  89.         }
  90.         else if (c == '\r') {
  91.             continue;
  92.         }
  93.         else {
  94.             fputc(c, out_file);
  95.         }
  96.     }
  97.     fclose(in_file);
  98.     fclose(out_file);
  99. }
  100.