2

Hello I am new to Arduino and C programming. I wanted to parse string using sscanf fuction

This is my Program

String hith;
int field1,field2;
float field3;
int F1=0,F2=0;
float F3=0;
int h1,h3;
float h2;
void setup() {
 
 Serial.begin(9600);
}
void loop() {
 field1=5;
 field2=6;
 field3=56.67;
 F1=field1;
 F2=field2;
 F3=field3;
 hith =hith+F1+","+F3+","+F2;
 Serial.println(hith);
sscanf(hith.c_str(),"%d,%f,%d",&h1,&h2,&h3);
Serial.println(h1);
Serial.println(h2);
Serial.println(h3);
 hith="";
 delay(1000);
}

I am only able to Parse Integer values but not Floating points.

asked Jun 28, 2021 at 16:26
1
  • 4
    %f is not implemented in the Arduino world. Commented Jun 28, 2021 at 17:21

1 Answer 1

1

On 8-bit Arduinos support for %f from printf and scanf (and related functions) has been removed to save space.

Instead you should look at parsing the string into chunks with strtok() and use atof() to convert relevant chunks to floating point.

answered Jun 28, 2021 at 20:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.