一个关于文件读取的问题
#include <stdio.h>#include <stdlib.h>#include <memory.h>#include <string.h>#define LENGTH 20#define SUB_LEN 512int main(void){ FILE *fp=NULL; char pch[20][512]; int i; FILE *fout=NULL; fp=fopen("rcl.txt","r"); if(fp==NULL) { printf("Can't open rcl.txt!\n"); return 0; } fout=fopen("result.txt","w"); if(fout==NULL) { printf("不能打开result.txt文件!\n"); return 0; } while(getc(fp)!=EOF) { fseek(fp,-1,SEEK_CUR); for(i=0;i<LENGTH && getc(fp)!=EOF; i++) { fseek(fp,-1,SEEK_CUR); if(fgets(pch[i],SUB_LEN,fp)) { printf("%d\n",i); } else { printf("%d\n",i); printf("读取失败!"); // return 0; } } } fclose(fp); fclose(fp); return 0;}