dtostrf function

cancel
Showing results for 
Search instead for 
Did you mean: 

dtostrf function

404 Views
Contributor II

I am tried to use the dtostrf() function to convert a floating variable to a string array but I am getting the following error  ../source/AdcSdkLcd.c:128:9: warning: implicit declaration of function 'dtostrf'; did you mean 'strstr'? [-Wimplicit-function-declaration].  What should I do to convert a floating variable to a string array?

Details:

Using MCUXpresso 10.3.0 IDE

Using Freedom Development Board FRDM-K22F

Trying to display an ADC voltage on a Hitachi 2X16 HD44780U Dot Matrix Liquid Crystal Display Controller/Driver

I am able to display an integer on the LCD with the itoa() function.

The ADC voltage is displaying correctly on the Tera Terminal.

0 Kudos
5 Replies

97 Views
Senior Contributor IV

In standard C, you should use sprintf- there are plenty of examples of how to do this.

0 Kudos

97 Views
Contributor II

Con Verse,

Thank you for your replay.  I cannot get function sprintf to work with a floating variable.  It returns a 0.000

Code:

char buffer1[5];

float value1 = 3.123;

sprintf(buffer1,"%5.3f", value1);

PRINTF("\rUsing function sprintf() to convert floating number %f to a string produces the following string: %s\n", value1, buffer1);


Tera Terminal Display:

Using function sprintf() to convert floating number 3.123000 to a string produces the following string: 0.000

Do you have any suggestions?

Thanks,

Joseph Grigaliunas

0 Kudos

97 Views
Senior Contributor IV

To start with your buffer is not long enough - what about the terminating \0?

0 Kudos

97 Views
Contributor II

Con Verse,

I'll try increasing the size of the buffer.

I don't understand what terminating \0 means.

Thanks,

Joseph Grigaliunas

0 Kudos

97 Views
Senior Contributor IV

I suggest it is time you learnt about strings in C.

for example

Strings in C 

0 Kudos