Hello DaniWeb!
I've created a function that parses a long string of text (JSON format, but that's not really important) for the specified JSON key/variable name, and it returns the JSON value as pointer to a char array.
For example,
//the function looks like:
char* extract_key( char* buf, char* find_this_key )
//this is how i've been calling it, if the JSON values are car_color and car_maker
char* color_of_car = extract_key(buf, "car_color");
char* brand_of_car = extract_key(buf, "car_maker");
where buf is the string and find_this_key is what we're looking for.
My problem is that I constantly use this function in different parts of my program, and I've found that even though this function is creating dynamically allocated char arrays and returning those, they are being overwritten (I think, since I'm getting bus errors) by the function when it is called again.
I'm new to C++ and am still understanding pointers. What I wanted to do was save the value of the function every time it is called into a local char array, so how would I go about this? Dereference the function? If I need to design this differently, I'm open to any suggestions, I really appreciate it.