C Program to Copy Files [System Programming]
This is the C Program to Copy Files,we open a file using filedescriptor fd1 and create another file fd2.the contents are copied from one file to another till end of file is met
#include<fcntl.h>
#include<unistd.h>
main(int argc,char *jp[])
{
int fd1,fd2;
fd1=open(jp[1],O_RDONLY);
fd2=creat(jp[2],0777);
copy(fd1,fd2);
}
copy(int old,int new)
{
char buff[1024];
int count;
while((count=read(old,buff,sizeof(buff)))>0)
{
write(new,buff,count);
}
}
Recent Comments