分类: LINUX
2015-04-02 21:40:55
原文地址:sscanf 特殊分隔符(逗号) 作者:大隐隐于床
结果为:
二、解决。将sscanf内的格式化输出改为以下形式:
结果为:
三、以下为MDSN的说明:
To read strings not delimited by space characters, a set of characters in brackets ([ ]) can be substituted for the s (string) type character. The corresponding input field is read up to the first character that does not appear in the bracketed character set. If the first character in the set is a caret (^), the effect is reversed: The input field is read up to the first character that does appear in the rest of the character set.
Note that %[a-z] and %[z-a] are interpreted as equivalent to %[abcde...z]. This is a common scanf function extension, but note that the ANSI standard does not require it.
理解:
%[] 指定字符集,即加了字符规则的'%s
^ 取反
%[^,] 取非','的内容,直到遇到','