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
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;
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
There are a few issues with the code you provided First you need to read the input string from the ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get StartedRecommended Textbook for
Managerial accounting
Authors: ramji balakrishnan, k. s i varamakrishnan, Geoffrey b. sprin
1st edition
471467855, 978-0471467854
Students also viewed these Programming questions
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
Question
Answered: 1 week ago
View Answer in SolutionInn App