473,386 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem: Displaying TEXT datatype with C program

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.

Can anyone pls advise?

Thanks
Thomas
Jul 20 '05 #1
1 1931
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.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Thomas | last post by:
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 =...
1
by: Thomas | last post by:
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 =...
0
by: Tom Pearson | last post by:
I create controls and validators dynamically dependent on data at runtime. I create the control then the relevant validator(s) for it assigning the Control.ID as the control to validate. These...
1
by: Rob Parker | last post by:
I posted this (with a different subjetc line) in the ms.public.access.forms newsgroup a few days ago, but haven't had a single response there. I'm hoping maybe someone here can help. Using...
1
by: Rob Parker | last post by:
I posted this with a different subject line (in two posts - I added additional info in the second) in this newsgroup a few days ago, but haven't had a single response. Hopefully, that was because...
3
by: Newbie | last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like the Datagrid is not getting the contents of the Datatable when the button ( btnAddAnotherLaborCategory) is clicked. ...
0
by: Chris Ericoli | last post by:
Hi, I am working with an 'in session' ado dataset with an asp.net application. My dataset is comprised of two tables, one of which maintains a few calculated datacolumns. For some reason these...
4
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
Hey, Well, I have a Problem. I have designed a table which has few fields which are being declared in the database of type .... char of length 10. and other fields with varchar 50 and...
5
by: dav3 | last post by:
I am by no means an ultra slick programmer and my problem solving skills.. well they leave much to be desired. That being said I have been working on the following problem for the past few days and...
0
by: JamesOo | last post by:
I have the code below, but I need to make it searchable in query table, below code only allowed seach the table which in show mdb only. (i.e. have 3 table, but only can search either one only,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.