Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

C include include include include define BLKSIZE 4096 int mainint argc char argv if argc 3 fprintfstderr Usage s argv0 exitEXITFAILURE int sourcefd de... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Operating System questions

Question

Symmetric encryption uses two keys. True False

Answered: 1 week ago

Question

Explain the causes of indiscipline.

Answered: 1 week ago