Jump to content
  • Advertisement
Sign in to follow this  

Is sscanf_s broken?

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

Along swapping to new Express Edition of MSVC I getting used to new "secure C" functionality. Everything else seems to function more or less the same as before, but I faced a small problem with "sscanf_s". With sscanf; sscanf (oneline, "VAR %d %d %s %s %d\n", &pos1x, &pos1y, &name, &string, &linkto); ... everything worked fine and smooth. Replacing it with "sscanf_s", however, results an instant crash. So is sscanf_s "broken" or does it function in some completely different manner I'm not familiar with? Thanks again! :D

Share this post


Link to post
Share on other sites
Advertisement
Shouldn't &name, &string be name, string? I'm not sure, I avoid sscanf[_s]() like the plague, and you should too if you can help it.

Share this post


Link to post
Share on other sites
i once had the same problem as you, but a look at the msdn helped me:

The sscanf_s function reads data from buffer into the location given by each argument. The arguments after the format string specify pointers to variables with a type that corresponds to a type specifier in format. Unlike the less secure version sscanf_s, a buffer size parameter sizeOfBuffer is required when using the type field characters c, C, s, S and [. This parameter must be supplied as an additional parameter after each buffer which requires it.

thats means:

char *buffer = new char[80];

sscanf_s(anysource, "%s", buffer, 80);




you don't need to do a sizeof(char) * 80 because one char has one byte and that wouldn't change much, if you multiply it with 80, wouldn't it? :)

i hope i could help :D

*edit* oops, ofcourse you need to use sscanf_s with the above parameters, corrected it ^^

[Edited by - SiS-Shadowman on May 20, 2006 8:24:48 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!