1,头文件:
#include<iostream.h>
2,函数原型:
int feof(FILE * stream);
3,参数:
stream为文件流指针
4,返回值:
检测到文件结束标识返回1,否则返回0。
5,事例:
#include<iostream.h>
#include<stdio.h>
void main(void)
{
FILE* stream;
long l;
float fp;
char s[81];
char c;
stream = fopen("fscanf.txt","w+");
if(stream == NULL) /*打开文件失败*/
{
printf("the file is opeaned error!\n");
}
else
{
fprintf(stream,"%s %ld %f %c","a_string",6500,3.1415,'x');
fseek(stream,0L,SEEK_SET); /*定位读写指针*/
fscanf(stream,"%s",s);
printf("%ld\n",ftell(stream));
fscanf(stream,"%ld",&l);
printf("%ld\n",ftell(stream));
fscanf(stream,"%f",&fp);
printf("%ld\n",ftell(stream));
fscanf(stream," %c",&c);
printf("%ld\n",ftell(stream));
fgetc(stream); /*使指针到结尾*/
if(!ferror(stream))
{
if(feof(stream)) /*如果不是结束*/
{
printf("We have reached end-of-file\n");
rewind(stream);
fscanf(stream,"%s",s);
printf("%s\n",s);
}
}
fclose(stream);
}
}