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

[cc lang=”c”]
#include
#include

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);
}

}
[/cc]

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *