CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to ftoa ?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Bart



Joined: 12 Jul 2005
Posts: 49

View user's profile Send private message

How to ftoa ?
PostPosted: Thu Sep 15, 2005 4:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu Sep 15, 2005 5:50 pm     Reply with quote

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);
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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