Reading/Writing tabled data

BlitzMax Forums/BlitzMax Beginners Area/Reading/Writing tabled data

kmac(Posted 2004) [#1]
Being absolutely new to this language I have a very simple question (probably to be followed by more).

Can one read and write tabled data using text files? Ideally, a solution similar to fscanf and fprintf would be great.

Thanks.


Perturbatio(Posted 2004) [#2]
at a guess, I would say it is unlikely to have a function that does exactly the same thing (I don't know much about C and only read a little about fscanf), however there's no reason you couldn't wrap the function in a mod.


kmac(Posted 2004) [#3]
Can't say I understand anything about mods. I just bought Blitzmax, though I've seen reference to MingW. Perhaps the functions from libc (?) are or will be made available.

Edit: Ultimately I'd like to read the contents of a table into a structure (e.g., firstname, lastname, age), then access individual records as needed.

Edit 2: I just had a closer look at the distribution. So, is GCC/MingW being used for the final compilation?


skidracer(Posted 2004) [#4]
Check out the ParseArg function in the BPaint demo (line 116).

It returns the first item of the string and removes it from the input string so you can use it like this:

a$="one,two,three"
while a$
print ParseArg(a$)
wend

which will print out

one
two
three


kmac(Posted 2004) [#5]
Thanks.

What I like about fscanf is that for space separated columns whitespace is considered the separator. A variable number of spaces doesn't affect the reading of the table. Additionally, each item is read into the proper type without explicit conversion (e.g., itoa, atoi). No doubt as I learn more a solution (of some form) will materialize using the existing facilities. Again, I know next to nothing about this language.

That said, what does one have to do to make the standard c functions available?

Thanks.


FlameDuck(Posted 2004) [#6]
It seems like what you're looking for is a StringTokenizer. I was going to convert one over from Java, but ran into a wall, since BlitzMAX didn't support overloaded functions (or private constructors).

You can still write one ofcourse, you just have to be more careful when using it (a white-box solution).