I was reading this page
http://dev.mysql.com/doc/refman/5.0/en/mysql-fetch-row.html
there is one line
printf("[%.*s] ", (int) lengths[i],
row[i] ? row[i] : "NULL");
from code
MYSQL_ROW row;
unsigned int num_fields;
unsigned int i;
num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
unsigned long *lengths;
lengths = mysql_fetch_lengths(result);
for(i = 0; i < num_fields; i++)
{
printf("[%.*s] ", (int) lengths[i],
row[i] ? row[i] : "NULL");
}
printf("\n");
}
what does [%.*s] mean in that code ?
[%.*s]is aprintfformat string meaning:[and](and trailing space) are transferred as-is.Normally, you would see something like
.7swhich means a 7-character string. The use of*for the length means to take it from the argument given.So what that entire line does is to print a string , the length of which is found in
lengths[i], and the value of which isrow[i](unlessrow[i]is NULL, in which case it uses the literal string"NULL").