Aim: Write a program to
copy a file.
Program:
#include<stdio.h>
#include<fcntl.h>
#define buf 2048
int main(int argc, char *argv[])
{
int
fd,fd1;
char
buf1[buf];
fd=open(argv[1],O_RDWR);
read(fd,buf1,buf);
fd1=creat(argv[2],O_WRONLY);
write(fd1,buf1,buf);
close(fd);
close(fd1);
}
Output:
$ cat aa.txt
HELLO
$ cc copy.c
$ ./a.out aa.txt
a.txt
$ cat a.txt
HELLO
No comments:
Post a Comment