C--->fopen/fseek/fread实现标准读取文本数据

 1   if(access(filename, 0))   //to judge the file whether exists,when it's valid, return 0
 2       return -1;
 3   FILE *f=fopen(filename,"rb");
 4   fseek(f,0,SEEK_END);
 5   long len=ftell(f);
 6   fseek(f,0,SEEK_SET);
 7   
 8   char *data=(char*)malloc(len+1);
 9   fread(data,1,len,f);
10   fclose(f);

 

posted @ 2021-07-09 11:17  `Konoha  阅读(140)  评论(0编辑  收藏  举报