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)?
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.
Heh. So many ways to answer this question...
No.
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?
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.
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
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?
1. Start notepad.
2. Click on File->Open.
3. Select the file.
4. ???
5. Profit!
That don't work. I tried and when I opened the file all I saw was a bunch of jumble text.
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.
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?
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
3 | |
4 | int 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 | } |
How do I write them as string?
By not using ios::binary?
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.
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.
You can change the file associations with Windows Explorer. I'd give you detailed directions, but I don't have Windows in English.
... lost cause, people. Lost cause.
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:
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.