Marco <98*****@sohu.com> wrote:
I saw the following line in a C source. what's the asterisk * mean?
fprintf(conn_out, "%.*s\r\n", (int)(strlen(buf + 1) - 1), buf + 1);
This really should be in your C textbook. (If you haven't got one, I
recommend, obviously, K&R 2.) It's also in the last public draft of the
C99 Standard: <http://www.open-std.org/jtc1/sc22/wg14/www/docs/n869/>.
Basically, if either the field width or the precision of a conversion
specifier is an asterisk, there's another argument (an int) that
provides the value of that part of the specifier.
In this case, the precision of your string argument, which is the
maximum number of chars to write, is given by the (int)(strlen(buf+1)-1)
argument. The result is that the whole string starting at buf+1 is
written, except for the last character.
Richard