Condividi tramite


_eof

Controlla se si è raggiunta la fine del file (EOF).

int _eof( 
   int fd 
);

Parametri

  • fd
    Il descrittore del file che fa riferimento al file aperto.

Valore restituito

_eof restituisce 1 se la posizione corrente è fine del file, oppure 0 se non lo è. Un valore di ritorno pari a –1 indica un errore; in questo caso, il gestore di parametro non valido viene richiamato, come descritto in Convalida dei parametri. Se si consente all'esecuzione di continuare, errno viene impostato a EBADF, che indica un descrittore di file non valido.

Note

La funzione _eof determina se la fine del file associato a fd è stata raggiunta.

Requisiti

Funzione

Intestazione obbligatoria

Intestazione facoltativa

_eof

<io.h>

<errno.h>

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

Esempio

// crt_eof.c
// This program reads data from a file
// ten bytes at a time until the end of the
// file is reached or an error is encountered.
//
#include <io.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <share.h>

int main( void )
{
   int  fh, count, total = 0;
   char buf[10];
   if( _sopen_s( &fh, "crt_eof.txt", _O_RDONLY, _SH_DENYNO, 0 ) )
   {
        perror( "Open failed");
        exit( 1 );
   }
   // Cycle until end of file reached: 
   while( !_eof( fh ) )
   {
      // Attempt to read in 10 bytes: 
      if( (count = _read( fh, buf, 10 )) == -1 )
      {
         perror( "Read error" );
         break;
      }
      // Total actual bytes read 
      total += count;
   }
   printf( "Number of bytes read = %d\n", total );
   _close( fh );
}

Input: crt_eof.txt

This file contains some text.

Output

Number of bytes read = 29

Equivalente .NET Framework

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

Vedere anche

Riferimenti

Gestione degli errori (CRT)

I/O a basso livello

clearerr

feof

ferror

perror, _wperror