Thread: EOF - but that can't be

  1. #1
    Registered User
    Join Date
    Sep 2004

    EOF - but that can't be

    Hi there,

    i got a wicked error which makes me totally mad
    i have a file (5,59kb) which i want to access to read out triangle coordinations.

    after the 95. cycle (the proceeded data should be ~570 byte) i get an EOF message. also the return value of the fread function call is zero then. but that cant be?! maybe a EOF ascii key is inserted somewhere in the file?

    hope any1 got any ideas

    the source:
    bool MapEntity::LoadMap( HashString hMap )
    	hMap = "maps/" + hMap + ".mpd";
    	FILE *File = fopen( hMap.c_str(), "r" );
    	if( !File )
    		neolog << LogLevel( ERROR ) << "*** cant access map" << endl;
    		return false;
    	fread( &m_sHeader, sizeof( sHeader), 1, File );
    	int asd = 0;
    	for( int i = 0; i < ( (int)m_sHeader.DataSize/( 3*sizeof(unsigned short) ) ); i++ )
    		Vector3d *pTriangle = new Vector3d;
    		unsigned short x, y, z;
    		if( feof( File ) != 0 )
    			asd = 1;
    		asd = fread( &x, sizeof(unsigned short), 1, File );
    		asd = fread( &y, sizeof(unsigned short), 1, File );
    		asd = fread( &z, sizeof(unsigned short), 1, File );
    		pTriangle->Set( x, y, z );
    		m_vCoordinates.push_back( *pTriangle );
    	fclose( File );
    	File = NULL;
    	return true;

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > FILE *File = fopen( hMap.c_str(), "r" );
    Open it in binary mode then
    FILE *File = fopen( hMap.c_str(), "rb" );
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2004
    ok. did that but i got checksum errors - but i found the problem. damn clearing of the vector.

    thx m8

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001

    Exclamation EOF is NOT a number!

    maybe a EOF ascii key is inserted somewhere in the file?
    EOF is NOT a number or value! See the Programming FAQ.

    I used to be confused about this too. I thought it was some numerical value inserted at the end of an ASCII file. (I thought the value was system-specific, because it's not on the standard ASCII chart.)

    I thought it could not be used with a non-ASCII file where that value might exist randomly. I thought it was just like the null-termination of a c-style string, or a carriage-return, or a linefeed. I was wrong, wrong, wrong!

  5. #5
    Registered User Frobozz's Avatar
    Join Date
    Dec 2002
    Hehe. You said what it is not but not what it is.

    The EOF marker is most likely platform/operating system dependant. My guess is that, under Windows, it is most likely determined by checking if the next read is for a byte or whatever bigger than the size of the file being read from.

  6. #6
    Hardware Engineer
    Join Date
    Sep 2001

    From the C standard (I couldn't find it in the C++ standard)...

    Today 01:04 PM

    Frobozz ,
    OK wise guy!

    Did you read the link above? EOF is a macro which holds a value representing a "state", or a "status condition", indicating if the end of a file has been reached.

    From the ANSI C Standard:

    7.19 Input/output <stdio.h>
    7.19.1 Introduction

    1 The header <stdio.h> declares three types, several macros, and many functions for performing input and output....

    ...3 The macros are...

    which expands to an integer constant expression, with type int and a negative value, that is returned by several functions to indicate end-of-file, that is, no more input from a stream;
    The operating system and file system know where the end of the data is. This is different than the "file size" reported by Windows Explorer, which is based on the cluster / file allocation unit size, and includes unused/wasted space in the cluster.
    Last edited by DougDbug; 09-02-2004 at 05:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. EOF Explanation Anybody?
    By blackcell in forum C Programming
    Replies: 1
    Last Post: 01-29-2008, 09:09 PM
  2. EOF or not EOF?
    By CornedBee in forum Linux Programming
    Replies: 2
    Last Post: 09-14-2007, 02:25 PM
  3. EOF messing up my input stream?
    By Decrypt in forum C++ Programming
    Replies: 4
    Last Post: 09-30-2005, 03:00 PM
  4. whats the deal with EOF really ???
    By gemini_shooter in forum C Programming
    Replies: 7
    Last Post: 03-06-2005, 04:04 PM
  5. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM