wsprintf() Function how to read Double Variable
I have one problem with wsprintf Function
if I write this code :
Code:
int I =500 ;int S ;
WCHAR sBuffer[10];
S= wsprintf(sBuffer,TEXT(" I value : %i "), I); // Here is the problem
Now My Problem is , If The Varibale I is double Not integer , How can I let wsprintf read the double variable
Simply if I have I = 122.45566777776 as Example , how can I print by using wsprinf function.
I think I have to convert I number (122.45566777776) to WCHAR varaible then print directly
But this will be very long way if I have to convert each int variable to wchar variable.
Kindly advise , and provide code examples if possible.
Thanks & Regards
Re: wsprintf() Function how to read Double Variable
1. wsprintf() does not read, it writes (prints).
2. Correct format specifier for double in printf
Re: wsprintf() Function how to read Double Variable
wsprintf is an old remnant from the 16-bit era that, in order to have low footprint and be faster than sprintf, not supports floating point numbers. It also has a buffer size limit of 1024 bytes. See http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
You should use one of the other formatting functions available like sprintf (or variants of it) or std::stringstream.
Re: wsprintf() Function how to read Double Variable
Quote:
Originally Posted by
S_M_A
Wow!
Very nice to learn again something new! :thumb:
Frankly, I NEVER used wsprintf(). Ever. Since the most of my projects are MFC ones I also very rarely use sprintf.
So, sorry for the incorrect reply! :blush:
Re: wsprintf() Function how to read Double Variable
Frankly, I can't tell how happy I am learning you something new. :D Such opportunities are at the best very rare...
Re: wsprintf() Function how to read Double Variable
Thanks so much S_M_A and VictorN for valuable answers,
and Here is code example :
Code:
int p,z;
double x; x = 23.4454 // as example
CHAR AA[20];
TCHAR sBuffer[80];
z= sprintf_s(AA, " %f",x); // Note sprintfl not working with win7_64 MSDN Recommend sprintf_s
p=wsprintf(sBuffer,TEXT("%S"),AA); // S should be Capital
x=_wtof(sBuffer); // Now again we con convert TCHAR to Double by using _wtof function
Re: wsprintf() Function how to read Double Variable
>> // S should be Capital
You should use "%hs". I recommend that you forget that %S even exists - use %s, %ls, or %hs.
>> // Now again we convert TCHAR to Double by using _wtof function
You should use _ttof().
gg