AnsweredAssumed Answered

HC08: Why sprintf does not work correctly ?

Question asked by Eliyahu Litvak on Nov 23, 2006
Latest reply on Nov 24, 2006 by CompilerGuru
Hello,
 
 
What is wrong with that:
 
unsugned char str[70];
sprintf (str, "Offset = %0.3f\n",0.12345); 
 
But If I'm printing out str, I receive "Offset = 1.497" instead of "Offset = 0.123" !
In the past, as I remember, I already encountered such a problem and then I fixed it by casting of 0.12345 to (double)0.12345 because it states in CodeWarrior manual on sprintf page that "The argument must be a double".But now suddenly it is not working.
Double means 64 bit in my understanding so I tested in the "MMDS-MMEVS Settings" that double is indeed 64 bit rather than 32. There is a check box DOUBLE is IEEE32 and this option is not checked, so I assume double is actually 64.
If I compiling this code in an other C compler (Bloodshed DEV-C++ 4.9.9.2 ), it is working !
So how can I fix the problem ?
 
Thanks in advance to any replier.  
 
p.s. I work with HC08 3.1 build 4210
 

Message Edited by CrasyCat on 2007-04-13 11:46 AM

Outcomes