Hello,
I'm new to arduino and programming in c++ in general but have some experience in java. I'm attempting to make a function that would parse an incoming string and place the resulting (int)'s into an array (input looks like "123,52,152," or "1,412,54," each number can be 1,2 or 3 digits... output is an int[]).
However even on the most simple testbed, every time my function is called, the board resets. It seems to output 2 of the three expected numbers correctly, but the first number always comes back as a much larger one. I've been reading about memory leaks in c++ (still don't have a real good handle on it), and thought that might be an issue (i guess i'm pretty lazy, coming form java

). Is that a valid concern given the limited size of my program?
Any suggestions about my ineptitude or a more efficient way of parsing this data would be greatly appreciated!
(ps. probably doesn't matter, but there is nothing connected to the board, i'm just running the program)
void setup(){
Serial.begin(9600);
Serial.println("setup");
delay(10);
}
//loops once every second.
void loop (){
Serial.println("looping");
delay(10);
//This string is would come over a serial port.
String output = "123,152,35,";
parseData(output);
delay(3000);
}
//Takes the string from the input and parses it into an int array. using ',' as a delimiter Finally prints out the vale
void parseData(String input){
int currentBrightnessArray[] = {0,0,0};
int returnCounter = 0;
int currentNum = 0;
//the loop looks for the delimiter and adds each digit (currently type char) into a substring,
//which is turned into an int. then the space in the string is set to ' ' and trimmed off.
while(input.length() > 0){
input.trim();
int nextCommaPosition = input.indexOf(',');
input.setCharAt(nextCommaPosition, ' ');
char currentSub[nextCommaPosition-1];
for(int counter = nextCommaPosition-1; counter >= 0; counter--){
currentSub[counter] = input.charAt(counter);
input.setCharAt(counter, ' ');
}
int temp = atoi(currentSub);
currentBrightnessArray[returnCounter] = atoi(currentSub);
returnCounter++;
}
//values of array are printed out.
Serial.print("Output =");
Serial.print(currentBrightnessArray[0]);
Serial.print(", ");
Serial.print(currentBrightnessArray[1]);
Serial.print(", ");
Serial.println(currentBrightnessArray[2]);
}
Thanks!
~Jester