Thread: Files holding data

  1. #1
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640

    Files holding data

    I have to write a program that can access a file, read it, and hold it inside a dlinked list for database access. I was wondering though, the EOF character inside a file indicates that it's the last character of the file, right? So what if you write more data to the file after the EOF character? Where does the data go, if anywhere? Is it accessible? Thanks,

    christoph
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Picture the following:
    Code:
     char months[13] = "JFMAMJ\0JASOND";
    It's stored in memory as simply 13 bytes in a row associated with eachother just like any other string. But it's generally accepted that a string ends at the null ('\0') character, so passing something like this to a function that counts the words in a string would be the equivalent of only passing the first 7 elements of the array, because the function is programmed to stop at a null character.

  3. #3
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    But would it be possible (using higher access functions) to write past it?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    From the FAQ, EOF is not a character. A read function may return a value that equates to EOF when an error has been encountered or when there is no more input to process.
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

  5. #5
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> But would it be possible (using higher access functions) to write past it? <<

    Yes, of course, the file can be expanded. Why don't you try it? There is no actual EOF character at the end of files on modern systems. The size of the file is stored instead. The C/C++ file functions will return an EOF value when the end of the file is reached. However, this value is added by the C/C++ I/O system and does not physically exist in the file.

  6. #6
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    >>The size of the file is stored instead.

    Where is this information kept? I tried opening small files in a hex editor, but I didn't see any information about the size of the file. Or what you are talking about is file specific? Like, special files registered to software keep that as part of a format?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  7. #7
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> >>The size of the file is stored instead.
    >> Where is this information kept?

    It is not stored in the file. It is stored by the file system for each file. Just like the name of each file is stored, its last modification date, which directory it is in, etc.

    Let's look at an imaginary file system. Each file entry may look something like this:
    Code:
    struct fileEntry
    {
        char fileName[MAXPATH];
        char parentDirectory[MAXPATH]
        int flags; /* Read only, archive flags,  etc */
        time_t creationDate;
        time_t lastModDate;
        unsigned long long fileSize;
        unsigned long long positionOnDisk;
        sid securityDescriptor; /* Access restrictions, owner, etc */
    };
    Each file would have an entry. Most of this information can be retrieved with various functions. The only information actually stored in the file is the data you write to it.

  8. #8
    30 Helens Agree neandrake's Avatar
    Join Date
    Jan 2002
    Posts
    640
    Thanks for the insight, it's clearer now. So it wouldn't be possible to change the size of the file that is stored in the FS without the data being cut off?
    Environment: OS X, GCC / G++
    Codes: Java, C#, C/C++
    AOL IM: neandrake, Email: neandrake (at) gmail (dot) com

  9. #9
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    >> So it wouldn't be possible to change the size of the file that is stored in the FS without the data being cut off? <<

    I'm not sure what you are asking. Obviously, if the file is made shorter data will be lost, while if the file is made longer data will not be lost. There is no function in the standard C/C++ libraries to shorten a file (without starting from scratch).
    Last edited by anonytmouse; 11-23-2004 at 06:29 PM.

  10. #10
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    I imagine data-retrieving utilities work in the reverse of this (by looking beyond the bounds of the file system's set filesizes). Of course, that's also why they're not always successful, since you'll get stuff overwritten/corrupted when you don't have any protective markers saying "This here memory's part of a file".
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. xor linked list
    By adramalech in forum C Programming
    Replies: 23
    Last Post: 10-14-2008, 10:13 AM
  2. Storing and accessing data from and to .txt files.
    By Glauber in forum C++ Programming
    Replies: 9
    Last Post: 05-27-2008, 02:59 PM
  3. reading formatted data files
    By gL_nEwB in forum C++ Programming
    Replies: 5
    Last Post: 04-22-2006, 10:09 PM
  4. Adding files of numerical data
    By Boucho in forum C Programming
    Replies: 4
    Last Post: 02-06-2006, 05:27 PM
  5. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM