Question: This is a C program. Given a file, data.txt. create a program with the following functionality. Use BUFSIZE=10 to iteratively read/write bytes from the input

This is a C program. Given a file, data.txt. create a program with the following functionality.

  1. Use BUFSIZE=10 to iteratively read/write bytes from the input file. If you use other sizes of buffer array, you will get 0 point.
  2. After your programs execution, the data.txt file contents should be reversed. For example, if the original contents of data.txt is ABCDEFGHIJKLMN, then the new contents should be NMLKJIHGFEDCBA. The file size should remain the same.
  3. You cant use any additional array or dynamic memory in your program except for buffer[10].
  4. You cant create/access any other files.
  5. If you want, you may find out the size of the file before the main loop. But, this is not really needed. We learned how to get the size of the file by using lseek() call.
  6. You need to iterate the following 4 steps as was discussed in the class:
    1. Use lseek() to move a read-write pointer towards the end of the file.
    2. Call read() to read 10 bytes into buffer[].
    3. Reverse each byte in the buffer[].
    4. Again, use lseek() to restore the read-write pointer to the position after a).
    5. Write buffer[] back to the file.
  7. Print out the new contents of data.txt file at the end of your program.

Give attention to:

The following steps need to be done in your main loop. I skipped one step in the lecture.

The following steps need to be done in your main loop.

  1. Use lseek() to move a read-write pointer towards the end of the file.
  2. Call read() to read 10 bytes into buffer[].
  3. Reverse each byte in the buffer[].
  4. Again, use lseek() to restore the read-write pointer to the position after a).
  5. Write buffer[] back to the file.

The following is an input file to be reversed. do not reverse ABCDEFGHIJKLMN but the following file content.

data.txt

Bottomless vales and boundless floods, And chasms, and caves, and Titan woods, With forms that no man can discover For the tears that drip all over; Mountains toppling evermore Into seas without a shore; Seas that restlessly aspire, Surging, unto skies of fire; Lakes that endlessly outspread Their lone waters lone and dead, Their still waters still and chilly With the snows of the lolling lily.

Thank you so much!

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!