home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fred Fish Collection 1.5
/
ffcollection-1-5-1992-11.iso
/
ff_disks
/
300-399
/
ff384.lzh
/
NorthC
/
Example2.LZH
/
top
/
copy.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-30
|
906b
|
46 lines
/*
(c) 1990 S.Hawtin.
Permission is granted to copy this file provided that:
1) It is not used for commercial gain
2) This notice is included in all copies
3) Altered copies are marked as such
*/
/* A function to copy files */
#include <stdio.h>
int
copy(srcName,destName)
char *srcName;
char *destName;
{/* Copy a file from source to dest */
FILE *srcFp;
FILE *destFp;
char buffer[1024];
int num;
srcFp = fopen(srcName,"r");
if(srcFp==NULL)
return(-1);
destFp = fopen(destName,"w");
if(destFp==NULL)
{fclose(srcFp);
return(-1);
}
num = fread(buffer,sizeof(char),1024,srcFp);
while(num > 0)
{
num = fwrite(buffer,sizeof(char),num,destFp);
if(num > 0)
num = fread(buffer,sizeof(char),1024,srcFp);
}
fclose(srcFp);
fclose(destFp);
return(num);
}