Fork me on GitHub

C库函数对文件的操作

 1 int main(int arg, char *args[])
 2 {
 3 
 4 //    char s[]="abc.txt";
 5     FILE* p=fopen(args[1],"r+");
 6     if(p==NULL)
 7         printf("error is %s\n",strerror(errno));
 8     else
 9     {
10         printf("success\n");
11         char buf[100];
12         size_t rc=0;
13         while(1)
14         {
15             size_t tmp=fread(buf,1,sizeof(buf),p);//第二个参数*第三个参数不能超过缓冲区
16             rc += tmp;
17             if(tmp==0)
18                 break;
19         }
20 
21         printf("rc=%d\n",rc);
22         fclose(p);
23     }
24     return 0;
25 }

 

posted @ 2016-07-20 17:21  千秋此意  阅读(182)  评论(0编辑  收藏  举报