-1

Possible Duplicate:
what does ā€œ%.*sā€ mean in printf in c

I have found the following line :

asprintf(&c, "%s%.*s", *msg_in, size * rxed, buffer)

And I want to know the meaning of %.*s

Community
  • 1
  • 1
developer
  • 4,744
  • 7
  • 40
  • 55

2 Answers2

4

The %.*s format means "print a string using a field width of n characters, where n is read from the next argument".

So here, it prints buffer with a width of size * rxed characters. (padding with spaces if necessary)

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
2

I would highly recommend reading the manual...

.* in a format string means:

the precision is not specified in the format string, but as an additional integer value argument preceding the argument that has to be formatted.

Details can be seen here.

So you didn't give any details, but if the result of: size * rxed was 5, then you could do this:

asprintf(&c, "%s%.*s", *msg_in, size * rxed, buffer)

or

asprintf(&c, "%s%5s", *msg_in, buffer)

to the same effect.

Mike
  • 47,263
  • 29
  • 113
  • 177