Advertisement Jump to content
Sign in to follow this  
Dookie

Easy 'StringCbPrintf' question (hopefully)

This topic is 5128 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, it's me again! First of all, here's my code to reference:
	int const arraysize = 30;
	float TempTest;
	TCHAR pszDest[arraysize]; 
	size_t cbDest = arraysize * sizeof(TCHAR);

	TempTest = 169474/495;

	StringCbPrintf(pszDest, cbDest, "%d", TempTest);
What I'm trying to do is fill the variable 'pszDest' with a string representation of the floating point value in 'TempTest'. But all the above returns is zero! What am I doing wrong? BTW, for those of you that haven't played around with 'StringCbPrintf' it's exactly like using 'wsprintf' except without accidently aggravating those good old Windows security issues. I also get a ZERO in pszDest if I use 'wsprintf' in the place of 'StringCbPrintf'. Thanks in advance for the help! :)

Share this post


Link to post
Share on other sites
Advertisement
%d is the format code for a signed integer. You probably want to use %f, %g, %e or some other code meant for displaying floating point data.

I'm not sure exactly why it outputs 0, since it should be 'trash', but I believe the above will fix your problem.

Share this post


Link to post
Share on other sites
Thanks for the reply, Extrarius!

Yep, that %f did the trick... Pretty weird, because I tried that earlier today and it put the letter 'f' into pszDest. But now it works!

Thanks again! :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!