Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Managerial accounting

Authors: ramji balakrishnan, k. s i varamakrishnan, Geoffrey b. sprin

1st edition

471467855, 978-0471467854

More Books

Students also viewed these Programming questions