soma sekhar
soma sekhar

Reputation: 504

* in sscanf , * inside a []

I am learning about sscanf and came across a format string as below:

sscanf("%[^:]:%[^*=]%*[*=]%n",a,b,&c);

I understood the part %[^:] means scan till a ':' is encountered and assign it to a. : in format string mean match for a ':'.

But

  1. I understood that %*d mean suppress the assignment till a number is encountered. But then %[^*=], what does the * inside the [] mean?

  2. %*[*=], is it like suppress the scanning till it encounters a =. If it is so, is it equivalent to %[^=]?

Upvotes: 2

Views: 200

Answers (1)

Greg Inozemtsev
Greg Inozemtsev

Reputation: 4669

The * inside square brackets is just a literal *.

This call to sscanf will match everything up to a * or = in the second directive, and assign the result to b. Then the third directive will grab all * or = characters, and throw away the result.

Upvotes: 1

Related Questions