Question: A certain file foo contains the ASCII text string This file contains 28 bytes.. That is, the bytes of the file, viewed as 8-bit

A certain file foo contains the ASCII text string  

A certain file foo contains the ASCII text string "This file contains 28 bytes.". That is, the bytes of the file, viewed as 8-bit integers, contain the values 0x54, 0x65, 0x73, 0x74, and 0x20, etc. a. Suppose a program opens foo for reading and writing (file descriptor fd is returned), and then does the following. Assume buf is a 30-byte array of char. if ((rv = read (fd, buf, 10)) < 0) {...handle error... } if ((rv = write(fd, buf, 10)) < 0) {... handle error... } Assuming both calls return 10, what does the file contain after this code runs? b. Suppose the same program next calls 1seek (fd, 0, SEEK_SET) to "rewind" the file offset to the beginning, and then does the following: if ((rv = read (fd, buf, 30)) < 0) {...handle error... } strcpy (buf, "That"); if ((rv = write(fd, buf, rv)) < 0) {... handle error... } What does the file now contain?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

a Suppose a program opens foo for reading and writing file descriptor fd is returned and then does t... 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 Programming Questions!