c++循环读取多行文本文件

2014-11-19 09:12:50 · 作者: · 浏览: 28

  其实主要的思路就是每次调用fgets,文件指针都会跳到下一行。


  自己写的代码


  #include


  #include


  #define Line 1024


  int main()


  {


  //读取多行文件,存多行文件


  FILE *fp;


  char filename[20];


  printf("Please enter the file name\n");


  gets(filename);


  fp = fopen(filename,"r");


  if(fp==NULL)


  {


  printf("File Open Error");


  return 4;


  }


  char *buf;


  buf = (char *)malloc(Line*sizeof(char));


  char *p;