What is the output of this program? [code] #include<stdio.h> #include<fcntl.h> int main() { int fd, count; char

Minh Phượng

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<fcntl.h>
   int main()
   {
       int fd, count;
       char ch[10];
       fd = open("123hoidap.txt",O_RDWR|O_CREAT);
       write(fd,"linux",5);
       lseek(fd,2,SEEK_END);
       write(fd,"san",3);
       lseek(fd,0,0);
       count = read(fd,ch,10);
       printf("%s\n",ch);
       return 0;
   }
A. linux
B. linuxsan
C. linux san
D. none of the mentioned
 
Answer: a
Explanation: The lseek function allows the file offset to be set beyond the end of the file and if the data is latter written this point, subsequent reads of the data in the gap returns NULL.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ./san
linux
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top