printf, sscanf, and floating point numbers

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm (ultimately) trying to get a floating point number out of a string. At the moment, however, I'm just trying to get one to print. Here's what I'm trying: percent sign got replaced with #

   float i = 2.1;
   printf("i: #f \n", i);

and i comes out as a question mark ("?")... what am i doing wrong here? This seems to fall in line with all the examples I've looked at. thanks :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Project | Project-Options | Libraries:
"libprintf_flt.a" added?

/Martin.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As Martin pointed out, the default printf library does not come with floating-point support. If you read the Avr-libc manual entry on vprintf you will find more information about this.

Stu

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i'm not using avr-studio since i'm on a mac. I think my makefile already includes the right stuff. I've attached it, since it's pretty long. I had to save it as a txt to please the forum god

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

never mind, figured it out

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

no it is not set up, you need to fill in the RHS side of the PRINTF_LIB= line to be PRINTF_LIB_FLOAT

PRINTF_LIB = PRINTF_LIB_FLOAT

Writing code is like having sex.... make one little mistake, and you're supporting it for life.