Condividi tramite


_eof

Test di fine del (EOF) file.

int _eof( 
   int fd 
);

Parametri

  • fd
    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 è.Restituito un valore pari a 1 indica un errore; in questo caso, il gestore non valido di parametro viene richiamato, come descritto in Convalida dei parametri.Se l'esecuzione è consentita per continuare, errno è impostato su EBADF, che indica un descrittore di file non valido.

Note

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

Requisiti

Funzione

Intestazione di associazione

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.

2hwz7wst.collapse_all(it-it,VS.110).gifOutput

Number of bytes read = 29

Equivalente .NET Framework

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

Vedere anche

Riferimenti

Gestione degli errori (CRT)

L'I/O di basso livello

clearerr

feof

ferror

perror, _wperror