-->

Is %dn a format string?

2019-09-04 16:42发布

问题:

I recently came across this line in a code -

fprintf(logfile,"   |-IP Version        : %dn",(unsigned int)iph->version);

Is "%dn" here a format string ? If so , what does it signify ?

回答1:

It sounds a bit like someone wanted to write %d\n to terminate the line with a linefeed, but the backslash got lost somewhere. The format code, in any case, ends with the "d".



回答2:

No, %d is a format string, signifying decimal value. 'n' will be appended. Unless it's '\n', which it probably is supposed to be, which is a newline (which will also be appended of course).



回答3:

It signifies a decimal number followed by a character 'n'.