sscanf(line,"%d %64[^\n",&seconds,message);
d [^表示 – 最多64个字符?
它应该与GNU C编译器一起使用吗?
解决方法
这意味着“最多可读取64个字符或在到达换行符时停止,以先到者为准”.它由标准指定,因此所有标准库都必须支持它.
C11 7.21.6.2
[
Matches a nonempty sequence of characters from a set of expected
characters (the scanset).
[…]
The conversion specifier includes all subsequent characters in the
format string,up to and including the matching right bracket (]).The characters between the brackets (the scanlist) compose the
scanset,unless the character after the left bracket is a circumflex
(^),in which case the scanset contains all characters that do not
appear in the scanlist between the circumflex and the right bracket.
如评论中所述,可能需要匹配]来划分扫描列表.不需要s说明符.