File format

This is a discussion on File format within the C++ Programming forums, part of the General Programming Boards category; How does one create their own file format in c++? I'm going to store some rather complex data for a ...

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    33

    File format

    How does one create their own file format in c++? I'm going to store some rather complex data for a game I am writing, and the .txt or .dat format is to convoluted and not exatly what I'm looking for.
    “Focused, hard work is the real key to success. Keep your eyes on the goal, and just keep taking the next step towards completing it. " -John Carmack

  2. #2
    sockets mad
    Join Date
    Mar 2002
    Posts
    126
    File formats are literally whatever you want them to be. C allows you to have byte for byte control of a file, so you design your file format around your requirements. As long as you write the code to both write and read the contents of the file, it's up to you how it's stored.

    It's a good idea to know the file manipulation routines very well if you want to get the most out of designing your own format.

    There are some C/C++ techniques which are used a lot in the reading and writing of files, but I'll leave that to someone else, since I don't know a huge amount on that.
    C/C++ Support IRC Channel

    Server: irc.dal.net Channel: #csupport

    Come along and help make it a great resource for the community.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Technically all files look the same. It's the file loader that decides how to decipher what's in it. As an example, Notepad uses the ASCII table to decipher txt files.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398
    Take a look at some of the .ini files on your computer (I'm assuming Windows). A format like that is probably the simplest, if it will work in your application.

    If you want to look at some more complex file-format specifications, check-out wotsit.org. Of these standard formats, the simplest that I know anything about are .wav, and .bmp.

    As far as I know, there isn't one .dat standard. Lots of programs use the .dat file extension to save data in their own proprietary formats.

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Even INI files requires minor token parsing, like [ and ].
    If you want simplicity, use something like this:
    Code:
    Enemy
    Name Goblin
    Health 100
    Mana 0
    
    Enemy
    Name Flying_Bird
    Health 80
    Mana 200
    ...or something. All you do is some iterative file reading/writing with an std::string.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  2. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

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