首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

文件的读取的有关问题

2012-02-04 
文件的读取的问题没有输出任何东西有个file.txt的文件内面的内容如下:c:\testc:\123.t#includestdio.h#i

文件的读取的问题
没有输出任何东西
有个file.txt的文件   内面的内容如下:
c:\test
c:\123.t

#include   <stdio.h>
#include   <stdlib.h>
#define   NUM   100
main()
{   FILE   *file;

    int   i;

    char   str[NUM],temp;

    file=fopen( ".\file.txt ", "r ");   /*   打开文件   */

    while(feof(file)!=0)

    {     for(i=0;;i++)

          {temp=fgetc(file);

            if(temp!= '\n ')

            str[i]=temp;

            else
            {str[i+1]= '\0 ';
              break;}
          }

          puts(str);

    }
    fclose(file);

    getch();

}


[解决办法]
while(feof(file)!=0)
============
while(feof(file)==0)
or:
while( !feof(file) )


热点排行