_eof

Pengujian untuk akhir file (EOF).

Sintaks

int _eof(
   int fd
);

Parameter

fd
Pendeskripsi file yang mengacu pada file yang terbuka.

Nilai hasil

_eof mengembalikan 1 jika posisi saat ini adalah akhir dari file, atau 0 jika tidak. Nilai pengembalian -1 menunjukkan kesalahan; dalam hal ini, handler parameter yang tidak valid dipanggil, seperti yang dijelaskan dalam Validasi parameter. Jika eksekusi diizinkan untuk melanjutkan, errno diatur ke EBADF, yang menunjukkan deskriptor file yang tidak valid.

Keterangan

Fungsi menentukan _eof apakah akhir file yang terkait fd telah tercapai.

Secara default, status global fungsi ini dicakup ke aplikasi. Untuk mengubah perilaku ini, lihat Status global di CRT.

Persyaratan

Function Header yang diperlukan Header opsional
_eof <io.h> <errno.h>

Untuk informasi kompatibilitas selengkapnya, lihat Kompatibilitas.

Contoh

// 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.

Hasil

Number of bytes read = 29

Baca juga

Penanganan kesalahan
I/O tingkat rendah
clearerr
feof
ferror
perror, _wperror