Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » DAT file question

This thread is locked; no one can reply to it. rss feed Print
DAT file question
blargmob
Member #8,356
February 2007
avatar

Howdy,

I want to create files in my program and save them as .dat for something. My question is, how do I save a .dat file with game data in it so that I can open it and edit it with notepad (txt)?
???

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

gnolam
Member #2,030
March 2002
avatar

Quote:

I'm using that allegro DAT grabber thingy that you can find somewhere on this website to make DAT files. My question is, how do I create a DAT file so that I can open it and edit it with notepad (txt)?

You don't.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

ImLeftFooted
Member #3,935
October 2003
avatar

Heh. So many ways to answer this question...

No.

blargmob
Member #8,356
February 2007
avatar

If you've played Soldat than you know you can edit the BOT files with notepad, how do I do that with my own game?

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

gnolam
Member #2,030
March 2002
avatar

Quote:

If you've played Soldat than you know you can edit the BOT files with notepad, how do I do that with my own game?

By not using DAT files.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

blargmob
Member #8,356
February 2007
avatar

Oh crap..... I made a mistake...... I was thinking about files that I save from my program......crap....hang on....lemme edit....

OK I EDITED REREAD POST

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

gnolam
Member #2,030
March 2002
avatar

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

blargmob
Member #8,356
February 2007
avatar

I know how to write files and read them and stuff, but how do I take that file and open it up in the windows app NOTEPAD and edit it like it was a .txt doc?

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

gnolam
Member #2,030
March 2002
avatar

1. Start notepad.
2. Click on File->Open.
3. Select the file.
4. ???
5. Profit!

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

blargmob
Member #8,356
February 2007
avatar

That don't work. I tried and when I opened the file all I saw was a bunch of jumble text.

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

Matthew Dalrymple
Member #7,922
October 2006
avatar

Quote:

That don't work. I tried and when I opened the file all I saw was a bunch of jumble text.

Then stop writing jumbled text to it

EDIT:

Are you just writing variables to it or are you converting to a string first? If you want it to be readable you need to write everything as a string to the file.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

blargmob
Member #8,356
February 2007
avatar

How do I write everything as a string? I'm using fstream and stuff to write teh files. I'm writing them as ios::binary. How do I write them as string?

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

moon_rabbits
Member #8,469
March 2007
avatar

1#include <stdio.h>
2#include <stdlib.h>
3 
4int main ()
5{
6 FILE* file; // pointer to a file
7
8 int x = 10;
9 char number[3];
10 
11 /* itoa ( int value, char * str, int base )
12 Stores value in str. Base is the base of the number being stored,
13 ie: base2 (binary), base8 (octal), base10, base16 (hexadecimal) */
14 itoa(x, number, 10); // stores x in number as a base10 number
15 
16 file = fopen ( "yourfile.bin" , "wb" ); // open your file
17
18 /* fwrite(const void * ptr, size_t size, size_t count, FILE * stream)
19 Writes ptr to stream. Size is the size of one element in the array
20 pointed to by pointer (hence sizeof()), and count is the amount of
21 elements to be written from ptr, all with size equal to size */
22 fwrite (number, sizeof(number[0]) , sizeof(number) , file );
23 fclose (file); // close up
24 return 0; // done!
25}

HardTranceFan
Member #7,317
June 2006
avatar

Quote:

How do I write them as string?

By not using ios::binary?

--
"Shame your mind don't shine like your possessions do" - Faithless (I want more part 1)

Hard Rock
Member #1,547
September 2001
avatar

Okay hopefully this link should help:

http://www.cprogramming.com/tutorial/cfileio.html

Basically there are two ways to write files, Binary and Text. Notepad can only open text based files otherwise you get the jumbled mess that you are seeing. So you need to write text based files.

What moon_rabbits posted is technically wrong(it might work out okay because it only writes within the range of chars notepad can read, but didn't test it), if you want to write text based files instead of:

 file = fopen ( "yourfile.bin" , "wb" ); // open your file

you do

 file = fopen ( "yourfile.bin" , "w" ); // omit the b

Now it looks like you're using C++ so just google for C++ file i/o but make sure its not binary based, as that's what notepad cant read. Also you'll need to convert all your values and codes into pure text (so numbers should be written as letters) for notepad be able to read them.

_________________________________________________
Hard Rock
[ Stars Dev Company ][ Twitter ][Global Warming: ARA My TINS 07 Entry][Pong Ultra Website][GifAllegS Ver 1.07]
"Well there's also coolwebsearch but we'll let that be an IE exclusive feature" - arielb on the New Browser Plugins "What's better, HTML or Variables?"

blargmob
Member #8,356
February 2007
avatar

So basically all I gotta do is write teh files as a text file instead of binary? But I want teh file exstenstion to be unique, not .txt, but still able to open it with notpad.

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

Rampage
Member #3,035
December 2002
avatar

You can change the file associations with Windows Explorer. I'd give you detailed directions, but I don't have Windows in English. :P

-R

gnolam
Member #2,030
March 2002
avatar

... lost cause, people. Lost cause.

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Matthew Dalrymple
Member #7,922
October 2006
avatar

Quote:

But I want teh file exstenstion to be unique, not .txt, but still able to open it with notpad.

A fundamental thing you need to understand is that computers will do exactly what you tell them to do.

So if you want to save the file as a different extension, do so. File extensions are really to help with differing files between which programs should open them. That doesn't mean a program can open it and that others cannot. If you know a file is formatted for a program to open it correctly then so what if it doesn't have the same extension. Changing a *.doc file to *.poo doesn't mean Word can't open it. To open it up in Notepad do as gnolam suggested:

gnolam said:

1. Start notepad.
2. Click on File->Open.
3. Select the file.
4. ???
5. Profit!

You might need to have all files (*.*) instead of text files (*.txt) selected.
That is why he is saying this is a lost cause... as it is.

=-----===-----===-----=
I like signatures that only the signer would understand. Inside jokes are always the best, because they exclude everyone else.

Go to: