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.

Newcomers DBPro Corner / file writing/reading issue

Author
Message
Masqutti
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location: insanity
Posted: 15th Mar 2010 15:56
Hi!

This might be just a simple thing that I haven't discsovered, but, how do I save a file in a format that I could open it let's say in notepad and it would be a readable. Same to reading it then.

Like, how do I save a string "hello world" into a file "hello.txt", open it in notepad so it's readable, let's say i'll change it to "hello to you too", load the file in DBpro project and print it to the screen. Is there a way?

I'd like to have a "setup.ini" type file where to declare some variables etc.

hmmmh.. that didn't compile
LBFN
17
Years of Service
User Offline
Joined: 7th Apr 2007
Location: USA
Posted: 15th Mar 2010 17:01
Here is some code to help you with it.



I would suggest saving the source file first and then reload the source so that you will know where it will write the files. You can indicate in your code where you want the file to be written, but the example simply writes a file in the current directory.

Run the code. Find the 'hello.txt' file and open it. Make the edits to it and save it and then re-run this program.

I hope this helps.

Masqutti
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location: insanity
Posted: 15th Mar 2010 17:26
Oh my.. It really was that easy Thanks! I remember trying that someday and it just wrote unreadable data but.. It seems fine now

hmmmh.. that didn't compile
TDK
Retired Moderator
22
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 15th Mar 2010 17:41
Quote: "I remember trying that someday and it just wrote unreadable data"


You were probably not using Write String before. The other variable Save and Write options write encrypted data.

If you need any other info on loading/saving files:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

(Tutorial 4).

TDK

Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 15th Mar 2010 18:03
When you write data to a file it's written as binary (except for strings which are written as text). When you open a file in Notepad, you are seeing the ASCII representation of these values. For example, the ASCII value of 'A' is 65 (see here for a list of characters and their values), meaning if you write a byte of value 65 to a file, when you open that file in Notepad you'll see 'A'. If you want to view the values as text, you must write to the file using strings.

Masqutti
14
Years of Service
User Offline
Joined: 8th Jan 2010
Location: insanity
Posted: 16th Mar 2010 08:18 Edited at: 16th Mar 2010 08:56
Ok Thanks for the info ! I realized it now 8)
Great tutorials you have there TDK!! I haven't found em earlier thanks!

hmmmh.. that didn't compile

Login to post a reply

Server time is: 2024-11-24 17:55:13
Your offset time is: 2024-11-24 17:55:13