Moving EOF's position in a file

This is a discussion on Moving EOF's position in a file within the C++ Programming forums, part of the General Programming Boards category; Hello, I'm trying to read input from a file to the screen using the fstream library. But what i want ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Moving EOF's position in a file

    Hello, I'm trying to read input from a file to the screen using the fstream library. But what i want to do is to shift the position of EOF to make the input stop at supposedly half the file and not at the end.

    Any help is appreciated.
    Last edited by tonit; 01-02-2011 at 12:03 AM.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    As you read, check for that value. When you detect it, stop reading.

    Quote Originally Posted by tonit
    But what i want to do is to shift the position of EOF to make the input stop at supposedly half the file and not at the end.
    Right, so your requirements changed

    Read the entire file and discard the second half, or find out the size of the file and then read just the first half.
    Last edited by laserlight; 01-02-2011 at 12:20 AM.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Thank you for your quick reply. But i'm curious if i can play around with EOF. So i can make EOF(Supposedly) "End of half-file" instead of "End of File".

    Hope i expressed my point clearly here.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    Quote Originally Posted by tonit
    But i'm curious if i can play around with EOF. So i can make EOF(Supposedly) "End of half-file" instead of "End of File".
    No. EOF is just a macro for a negative value used to indicate end of file has been reached.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That is to say, at least on pretty much every system still running, there is no actual "end-of-file" character in a file.

  6. #6
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,288
    You can't decrease a file's length on some OSes. You can under Windows, but not under Linux afaik. In Linux I'm told that you read in the file and write half of it out again and then delete the original file. So, what OS?
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,310
    hmm... so, are you trying to truncate the file to half its length, or are you trying to only read half of the file?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Quote Originally Posted by iMalc View Post
    You can't decrease a file's length on some OSes. You can under Windows, but not under Linux afaik. In Linux I'm told that you read in the file and write half of it out again and then delete the original file. So, what OS?
    I'm working under the windows platform.

  9. #9
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,420
    SetEndOfFile Function (Windows)
    Bookmark the top level if you're into Win32 programming.
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,230
    Quote Originally Posted by iMalc View Post
    In Linux I'm told that you read in the file and write half of it out again and then delete the original file.
    That would be insane. You just call truncate().
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File Writing Problem
    By polskash in forum C Programming
    Replies: 3
    Last Post: 02-13-2009, 09:47 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  3. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  4. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  5. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21