Loading Multiple Variables in sscanf

Asked 1 years ago, Updated 1 years ago, 115 views

I am writing a program that extracts strings and numbers from the strings entered in Arduino, but it does not work well.

char mode[6]=";
double a, b, c;
// str = "PID 1.42.4 3.4"
sscanf(str, "%s%lf%lf%lf", mode, & a, & b, & c);
// sscanf(str, "%s%lf%lf%lf", mode, &a, &b, &c); also tried

However, only the mode is loaded normally, and a, b, and c are 0.00.
I've tried many things, but it doesn't work.How can I fix it to work properly?

c arduino

2022-09-30 21:16

1 Answers

When I looked into it, I found the answer, and I was able to move it normally, so I will give you an answer.
It seems that Arduino's C++ does not have a %f conversion specifier, so %f cannot be used in scanf, etc.
The solution worked by reading a variable you want to read as a double type as a string using another variable and then converting it to a double type using atof.


2022-09-30 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.