473,378 Members | 1,500 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,378 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 1928
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,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.