-
October 11th, 2012, 12:36 AM
#1
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
-
October 11th, 2012, 12:59 AM
#2
Re: wsprintf() Function how to read Double Variable
1. wsprintf() does not read, it writes (prints).
2. Correct format specifier for double in printf
Victor Nijegorodov
-
October 11th, 2012, 02:50 AM
#3
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.
-
October 11th, 2012, 03:03 AM
#4
Re: wsprintf() Function how to read Double Variable
Victor Nijegorodov
-
October 11th, 2012, 11:12 AM
#5
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...
-
October 11th, 2012, 02:25 PM
#6
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
-
October 11th, 2012, 03:22 PM
#7
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|