feof

Verifica la fine del file in un flusso.

int feof( 
   FILE *stream 
);

Parametri

  • stream
    Puntatore alla struttura FILE.

Valore restituito

La funzione feof restituisce un valore diverso da zero se un'operazione di lettura ha tentato di leggere oltre la fine del file; in caso contrario restituisce 0.Se il puntatore di flusso è NULL, il gestore di parametro non valido viene richiamato dalla funzione, come descritto in Convalida dei parametri.Se l'esecuzione può continuare, errno viene impostato su EINVAL e feof restituisce 0.

Vedere _doserrno, errno, _sys_errlist, e _sys_nerr per ulteriori informazioni su questi, e altri, codici di errore.

Note

La routine feof (implementata sia come funzione che come macro) determina se è stata passata la fine di stream.Quando viene passata la fine del file, le operazioni di lettura restituiscono un indicatore di fine del file finché non viene chiuso lo stream o finché rewind, fsetpos, fseek, o clearerr vengono chiamate su di esso.

Ad esempio, se un file contiene 10 byte e vengono letti 10 byte dal file, feof restituirà 0 perché, anche se il puntatore del file è la fine del file, non si è tentato di leggere oltre la fine.Solo dopo che si è tentato di leggere l'undicesimo byte feof restituirà un valore diverso da zero.

Requisiti

Funzione

Intestazione obbligatoria

feof

<stdio.h>

Per ulteriori informazioni sulla compatibilità, vedere Compatibilità nell'introduzione.

Esempio

// crt_feof.c
// This program uses feof to indicate when
// it reaches the end of the file CRT_FEOF.TXT. It also
// checks for errors with ferror.
//

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   int  count, total = 0;
   char buffer[100];
   FILE *stream;

   fopen_s( &stream, "crt_feof.txt", "r" );
   if( stream == NULL )
      exit( 1 );

   // Cycle until end of file reached:
   while( !feof( stream ) )
   {
      // Attempt to read in 100 bytes:
      count = fread( buffer, sizeof( char ), 100, stream );
      if( ferror( stream ) )      {
         perror( "Read error" );
         break;
      }

      // Total up actual bytes read
      total += count;
   }
   printf( "Number of bytes read = %d\n", total );
   fclose( stream );
}

Input: crt_feof.txt

Line one.
Line two.

xssktc6e.collapse_all(it-it,VS.110).gifOutput

Number of bytes read = 19

Equivalente .NET Framework

Non applicabile. Per chiamare la funzione standard C, utilizzare PInvoke. Per ulteriori informazioni, vedere Esempi di PInvoke.

Vedere anche

Riferimenti

Gestione degli errori (CRT)

Flusso I/O

clearerr

_eof

ferror

perror, _wperror