读书人

文件的读取的有关问题

发布时间: 2012-02-04 15:43:08 作者: rapoo

文件的读取的问题
没有输出任何东西
有个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) )


读书人网 >C语言

热点推荐