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.
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.
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
Re: wsprintf() Function how to read Double Variable
Originally Posted by S_M_A
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
Wow!
Very nice to learn again something new!
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!
Re: wsprintf() Function how to read Double Variable
Frankly, I can't tell how happy I am learning you something new. Such opportunities are at the best very rare...
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.
- Brian W. Kernighan
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
Bookmarks