在dos下,可以用下面语句:char c;c = fgetc(fp);
if(c==EOF)
{
...............
}但window下,好像不行,读出的c是0xff.
该用什么方法哪?

解决方案 »

  1.   

    /* 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>
    void main( void )
    {
       int  fh, count, total = 0;
       char buf[10];
       if( (fh = _open( "eof.c", _O_RDONLY )) == - 1 )
       {
            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 );
    }
    OutputNumber of bytes read = 754
      

  2.   

    sorry, 试过了,这种办法不行.
      

  3.   

    fp  = fopen()
    count = fread( fp ..)
    if ( count == 0 ) // end of file
      

  4.   

    先获取文件长度,然后根据文件的长度来读取文件,这样才能确保万无一失。DOS下面的c==EOP也只对普通的文本文件有用吧,对二进制文件呢?
      

  5.   

    if( fread(...count...) < count )
    结束
      

  6.   

    fgetc应该判断返回是否为NULL
    getc返回的是一个整形的。