Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all, I've been trying to figure out the working of swscanf function, but did not quite undrestand the the working. I tried a code :

C++
char  tokenstring[] = "$hello 12 14...";

 if ( sscanf_s( tokenstring, "%$s", s) == 1)
     {
  cout<< "right";
}
else
  cout <<"wrong";
}


The output is "wrong", while I expected a "right".
Why is that ?
Posted

1 solution

If you're using C++ then don't use any of the functions from cstdio, there are far better ways of extracting data from formatted strings.

And if you really have to use any of them you're not providing enough parameters to the sscanf_s call. It'd be okay for sscanf but not the hoopy so called Microsoft secure version.

Have a look at the example on Here[^] - you'll see that the first call to sscanf_s has the size of the buffer the string will be written into after the string parameter.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900