Thomas wrote:
Hi,
I'm currently trying to display the contents of a field which datatype
is set to TEXT, I'm trying to output this through a C program.
the line is as follows:
while((row = mysql_fetch_row(result)) != NULL)
{
printf("SID: %d\t\tSensor: %s",(row[1] ? row[1] : "NULL"));
}
I have trued %c and %s in to print the Sensor name, however %s
crashes the program and %c produces a smiley face.
The docs say that you can't rely on the string being null-terminated for
BLOB and CLOB data. Printf's %s control by itself will keep on pulling
bytes from the string parameter until it finds a null terminator, or
crashes by overflowing something. So you need to tell it to stop.
Read about mysql_field_lengths():
http://dev.mysql.com/doc/mysql/en/my...h_lengths.html
You might be able to use field precision in the printf %s conversion.
For example (I haven't tested this, but it might get you on the right
track):
while((row = mysql_fetch_row(result)) != NULL)
{
unsigned long *lengths = mysql_field_lengths();
printf("SID: %d\t\tSensor: %.*s",
(int) lengths[1],
(row[1] ? row[1] : "NULL"));
}
Regards,
Bill K.