I'd like to teach the world to c
I'd like to teach the world to c
Huh?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
ehem, cough, sorry ahd some problems there with awriting a post thinking I was logged in, but turns out I wasn't, so I lost it.
Anyhow, keeping with the subject, I'd like to read in some variable values from a setting text file, which goes like so:
varname = value
so
fscanf(filein, "%s = %i", varname, &value);
would *roughly* be what I'd do ...
If the order of the variables names is observed, and known to the program the job is not too difficult. But if not - and it would be more robust - the program needs to recognise the varname is the correct. strcmp() would be the way here and then a conditional assigning.
Is there a more direct way? JUst looking for hints. I apologise for the poor wording.Please understand it's the second time I write this post.
Thanks in advance. Cheers.
Still not sure what you mean, need to explain by giving a clearer example.
I think what he means is if having a config file like for example
he wants to parse the file and use the rvalue in his code by looking up the lvalue. If so then any implementation of a linked list should do, and you could do something likeCode:Name = My Name Age = 123 DecimalVar = 3.3
Code:struct Variable { const char* Name; void* Data; int VariableType; struct Variable* next; } struct Variable* list = NULL; ParseConfigFile("filename.txt", &list); const char* name = GetStringVar(list, "Name"); int age = GetIntVar(list, "Age"); float floatVar = GetFloatVar(list, "DecimalVar"); SetStringVar(list, "NewStringVar", "Hello World!"); SaveConfigFile("filename.txt", list);