Question: The reverse1.c (posted on the course site) was written using system I/O functions for file access, rewrite it using standard I/O functions for file access.

The "reverse1.c" (posted on the course site) was written using system I/O functions for file access, rewrite it using standard I/O functions for file access.

reverse1.c code:

// reverse1.c // solution 1: Start reading at the end // Use lseek() on fileIn #include #include #include

int main(int argc, char *argv[]){ int fd1, fd2; char buffer; // 1 character buffer

long int i=0, fileSize=0;

fd1=open(argv[1], O_RDONLY); fd2=open(argv[2], O_CREAT|O_WRONLY|O_TRUNC, 0755);

//two ways to figure out the size of the file

while(read(fd1, &buffer, 1)>0) fileSize++;

// printf("files size is %d ", fileSize);

/* fileSize =lseek(fd1, 0, SEEK_END); printf("files size is %d ", fileSize); lseek(fd1, 0, SEEK_SET); */ while(++i <= fileSize){ // differnce between ++i and i++ lseek(fd1, -i, SEEK_END); read(fd1, &buffer, 1); write(fd2, &buffer, 1); } close(fd1); close(fd2); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!