C语言中如何从一个文件中读取一段含\n的字符串?

如题所述

    下面例程读一行输出1行。

#include <stdio.h>
int main()
{
   FILE * pFile;
   char mystring [1000];
   pFile = fopen ("myfile.txt" , "r");
   if (pFile == NULL) perror ("Error opening file");
   else {
     if ( fgets (mystring , 1000 , pFile) != NULL )//读取一行字符串
       puts (mystring);//输出该字符串
     fclose (pFile);
   }
   return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答