c program to implement mv command 1

c program to implement mv command

#include
#include
#include
#include
main( int argc,char *argv[] )
{
int i,fd1,fd2;
char *file1,*file2,buf[2];
file1=argv[1];
file2=argv[2];
printf("file1=%s file2=%s",file1,file2);
fd1=open(file1,O_RDONLY,0777);
fd2=creat(file2,0777);
while(i=read(fd1,buf,1)>0)
write(fd2,buf,1);
remove(file1);
close(fd1);
close(fd2);
}

Here is what the above code is Doing:
1. It takes two arguments from the command line.
2. It opens the first file in read mode and the second file in write mode.
3. It reads the first file and writes it to the second file.
4. It deletes the first file.
5. It closes both the files.

Similar Posts