Advertisement

File formats read and write.

Started by October 11, 2000 04:25 AM
11 comments, last by DefaultUser 24 years, 2 months ago
Hi! Where I can get more information about how to make or read-and-write your own data file, like a .map or a .dat file. I want to put all my arts and maps inside a single file but I don''t know how. -Thanks
Forget about that buggy code, let's start all-over - from scratch. Let's go!

Buy a C/C++ book..
Advertisement
Or go thru some of the Tutorials on this side.
You can find them under http://www.gamedev.net/reference/programming

There also links to some Basic Tutorials for different Programming Languages.

Lars
--------> http://www.larswolter.de <---------
Beware the pitfalls of custom resource files!! I thought it would be a great idea to add this to my game, little did I know the difficulties involved. My resource file was for bitmaps only. I figured I could point Windows to the file and give it an offset, but no... Micro$oft could never make it that easy. I had a choice, extract the bmp to its own file, then call LoadImage(), or write my own custom bitmap loader. I chose the latter, but given the dearth of information on the topic, and the general lack of knowledge on how to do so here (although there are a few ppl on here who really kick ass and had some helpful bits for me), made it an extremely painful and ardous process... who knew that BITMAPINFO::bmiHeader.biSizeImage was incorrect?? (kinda invalidates the purpose of this member doesnt it??)

Sorry if that has nothing to do with your situation, I just wanted you to be aware of the difficulties involved! Good luck!
There is no spoon.
I would just like to step in here and point out that the post directly above mine is a perfect example of the kinds of misinformation that floats around here all the time.

Coming up with your own file formats and the associated reading/writing code is a completely, utterly normal and commonplace occurence. To argue that its "dangerous" is like saying "Be careful! Learning how to program exposes you to all the problems of programming!".

I encourage you to experiment with file io through tutorials or just a garden variety how-to C/C++ book (using straight C stdio stuff is a great way to get the basics going). Its an excellent, _beginner_ level skill to have.
Volition, Inc.
I agree with daveb, that creating your own file formats / learning file io with something that you understand is a good way to learn file programming.

One bit of advice for you, before you start to design your .map/.dat/.myformat/.bmp/.pcx./jpg file format en-/de-coder sit down and write out the file structure and make sure you understand it before you start, I''ve often started to code something up and half way though it I''ve had to ethier re-start or scrap the project as I did not fully understand the file format.

The first file format I read was the Amiga IFF format, it''s a wounderful all singing all dancing do all end all file format. The IFF stands for Interchangable File Format, it could hold a sound file, an image, a word processed document, anything. It was easy to understand, but a swine to code because you had to read in 4 bytes, and see if the following bit of data is ok for your app, thus a lot of the file is redundant. If you want to see what this format is like jump over to wotsit.com and look up ILBM.

I know there is probably a lot of dribble in this reply, but some of the pitfalls that I have experience were from lack of documentation, which is what this reply is suppost to convay, i.e get some documentation wrote up for your own formats, get documentation on any formats that you want to read, then study them carefully before you start to program.
When I find my code in tons of trouble,Friends and colleages come to me,Speaking words of wisdom:"Write in C."My Web Site
Advertisement
wotsit.com <-- are you sure this is the right address because It gives me nothing about file-formats?
Forget about that buggy code, let's start all-over - from scratch. Let's go!
That would be http://www.wotsit.org , actually.
fopen, fread and fwrite ftell(very handy ) are the functions I use for file io. Do a search for these functions and then experament.

Once you have a reader for a specific file format, you can easily append files to each other and read in the order that they were saved.
quote: Original post by WhatEver

fopen, fread and fwrite ftell(very handy ) are the functions I use for file io. Do a search for these functions and then experament.

Once you have a reader for a specific file format, you can easily append files to each other and read in the order that they were saved.



You neglected to mention fseek(). And the text mode functions.


------------------------------
#pragma twice


sharewaregames.20m.com

This topic is closed to new replies.

Advertisement