Question: Next to each marked statement of the program given below, specify the offset on the corre sponding file after the statement is carried out successfully.

Next to each marked statement of the program given below, specify the offset on the corre sponding file after the statement is carried out successfully. void main() \{ char buf [100]; int fd1 = open("file1.txt", O_RDWR | O_CREAT, S_IRUSR I S_IWUSR); int fd2 = open("file2.txt", O_RDWR | O_CREAT, S_IRUSR I S_IWUSR); strcpy(buf, "12345678901234567890"); write(fd2, buf, 20); write(fd1, buf, 15); lseek(fd1, 5, SEEK_SET); read(fd1, buf, 10); lseek(fd2, -5, SEEK_END); lseek(fd1, -5, SEEK_CUR); //be careful here, what does buf contain? write(fd2, buf, strlen(buf)); \} void main(){ char buf [100]; int fd1 = open("file1.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); int fd2 = open("file2.txt", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); strcpy(buf, "12345678901234567890"); write(fd2, buf, 20); write(fd1, buf, 15); lseek(fd1, 5, SEEK_SET); read(fd1, buf, 10); lseek(fd2, -5, SEEK_END); lseek(fd1, -5, SEEK_CUR); //be careful here, what does buf contain? write(fd2, buf, strlen(buf)); \}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
