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

  1. 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);

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

C include include include include define BLKSIZE 4096 int mainint argc char argv if argc 3 fprintfstderr Usage s argv0 exitEXITFAILURE int sourcefd de... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!