473,480 Members | 1,833 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Pro*C Question - printing varchar

I have the following:

varchar name[21];
.... select statement puts value into name ...
.....
name.arr[name.len] = '\0';
printf ("name is %s.\n", name.arr);

Example of what I get when I do this I get:
"name is bob."

What I want is to have all the extra spaces printed out as well:
"name is bob."

Anyone know how to do this?
Nov 14 '05 #1
3 8264
On Thu, 14 Oct 2004 22:09:10 -0400, Kareem Nutt <me********@gmail.com>
wrote:
I have the following:

varchar name[21];
... select statement puts value into name ...
....
name.arr[name.len] = '\0';
printf ("name is %s.\n", name.arr);

Example of what I get when I do this I get:
"name is bob."

What I want is to have all the extra spaces printed out as well:
"name is bob."

Anyone know how to do this?


What extra spaces? If you don't like

printf("name is %s.\n", name.arr);

then you have to tell us where the extra spaces come from.
<<Remove the del for email>>
Nov 14 '05 #2
Kareem Nutt wrote:

I have the following:

varchar name[21];
... select statement puts value into name ...
....
name.arr[name.len] = '\0';


name is an array of the undefined varchar. Supply that
definition. name.arr is an error.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #3
On Thu, 14 Oct 2004 22:09:10 -0400, Kareem Nutt <me********@gmail.com>
wrote:
I have the following:

varchar name[21];
... select statement puts value into name ...
....
name.arr[name.len] = '\0';
Assuming that 'varchar' declaration actually expanded to a struct
containing some_integer_type len and char arr[21 or maybe 22], as I
have seen for another SQL-binding-C comparable to Pro*C, and
assuming the select (or fetch?) sets name.len to the actual value
length, that is without/before padding, this truncates the string at
the location of the first possible padding space.
printf ("name is %s.\n", name.arr);

Example of what I get when I do this I get:
"name is bob."

What I want is to have all the extra spaces printed out as well:
"name is bob."

Anyone know how to do this?


Do you really mean leading spaces and not trailing? If there are
leading spaces no good SQL implementation should remove them, and
neither would the code you posted.

If you meant trailing padding, to make values fixed-length:

*If* Pro*C returned padding spaces, don't clobber them as above. If it
did (allocate room for and) store a null terminator after the last
data/padding char, just use %s and name.arr. If not use %.Ns where N
is the number of actual char, or * and add that number as an argument:
printf ("%name is %.*s\n", (int) sizeof name.arr, name.arr);

If it (maybe) didn't store padding and (so) you have a variable-length
null-terminated string, as normal for C, use %Ns to right-align
(leading spaces) in a fixed-width field, or %*s with an additional int
argument; or %-Ns to left-align (trailing spaces) or %-*s similarly.

- David.Thompson1 at worldnet.att.net
Nov 14 '05 #4

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

Similar topics

2
5967
by: Chris | last post by:
I have tableA, defined as: field1 varchar2(10), field2 varchar2(10), field3 varchar2(10) I have host variables defined as: v1 pic x(10) varying v2 pic x(10) varying
1
3637
by: PRiya | last post by:
Hi, The common examples provided under "Pro*C/C++ Programming with Unicode" is #include <sqlca.h> main() { ... /* Change to STRING datatype: */ EXEC ORACLE OPTION (CHAR_MAP=STRING) ;
12
9459
by: wenmang | last post by:
Hi, I am using following Oracle Proc-C compiler: Pro*C/C++: Release 8.1.7.0.0 - Production on Thu Jun 15 15:57:32 2006 (c) Copyright 2000 Oracle Corporation. All rights reserved. I like to...
2
4641
by: chets | last post by:
Hi All, I am facing problem in executing one dynamic query in PRO *C program on linux. I want to update table mytable by data MADURAI for a column mycolumn1 where primary key is myPK.I want to...
2
32402
by: triciameza | last post by:
Here is my SP: Create PROCEDURE . ( @customerid as numeric(10), @oldemail as varchar(50), @newemail as varchar(50) ) AS BEGIN
2
2150
by: V Sudarshan | last post by:
#include <stdio.h> #include <sqlca.h> #include <sqlcpr.h> struct my_vc_ptr { unsigned short len; unsigned char arr; };
0
1898
by: mithubabu1970 | last post by:
Hello Friends.. I am working on some Pro-C program using Dynamic SQL. I am fetching a set of values and storing those in an host variable array of datatype long. The fetching into the array is...
0
1364
by: manoj339 | last post by:
I have varchar variable declared .When I print this var it shows me correct value before a C function. Inside a c function this variable value is getting truncated . The c function does not pass...
0
1501
by: rgettman | last post by:
Hello, I'm attempting to use Pro*C to create a nested table and send that data to a stored procedure as a parameter. However, I'm getting a Pro*C compiler error that I'll describe below. I'm...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7092
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...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4488
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.