在C語言中feof函數用來判斷是否到達文件的末尾。如果要使用此函數必須引入stdio.h頭文件。
函數形式:int feof(FILE *stream);
函數返回值:如果文件指針到達文件末尾則反回一個非零值,否則為0;
下面用一個實例來說明:
#include <stdio.h>
#include <stdlib.h>
int main(void){
FILE *fp;
if((fp=fopen("test", "rb"))==NULL) {
printf("Cannot open file./n");
exit(1);
}
while(!feof(fp)) {
char ch = getc(fp);
printf("%c",ch);
}
fclose(fp);
}
|
新聞熱點
疑難解答