Advertisement Jump to content


This topic is now archived and is closed to further replies.


Problem in VC++NET but not in VC++6 (sprintf)

This topic is 5886 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

I just tryed working on my project with VC++NET which I had been working on with VC++6 I found that my code is not doing the same thing. I was using sprintf() like this... sprintf( buffer, TEXT("%s"), bmptxt.rollingNumberInt(100,playerunlock,4)); where rollingNumberInt() returns a char pointer (the text representation of the number I want to be in the buffer) with VC++6 this all worked So when I compiled this with VC++NET sprintf() does not put the the string of what the char pointer is into buffer, it only fills it with garbage. I took it back into VC++6 and it works fine (this was done on the same computer) whats up? has there been some change to sprintf() in .NET that I am un aware of?

Share this post

Link to post
Share on other sites
Original post by Drastick
sprintf( buffer, TEXT("%s"), bmptxt.rollingNumberInt(100,playerunlock,4));

Wide-characters ? Unicode ? Locale issues ?
Do you need wsprintf ?
Can you use std::stringstream ?
Or maybe std::wstringstream ?

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]

Share this post

Link to post
Share on other sites
wsprintf works thanks! It''s just strange that sprintf worked on 6 but not.NET I''ll test it later it see if it was caused by something in my project.

Share this post

Link to post
Share on other sites
If you want to use sprintf then get rid of the "TEXT" macro in your second parameter. In a UNICODE build that is expanded to a L and makes the string a unicode string, but sprintf expects an ANSI (multibyte) string. In an ANSI build the TEXT macro is not expanded, so sprintf will work there.

VC++6 uses ANSI by default and that is why your code worked there, but .NET (I believe) is UNICODE by default.

wsprintf on other hand expects a "wide" (i.e. unicode) string.

Check out the "TCHAR" functions in tchar.h. basically, MS provides functions such as "_tsprintf" (I think that is right) that expand to the ANSI function (e.g. sprintf) in a ANSI build and to the wide function (e.g. wsprintf) in a UNICODE build.


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!