I have a past exam question like that:
Consider the following C code assuming that filename is a plain text file containing the following string:
0123456789
and none of the function calls fail, buffers are big enough, etc...
int fd1, fd2, fd3;
char buf1 = 'x', buf2 = 'x', buf3 = 'x';
fd1 = open("filename", O_RDONLY);
fd2 = dup(fd1);
fd3 = open("filename", O_RDONLY);
lseek(fd1, 4L, SEEK_SET);
lseek(fd2, 2L, SEEK_SET);
lseek(fd3, 7L, SEEK_SET);
read(fd1, %26amp;buf1, 1);
read(fd2, %26amp;buf2, 1);
read(fd3, %26amp;buf3, 1);
So,what will be the content of buf1,buf2,buf3. And explain why.
Can someone help me,please.
Basic file I/O in C?
But it wont compile correctly, filename is undefined, and the open functions (plus parameters such as _O_RDONLY) are OS\compiler specific. Thefore buf1, buf2, and buf3 all equal null.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment