Basic file reading?

BlitzMax Forums/BlitzMax Beginners Area/Basic file reading?

IKG(Posted 2007) [#1]
I just need help understanding the basics of reading opened files. I want to be able to open a text file, jump from line to line, and read values separated by spaces or special signs.

I brought this up in a thread awhile back, but it kinda went off-topic and now I need to know. I know this is a broad question, but maybe some of you have some simple examples? I'm not looking for source code to use; just something to learn from.

Thanks :)


bradford6(Posted 2007) [#2]
I accidently posted here and felt kind of bad for not giving a decent answer.

so i knocked this up. I hope it helps:



this should handle reasonably complex files. keep in mind that 'proper' csv parsers probably can identify fields that have commas in them (usually by wrapping them in quotes:

john smith , "13444 lollypop lane,sarasota, fla" , meateater

the above would be 5 elements in my code but should be 3 elements. should not be too hard if that kind of complexity is what you are after. but to be honest, if you get to the point where you need *proper* CSV reading, you should maybe move on to XML. Brucey and John J both made excellent XML modules for Blitzmax


Chris C(Posted 2007) [#3]
consider looking at bruceys xml module

although seemingly complex to begin with xml is well worth the investment

implementing new "fields" or properties in loader and saver code is dead easy as your not stuck to scanning through looking for n number of commas...


bradford6(Posted 2007) [#4]
I Wholeheartedly agree!

a CSV parser may be good for looking at simple spreadsheet created docs. (excel can out put into a CSV) but if you miss one comma in your loader, you are screwed.

I have been using Bruceys XML module lately and i really like it. If you have a specific file structure or data & you want a simple example, past it here.


IKG(Posted 2007) [#5]
Thanks guys, but I'm not looking for any specific way to make files, or source code to build off of. I just want to learn the basics of file reading and writing in BlitzMax :)


Blitzplotter(Posted 2007) [#6]
Nice piece of code bradford.


smilertoo(Posted 2007) [#7]
There's basis file handling examples in the blitzmax help system.