Jump to content
  • Advertisement

Archived

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

Drastick

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

This topic is 5793 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
Advertisement
quote:
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.


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

P.P.S.
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.

Blake

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!