Jump to content

Home

Please help me parse an external file.


Vruki Salet

Recommended Posts

I have a simple file that's a list of paired keys & values, just like a server config file. Let's call it "stuff.cfg." I want to read the values and assign them to variables. Looking at the way the .sab and .npc files and the others is making my head spin. Will somebody help me here? Like walk me through it or direct me to instructions.

 

Here's a setup to work with:

 

stuff.cfg contains 3 lines like this:

 

fooInt 24

fopInt 0

fooString "yomama"

 

Then I have 3 variables like so:

 

int entNumberFoo

int entNumberFop

char *fooString

 

I have stuff.cfg read into memory in the name stuffData.

 

How do I parse stuffData so that:

 

entNumberFoo = the value of fooInt

entNumberFop = the value of fopInt

fooString = the value of fooString

 

???

 

BTW there's just one file to parse and no curly braced sections to separate. Being able to deal with // and /* */ comments would be nice but not necessary.

Link to comment
Share on other sites

I figured it out using BG_SiegeGetPairedValue like so:

 

BG_SiegeGetPairedValue(stuffData, "key_from_cfgfile", tempBufferVartoHoldData)

 

then used atoi(tempBufferVartoHoldData) if it had to be an int.

 

Thanks though. I'll still check it out to maybe get more understanding. If all goes well I'm going to have to write back to the file later.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...