feof ()- 測試檔案結尾指示器

格式

#include <stdio.h>
int feof(FILE *stream);

語言層次

ANSI

安全執行緒

說明

feof() 函數指出是否為給定 串流設定檔案結尾旗標。 檔案結尾旗標由數個函數設定,以指出檔案結尾。 透過呼叫此串流的 rewind()fsetpos()fseek()clearerr() 函數,清除檔案結尾旗標。

回覆值

只有在設定 EOF 旗標時, feof() 函數才會傳回非零值; 否則會傳回 0

範例

此範例會掃描輸入 stream ,直到它讀取檔案結尾字元為止。
#include <stdio.h>                           
#include <stdlib.h>                          
 
int main(void)
{                             
   char string[100];                         
   FILE *stream;                             
   memset(string, 0, sizeof(string));        
   stream = fopen("qcpple/qacsrc(feof)", "r"); 
 
   fscanf(stream, "%s", string);             
   while (!feof(stream)) 
   {                   
      printf("%s\n", string);                
      memset(string, 0, sizeof(string));     
      fscanf(stream, "%s", string);          
   }                                         
} 

相關資訊