Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

%64[^ specificator in C

Tags:

c

sscanf(line, "%d %64[^\n", &seconds, message);

does %64[^ mean - up to 64 characters? Should it work with GNU C Compiler?

like image 475
Nusrat Nuriyev Avatar asked May 25 '12 07:05

Nusrat Nuriyev


1 Answers

It means "read at most 64 characters or stop when reaching a newline, whichever comes first". It's specified by the standard so all standard libraries have to support it.

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.

As noted in the comments, a matching ] is probably required to delimit the scanlist. An s specifier is not required.

like image 92
cnicutar Avatar answered Oct 05 '22 17:10

cnicutar