September 1st, 2003, 12:21 AM
Parsing a config in C
I want to incorporate a configuration file into some of my programs but I have no idea where to start. I googled it and didn't find much.
I'm trying to get something like this working:
name = "chris"
dl_dir = "C:\chris\"
age = "15"
Any links, help or bits of sample code would be appreciated !
September 1st, 2003, 12:27 AM
hehe I meant
September 1st, 2003, 03:38 AM
after reading the line from the file you can use token for parsing the string
char separator = " \"";
//string is the string that you want to parse
token = strtok( string, separator );
while( token != NULL )
printf( " %s\n", token );
token = strtok( NULL, seps );
hope this solves your problem
September 1st, 2003, 08:32 AM
September 1st, 2003, 09:56 AM
September 1st, 2003, 10:39 AM
I looked at the other thread, mitakeet but I've never seen this before:
std::map < std::string, std::string > myMap;
std::map < std::string, std::string >::iterator myIterator = myMap.begin();
September 1st, 2003, 10:44 AM
It is C++. You can do the same thing with C but it is very painful. Unless you are stuck in the C world, I suggest you try to make do with the C++ version (the C version would probably be 4 times as long).
September 1st, 2003, 11:04 AM