Convert string to float

I program on the AVR XMEGA microcontroller using AtmelStudio.

I am having trouble converting a string to float. The string is called token2and matters"8.604165"

I have already tried several functions:

  • float lon = atof(token2); printf("lon=%f", lon); returns lon=?
  • float lon = strtod(token2, NULL); printf("lon=%f", lon); returns lon=?
  • float lon = strtof(token2, NULL); printf("lon=%f", lon);gives an error undefined reference to strtofincluding<stdlib.h>

Am I doing something wrong?

+4
source share
2 answers

So, this is something special for microcontrollers.

Just what I said @Sneftel, I just needed to add the library libprintf_flt.aand libm.ain AtmelStudio.

0
source

AVR-libc , . , atof, , , . printf , .

AVR-libc , printf. printf , , . , printf ( , ), printf_min, . , , printf_flt.

. , -Wl,-u,vfprintf -lprintf_flt -lm .

+5

Source: https://habr.com/ru/post/1652474/


All Articles