For a command line application I need to compare the input string to a command pattern. White spaces need to be ignored.
This line should match input strings like " drop all " and " drop all":
int rc = sscanf( input, "drop all");
But what does indicate a successful match here?
Use "%n"
to record where the scanning stopped.
Add white space in the format to wherever WS in input
needs to be ignored.
int n = -1;
sscanf( input, " drop all %n", &n);
// v---- Did scanning reach the end of the format?
// | v---- Was there additional text in `input`?
if (n >= 0 && input[n] == '\0') Success();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With