I am trying to take a string of numbers and commas, then separate the numbers from the commas and turn them into ints and store them into an array. I print out the array in the while loop, and it works perfectly fine, but when I try printing the array outside of the while loop it outputs random numbers that change every time. I'm assuming it has something to do with pointers or data storage but I don't know why.
I know that the numbers in the array are correct and ints since I can do mathematical operations to them without resulting in errors, but for some reason as soon as it exits the while loop all the numbers change to random ones.
int commaCount = CntComma(point);
int numArray[commaCount];
//run a while loop to take strings and turn them into ints, then store them in a 1D array
while(point.find(",") != std::string::npos){
int i = 0;
int commaLocate = point.find(",");
string subPart1 = point.substr(0, commaLocate);
numArray[i] = stoi(subPart1);
point = point.substr(commaLocate + 1, (point.length()-1) - subPart1.length());
i++;
}