data corruption in structs

I've got a struct outlined as such:

1
2
3
4
5
struct PidStruct {
	string KeywordValues[NUM_OF_KEYWORD - 14]; //only need the first eight keywords
	string HwInfo[MAX_HID][NUM_OF_KEYWORD];
	unsigned short HwCount;
}; //end of struct for the program identifier 


where the two string arrays store independant values from one another. Later In my program I parse through a file to locate these and store them into their respective arrays.

however it seems like whenever i write to PID.HwInfo[X][8 or 9] for any value X under 256, it will also write the value into PID.KeywordValues[16 or 17] where the '8' value directly correlates to the '16' value.

ie, PID.HwInfo[X][8] = "Hello";

will also cause: cout << PID.KeywordValues[16] << endl; to result in "Hello"


the opposite is also true where I can write PID.KeywordValues[16] = "Welcome" ;

will also cause cout << PID.HwInfo[X][8] << endl; to result in "Welcome" as well.



Also when I tried to move the order of the variables around in my structure that it would still corrupt but just to other locations. I'm assuming that for some reason I'm getting data corruption for some reason but I'm not quite sure why. any ideas?
Last edited on
What is NUM_OF_KEYWORD ? Aren't you just reading out of bounds?
NUM_OF_KEYWORD and MAX_HID are both pre-defined constants. Whenever I'm reading/writing it's under that limit.

NUM_OF_KEYWORD == 22 and MAX_HID == 256
You are. There are 22-14 = 8 elements in KeywordValues. There is no 16th and 17th elements. You're just reading the contents of HwInfo.
Topic archived. No new replies allowed.