I need help parsing an array of comma separated values and storing those values as characters. Here is a short sketch with my attempt and more info in the code comments.
/* This is a simplified problem I am trying to solve.
Given: Object of type String receivedString = "78,128,4";
Find: A solution to save the comma seperated values as type char.
Attempt: First: I transform the String Object into a Char Array receivedStringConvertedToArray[9];
Second: I try to use function strtok to parse for the first integer before the comma,
which is 78 but I only get the 7
*/
String receivedString = "78,128,4";
char receivedStringConvertedToArray[9];
//char separator[] = ",";
char separator = ',';
char *token;
void setup() {
convertString();
}
void loop() {
// put your main code here, to run repeatedly:
delay(1000);
parseStringForIntegers();
}
void convertString() // Convert String Object to char array[]
{
receivedString.toCharArray(receivedStringConvertedToArray, 9);
};
void parseStringForIntegers()
{
token = strtok(receivedStringConvertedToArray, &separator);
Serial.println(*token);
};