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.

Author
Message
Arius Myst
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 28th Aug 2003 17:39
There is probably a very simple answer to my question. I've never actually written or read a file in a language before(I usually open the file using a control OOP like). So could somebody help me out with this please. I'm trying to read all the strings from a file, line by line, and then display them. I know this code is wrong, but its what i've been using as a simple test:



Eventually i want that function to load all of my level data. When i run that function the first line in the file displays fine. After that i get a lime green screen(I havent tested the theory but id imagine its that colour because of the ink setting). If i then press Esc to try and quit the program i get a GPF. Could somebody give me a commented example of how to do this please.

Thnx,

¥öü ®å§Ë tHË ß|å�Ë, ¥öü måkË tHË ÇHåñgË, ¥öü ®Ëå®åñgË mË tî|| î'm §åñË
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 28th Aug 2003 18:33 Edited at: 28th Aug 2003 18:34
save your text as a basic TXT file, no font or formating data, many text formats like those from word can have control characters embedded (rather like an html page) that mess up the reading (as you found), either make a simple DB editor to save the data with or use a simple ascii txt file, save it as either "text" or "text document MsDos format" otherwise the control codes in more elaborate formats like word 6.0 will give you problems, your code should read the files fine, just remember to close the file when you finish reading it, cheers.

Mentor.
the_winch
23
Years of Service
User Offline
Joined: 1st Feb 2003
Location: Oxford, UK
Posted: 28th Aug 2003 19:03 Edited at: 28th Aug 2003 19:05
Other than checking the file exists before opening it and closing it after you finished using it there is nothing wrong with the code apppart from if there is only one string in the file it will cause problems when you try to read a string that isn't there.

Darkbasics file access is similar to most other basics. So you can have a look at how it's done in other basics that have better documentation to get the general idea if you have never used this type of file access before.

For editing text files use notepad, any program described as a text editor should work.

I changed your source to check the file exists before it opens and to load a string and print it to the screen until it reaches the end of the file. click the code button undet this post.

edit: if you change the ink colour to the same colour as the background of course you won's see anything.

Login to post a reply

Server time is: 2026-07-25 08:11:51
Your offset time is: 2026-07-25 08:11:51