Modify the C code to MERGE 2 files, by reading the first file and writing into
Fantastic news! We've Found the answer you've been seeking!
Question:
Modify the C code to MERGE 2 files, by reading the first file and writing into the second one. (or vice-versa) Once you have compiled the C code, you can execute it by typing ./a.out file1 file2
New file contents will be file2+file1 or file1+file2 (Merged)
C code
#include
#include
#include
#include
#define BLKSIZE 4096
int main(int argc, char *argv[])
{
int fd, gd, n, total=0;
char buf[BLKSIZE];
fd = open(argv[1], O_RDONLY);
gd = open(argv[2], O_WRONLY|O_CREAT);
while (n = read(fd, buf, BLKSIZE)){
write(gd, buf, n);
total += n;
}
printf("total bytes copied=%d", total);
close(fd);
close(gd);
}
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date: