1 #include<stdio.h>
2 #include<sys/types.h>
3 #include<sys/stat.h>
4 #include<fcntl.h>
5 #include<unistd.h>
6 #include<string.h>
7 #define num 50
8 int main()
9 {
10 int r_fd,w_fd,ret;
11 char s[num];
12 char c[30]=“hello,software weekly\n”;
13 w_fd=open(“hello.txt”,O_CREAT|O_RDWR,S_IRWXU);
14 if(w_fd==-1)
15 {
16 printf(“write error!”);
17 return -1;
18 }
19 else
20 {
21 write(w_fd,c,strlen©);
22 close(w_fd);
23 }
24 r_fd=open(“hello.txt”,O_RDWR);
25 ret=read(r_fd,s,num);
26 if(ret==-1)
27 {
28 printf(“read error”);
29 }
30 printf("%s\n",s);
31 close(r_fd);
32 return 0;
33 }