I'm having some issues using itoa I can't seem to figure out. The principle is simple, I am using a 2dimensional char array. For dealing with quantity I use atoi to make it all happy and then I want to use itoa to convert it back into a string because the inventory array is of type char.
It all works until I hit the itoa line. Then it gives me a access violation error. More accurately, this one
Unhandled exception at 0x63ed144c (msvcr90d.dll) in InventSystem.exe: 0xC0000005: Access violation writing location 0x00067768.
I know this means that there's something i'm doing wrong regarding the actual implementation. I found many examples using itoa in single arrays (as strings are all 1d char arrays at heart), perhaps there is something about 2d arrays i'm missing?
I've isolated the snippet of code I think is necessary to run. Any and all help greatly appreciated.
#define SIZE 12
// The 2 dimensional arrays, Inventory is the items you hold, wildItems are the items you find in different zones. The first field is the name, the second field quantity, and third is zone.
char *Inventory[SIZE][2]= {{"HP Potions", "10"}, {"Mana Potions", "10"}, {"Map","1"},{"", ""},{"", ""},{"", ""},{"", ""},{"", ""},{"", ""},{"", ""},{"", ""},{"", ""}};
char *wildItems[][3]={{"HP Potion", "1", "1"}, {"Apple", "2", "1"}, {"Apple", "2", "2"}, {"Rusty Spoon", "1", "3"},{"Rusty Spoon", "1", "1"}};
int arrayIter;
int x;
for (arrayIter=0;arrayIter<SIZE;arrayIter++){
if (Inventory[arrayIter][0] == wildItems[storeSpots[itemSelect-1]][0]){
x =atoi(Inventory[arrayIter][1]) + atoi(wildItems[storeSpots[itemSelect-1]][1]);
itoa(x,Inventory[arrayIter][1],10);
}
else if (Inventory[arrayIter][0]==""){
Inventory[arrayIter][0] = atoi(wildItems[storeSpots[itemSelect-1]][0]);
x =atoi(Inventory[arrayIter][1]) + atoi(wildItems[storeSpots[itemSelect-1]][1]);
itoa(x,Inventory[arrayIter][1],10);
break;
}
}