C语言用fscanf()函数如何读取文件全部内容?

来源:百度知道 编辑:UC知道 时间:2024/05/23 11:03:11
有一个文件,我知道数据在其中的存储格式,比如txt文件,所有数据都是以"%d %d %d %d %d\n"格式存储的:
1 1 1 1 1
2 2 2 2 2
.........
但是我不知道文件的长度,如何用fscanf()函数以同样的格式读取整个文件。
或者用其它函数也行,但格式要相同。

int []account;
for(int i=0;!feof(file_p);++i) /*file_p是文件标识符*/
{
fscanf(file_p,"%d",account[i]);
}

int []account;
for(int i=0;!feof(file_p);++i) /*file_p是文件标识符*/
{
fscanf(file_p,"%d",account[i]);
}

#include <stdio.h>
void main( void )
{
FILE *f;
int a,b,c,d,e;
f = fopen("a.txt", "r");
while(fscanf(f,"%d %d %d %d %d",&a,&b,&c,&d,&e)==5)
{
//你的代码
}
fclose(f);
}