Question about c++ in arduino IDE I am trying to split a string using a ,
Question:
Question about c++ in arduino IDE
I am trying to split a string using a ", " as a delimiter.And then assign each integer to a variable:
For example:
Say you enter a string in this format: 1,2
Then the code will assign num1 = 1 and num2 = 2.
Please take a look at what I have. I can't find themistake.
int num1 = 0;
int num2 = 0;
char str[100];
int j = 0;
void setup() {
Serial.begin(9600);
Serial.print("Enter string in this format 1,2");
}
void loop() {
while (Serial.available() > 0)
{
j = 1;
}
if (j == 1)
{
char* point;
point = strtok(str, ",");
num1 = atoi(point);
point = strtok(NULL, ",");
num2 = atoi(point);
Serial.print("num1 = ");
Serial.println(num1);
Serial.print("num2 = ");
Serial.println(num2);
j = 0;
}
}
Managerial accounting
ISBN: 978-0471467854
1st edition
Authors: ramji balakrishnan, k. s i varamakrishnan, Geoffrey b. sprin