Thread: getc() says $1A = EOF! Wtf?

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    11

    Question getc() says $1A = EOF! Wtf?

    I've just spent a few hours trying to work out why my level editor wasn't loading certain level files properly. After a certain point, everything byte starts returning EOF, -1.

    Turns out it was the $1A character tripping it up. I did a bit of searching around and all I could find was one thread by another person with the same problem and some source code with a comment about how $1A is meant to mean end of file in the DOS instruction set or something. Strange.

    Can anyone tell my why this happens, and how I can get around it?

    Cheers.

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    AFAIK EOF should not cause a problem. EOF is not recorded in the file but in the file system. EOF in DOS was placed in the last cluster of the file. So when the next FAT cluster indicated EOF, DOS stopped following the cluster chain. In other words EOF is encoded below the level of the actual file object. It is part of the file cluster chain.

    But you probably want to open the file in binary mode so no interpretation is done on the binary data in the file.

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    11
    Thankyou! Switched "r" to "rb" and it works beautifully. I hadn't realised there was a separate binary mode. Amazing what difference one character can make.

  4. #4
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    869
    Indeed, MS-DOS distinguishes between text mode and binary mode. One of the "features" of text mode is that when you're reading a file and you get the '\x1A' character, that signifies end of file.

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. files won't stop being read!!!
    By jverkoey in forum C++ Programming
    Replies: 15
    Last Post: 04-10-2003, 05:28 AM
  5. getc or not getc that is the problem
    By Juan Roberto in forum C Programming
    Replies: 3
    Last Post: 11-13-2001, 12:43 PM