|
|
View previous topic :: View next topic |
Author |
Message |
Bart
Joined: 12 Jul 2005 Posts: 49
|
How to ftoa ? |
Posted: Thu Sep 15, 2005 4:23 pm |
|
|
Hello,
I need to convert a float back to an char array.
I tryed this
Code: |
fprintf(MODEM,"SPEED field in buffer : %S knots ",temp_buffer);
temp_buffer = (atof(temp_buffer) * 1.852) + '0';
temp_buffer[8] = 0;
fprintf(MODEM,"( %3.3f km/uur)\n\r",temp_buffer);
|
but this won't compile.
The Code: | atof(temp_buffer) * 1.852 | is giving something in the form
x.xxxxxxxx
xx.xxxxxxx
xxx.xxxxxx
(no more than 3 before the dot, don't need more than 3 after the dot)
Can someone correct my code ?
Thanks for the great help.
PS : Can't use other/additional variables due to RAM limitations. _________________ I like Skype (www.skype.com), my username is BplotM |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 15, 2005 5:50 pm |
|
|
Quote: | I need to convert a float back to an char array. |
The output of the following test program is: 1.23
Code: | #include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
//======================================
main(void)
{
float f;
char buffer[20];
f = 1.234;
sprintf(buffer, "%4.2f", f);
printf("%s", buffer);
while(1);
} |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|