请教文件读写简单问题
打印错误如下:
localfd = 3
read error = -1
The buf is *
晕了,感觉挺简单啊
1 #include <stdio.h>
2 #include <fcntl.h>
3
4 int main()
5 {
6 int localfd;
7 int len, len_w;
8 char buf[10];
9 char *cp;
10
11 len = 0;
12 localfd = open("ccc.test", O_WRONLY|O_CREAT, 0644);
13 if(localfd < 0) printf("open error\n");
14
15 printf("localfd = %d\n", localfd);
16
17 len_w = write(localfd, "Hello", 6);
18 if(len_w < 0)
19 printf("write error %d\n", len_w);
20
21 len = read(localfd, buf, 6);
22 if(len < 0)
23 printf("read error = %d\n", len);
24 printf("The buf is %s\n", buf);
25
26 close(localfd);
27 return 0;
28 }