开发者

Using sscanf to extract some values

开发者 https://www.devze.com 2022-12-23 01:48 出处:网络
gcc 4.4.2 I have the following code: char channels[] = \"NumberOfChannel = [2]\"; sscanf(channels, \"%*[^=]= %d\", &chan);

gcc 4.4.2

I have the following code:

char channels[] = "NumberOfChannel = [2]";

sscanf(channels, "%*[^=]= %d", &chan);

I am wondering what this means. As far as I can tell.开发者_如何转开发 It is ignoring the equals sign.

'^ ignore the character ='

Would that be correct?

Many thanks,


%*[^=]

The [^=] means match a string which contains no =. This is a POSIX extension. The * means discard the matched result.

(BTW, to correctly get chan you need sscanf(channels, "%*[^=]= [%d]", &chan);.)

0

精彩评论

暂无评论...
验证码 换一张
取 消