Re: Bizarre char* problem
Okay, this one has me totally baffled. I have a function,
getParsedKey(char* key, char* returnString). I pass in the key I
want, it retrieves it from a data structure and puts the value in
returnString. The problem is that returnString points to the correct
value in the function, but after the function has finished, the string
that it points to is empty.
char* radioList = NULL;
bool iniparser::getParsedKey(char *key, char *returnString)
//for all the keys in the section
for (int i = 0; i < numKeysInSection; i++)
//returnString takes the value of the current key
returnString = strtok(iniSection[i],"=");
You change the *local* pointer here. This action has nothing to do
with the variable that you passed in.
//if the current key is the desired key
if ((strcmp(returnString,key) == 0))
//then returnString takes on the key's value
returnString = strtok(NULL,"\n");
You have 'newline' in a literal here...
//return the key's value
MessageBox(NULL,"KEY NOT FOUND","OK",NULL);
//if the key isn't found, return NULL
So, to clarify, radiolist gets passed to getParsedKey, which finds the
key "Radio" and puts the value assosciated with radio in the pointer.
While it's in the function, the pointer (returnString) points, as it
should, to the value. After the function has finished, however, the
pointer radioList points to an empty string. This has me totally
How about this:
foo(char const * blah)
blah = "DEF";
const char * blah = "ABC";
? Confusing as well?
I'm hoping I've made a noob mistake somewhere in the code
and that someone can kindly point it out to me, because I've been
staring at this and poking at it for many, many hours now, to no
Don't use plain pointers. Or pass the second argument by reference.
P.S: I'm working in the Visual Studio 2005 IDE
If you need a VC++-specific solution, you might want to post to
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask