c++ - C format specifier question -


When I was working I came across a code that was written by someone else. I see a statement,

  sprintf (o_prem-> o_file_name, "% s_% s_% 04.4d_% s_% s.ASC", "OUTD", "RM", sequence_no, datestamp_book 1, timestamp_buff 1);  

In the above statement, I see % 04.4d . Is this a perfect format specifier?

variable sequence_no is constant int and does not have a decimal in it.

to <3> printf

An optional precision, after a period, an optional number string after it, if the numeric string is omitted, then it is taken as the exact zero. Returns the minimum number of digits appearing for D, I, O, U, X and X conversion , after the decimal point for the number of digits, A, A, E , F and F conversion, the maximum number of significant digits for live and live conversions, or the maximum number of characters from the string of conversions is printed.

In this situation, % 04.4d , .4 specifies that all four digits of the number should be printed. Of course, the 04 part is less than 1000 only, if the number pad with leading zero. However, in this case, in the form of the above manual page,

`0 '(zero) for all conversions except zero padding N, the changed value is padded on the left, instead of zero With zero If a precise numerical conversion is given with (D, I, O, U, I, X and X), then 0 flag is ignored .

As surely all four digits will be printed, my guess is that it is only surviving or typo or something that is composed of this syntax GCC-VAL generates compiler warnings (see Sinan Unur's example), but this is not a real error.


Comments

Popular posts from this blog

MySql variables and php -

url rewriting - How to implement the returnurl like SO in PHP? -

Which Python client library should I use for CouchdB? -