# 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 on other sites
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 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 on other sites
Yes! That's how goes! Many great thanks for help!

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628305
• Total Posts
2981939

• 9
• 11
• 11
• 11
• 10