Sign in to follow this  
necrophilissimo

Is sscanf_s broken?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this