home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_07_07 / v7n7056a.txt < prev    next >
Text File  |  1989-09-05  |  1KB  |  59 lines

  1.  
  2. Listing 3:
  3.  
  4. #include <stdio.h>
  5. #include <stdio.h>
  6.  
  7. main(int argc, char *argv[])
  8.    {
  9.    copy_it(argv[1], argv[2]);
  10.    end_it("copy is done\n");
  11.    }
  12. copy_it(char FileIn[55], char FileOut[55])
  13.    {
  14.    FILE *fi;
  15.    FILE *fo;
  16.    int gc;
  17.      
  18.    /* The next 2 lines fixed the problem */  
  19.    /* NOT VERY ELEGANT BUT IT WORKS! */
  20.    if (*FileIn == *FileOut)
  21.        end_it("ABORT: Make first letters of names different\n");
  22.  
  23.    if ((fi = fopen(FileIn, "rb")) == NULL) 
  24.        end_it("File not found\n");
  25.    if ((fo = fopen(FileOut, "wb")) == NULL)
  26.        {
  27.        fclose(fi);
  28.        end_it("No output\n");
  29.        }
  30.    while (!feof(fi))
  31.        {
  32.        gc = getc(fi);                  
  33.        if (!feof(fi)) 
  34.            putc(gc, fo); 
  35.        }                                 
  36.        fclose(fi);                       
  37.        fclose(fo);                       
  38.    }
  39.  
  40. /*
  41.    IF FILEIN = FILEOUT, AND FILE IS LARGER THAN ABOUT 2-3K,  
  42.  
  43.  
  44.                            6
  45.  
  46.  
  47.  
  48.       YOU WILL DAMAGE DIRECTORY TABLE!         
  49. */
  50.  
  51. static end_it(s)
  52. char *s;            /* String to display to User */
  53.    {
  54.    /* Display string passed and simply abort */
  55.    fprintf(stdout, s); 
  56.    exit (0);
  57.    }             
  58.  
  59.