home *** CD-ROM | disk | FTP | other *** search
/ Fish 'n' More 2 / fishmore-publicdomainlibraryvol.ii1991xetec.iso / dirs / northc_384.lzh / NorthC / Example2.LZH / top / copy.c < prev    next >
C/C++ Source or Header  |  1990-08-30  |  906b  |  46 lines

  1. /*
  2.  
  3.   (c) 1990 S.Hawtin.
  4.   Permission is granted to copy this file provided that:
  5.    1) It is not used for commercial gain
  6.    2) This notice is included in all copies
  7.    3) Altered copies are marked as such
  8.  
  9. */
  10.  
  11. /* A function to copy files */
  12.  
  13. #include <stdio.h>
  14.  
  15. int
  16. copy(srcName,destName)
  17.     char *srcName;
  18.     char *destName;
  19.    {/* Copy a file from source to dest */
  20.     FILE *srcFp;
  21.     FILE *destFp;
  22.     char buffer[1024];
  23.     int num;
  24.  
  25.     srcFp = fopen(srcName,"r");
  26.     if(srcFp==NULL)
  27.         return(-1);
  28.     destFp = fopen(destName,"w");
  29.     if(destFp==NULL)
  30.        {fclose(srcFp);
  31.         return(-1);
  32.         }
  33.     num = fread(buffer,sizeof(char),1024,srcFp);
  34.     while(num > 0)
  35.        {
  36.         num = fwrite(buffer,sizeof(char),num,destFp);
  37.         if(num > 0)
  38.             num = fread(buffer,sizeof(char),1024,srcFp);
  39.         }
  40.  
  41.     fclose(srcFp);
  42.     fclose(destFp);
  43.  
  44.     return(num);
  45.     }
  46.