HI there, I'm working in a logger system that send logged data to a PC. By now I'm developing the PC Software in C# with a lot of very usefull tools that allow me to change from Hexa to Float, Flota to Hexa, to String... what I want, but I know when I want to develope in Visual4Android I will not be so lucky.
So, someone knows how can I convert ASCII data string (4 bytes received by serial SPI) in to a float data? In other words the opposite of sprintf.
Mi idea is send a float data converted by sprinf in ASCII string and reseive float configuration data also in ASCII strings.
I'm using the MCF51CN128 ColdFire.
Thank you for your time!
Regards!
Pablo, from Buenos Aires.
Solved! Go to Solution.
try atof() ----- ascii to floating point numbers
#include <stdlib.h>
void main(void) {
volatile double f;
char sf[10]="1.23";
f = atof(sf); //atof
}
Hope this helps!
try atof() ----- ascii to floating point numbers
#include <stdlib.h>
void main(void) {
volatile double f;
char sf[10]="1.23";
f = atof(sf); //atof
}
Hope this helps!
Hi ZhangJennie,
I am using TWRK60F120M
codewarrior 10.5 &
mqx4.0.2
I have tried conversion of ascii string to float using atof function as you explained but for conversion of 1.23 I am getting it as 2.06 & also I am getting warning for this api as implicit declaration of function.
Please let me know how to solve this.
Thanks.
> I have tried conversion of ascii string to float using atof function
This is both a basic "Programming in C" question as well as being related to the compiler you're using. You should be asking questions there.
You should also type error messages you don't understand into Google to find everyone else who has had the same problem - and how they solved it.
Tom
Thanks to All, I will try it.
So might consider sscanf the inverse of sprintf.