Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Writing/Reading Files *Help*

Author
Message
Antigroup
16
Years of Service
User Offline
Joined: 21st Jan 2008
Location:
Posted: 24th Jul 2008 02:56
Ok I have just started looking at the file section of the DarkGDK commands and I thought I had the idea but it seems that it doesn't work right. Could anybody tell me what I am doing wrong here. I set up a simple set of statements to write a few values to a file which I was going to see if I could read them back in the right order. Here is the code that I set up to write it.

dbMakeFile("test.txt");
dbOpenToWrite(5,"test.txt");
dbWriteString(5,"This is a test.");
dbWriteByte(5,number);
dbWriteFloat(5,floatpoint);
dbCloseFile(5);

This went before the main loop.
It created test.txt where I expected it to be but it doesn't have anything in it. What is wrong here?
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 24th Jul 2008 03:03 Edited at: 24th Jul 2008 03:06
It seems as if that should work, and I'm not quite sure why it doesn't. Personally, I think this approach works better: (fputs tutorial)


Globstuct.h and Windows.h are only for the MessageBox() command, it's not necessary and can be taken out if you so choose.

Why are you calling dbMakeFile()? With dbOpenToWrite() the file should be created if it doesn't already exist.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 24th Jul 2008 03:07
I recommend standard C++ file I/O commands over the GDK commands. It takes a little extra to learn, but is much better in the long run; mainly due to portability and the fact that there is so much information on it in comparison.

http://www.cplusplus.com/reference/iostream/

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
SunDawg
19
Years of Service
User Offline
Joined: 21st Dec 2004
Location: Massachusetts
Posted: 24th Jul 2008 03:09
Can't get much more standard than the functions in stdio.


My site, for various stuff that I make.
Mahoney
16
Years of Service
User Offline
Joined: 14th Apr 2008
Location: The Interwebs
Posted: 24th Jul 2008 03:13
Yes, but stdio is outdated. It's all in C. I think iostream is the best way to go.

Windows Vista Home Premium Intel Pentium Dual-Core 1.6 Ghz 1GB DDR2 RAM GeForce 8600GT Twin Turbo
Antigroup
16
Years of Service
User Offline
Joined: 21st Jan 2008
Location:
Posted: 24th Jul 2008 03:29
I don't know many of the standard libraries in C++ or winAPI. I have yet to learn that. That is why I used the GDK commands.
And for some reason I didn't see that It was not supposed to exist.
It seems to work without dbMakeFile but the byte and float look wierd. Im going to see if I can read the data in the correct order.
Here is the file it made.
This is a test.
ö(HA
I think that the square thing is the byte and the other 4 are the 4 bytes that make up a float.
Antigroup
16
Years of Service
User Offline
Joined: 21st Jan 2008
Location:
Posted: 24th Jul 2008 03:39
ok reading it works but the byte and the float look weird at their first letter but the rest of it is what it should be.

Login to post a reply

Server time is: 2024-09-30 03:32:32
Your offset time is: 2024-09-30 03:32:32