Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Float in sscanf on Teensy 3.1

  1. #1
    Junior Member
    Join Date
    Feb 2015
    Posts
    2

    Float in sscanf on Teensy 3.1

    Hi, I am trying to parse a string with floats in it using sscanf. I know the avr-gcc lib doesn't allow using %f format specifier, but since teensy 3.1 uses an cortex-m4 and hence the arm gcc compiler shouldn't something like this work?
    Code:
    float num;
    sscanf("23.4", "%f", &num);
    Running a sketch like this results in 0.00 value for num instead of 23.4

    Need help

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    19,922
    Here's the magic trick you need:

    Code:
    void setup() {
      // this is the magic trick for printf to support float
      asm(".global _printf_float");
      
      // this is the magic trick for scanf to support float
      asm(".global _scanf_float");
    }
    
    void loop() {
      float f;
      sscanf("123.456", "%f", &f);
      Serial.println(f);
      delay(1000);
    }

  3. #3
    Junior Member
    Join Date
    Feb 2015
    Posts
    2
    Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •