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 }
时间: 2024-11-14 22:10:17