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

Kim Trang

New member
What is the output of this program?
Code:
   #include<stdio.h>
   #include<fcntl.h>
   int main()
   {
       int fd, count;
       fd = open("123hoidap.txt",O_WRONLY|O_CREAT);
       count = write(fd,"Linux System Programming",5);
       if(count != 5)
           perror("write");
       return 0;
   }
A. it will create a file “123hoidap.txt” in the present working directory
B. it will write the string “Linux System Programming” in the file “123hoidap.txt”
C. all of the mentioned
D. none of the mentioned
 
Answer: a
Explanation: This program will write only “Linux” in the file “123hoidap.txt” because we are writing only 5 bytes with “write” system call.
Output:
[root@localhost 123hoidap]# gcc -o san san.c
[root@localhost 123hoidap]# ls
san san.c
[root@localhost 123hoidap]# ./san
[root@localhost 123hoidap]# ls
san san.c 123hoidap.txt
[root@localhost 123hoidap]# vim 123hoidap.txt
[root@localhost 123hoidap]#
 

Tìm kiếm

Back
Top