![]() |
|
#1
|
|||
|
|||
Passing VARCHAR to functionServer: HP-UX B.11.11
I am getting different results when I print the VARCHAR array in the main function and in the called function. code: CPP / C++ / C Code:
output: Quote:
I would really appreciate if someone can tell me why I am getting different outputs. Thanx! Last edited by dsmith : 29-Apr-2004 at 11:07.
Reason: Use [c] & [/c] for syntax highlighting.
|
|
#2
|
||||
|
||||
|
Hi enomad. I moved your post to the C forum.
I am having a bit of trouble following what you are doing. Do you have a definition for the structure VARCHAR? Does it only include an arr and len entry and how are these defined? The base of the problem (I think) has to do with the fact that you define a 2d array of type VARCHAR here: CPP / C++ / C Code:
Then all of your assignments use single indexing: CPP / C++ / C Code:
This works just fine, but I am wondering why you are defining this as a 2d array? Finally, when you give the header definition for fnDummy, it is going to treat whatever you send it as a linear 1d array. Somewhere you need to tell it that this is a 2d array: CPP / C++ / C Code:
I think this should be more like to let it know what you are passing: CPP / C++ / C Code:
This is just speculation, since I don't know what VARCHAR is. It also won't compile under linux (I don't have sqlca.h where I believe VARCHAR is defined). I tried to emulate it, but I get no luck. Maybe if you could explain your declerations a bit more I could try to help more? Sorry, d |
|
#3
|
|||
|
|||
|
Snippet from Ora Doc:
------------------------------- Think of a VARCHAR as an extended C type or pre-declared struct. For example, the precompiler expands the VARCHAR declaration VARCHAR username[20]; into the following struct with array and length members: struct { unsigned short len; unsigned char arr[20]; } username; -------------------------------- I changed the code as suggested and changed VARCHAR to char, and it is working fine. But for VARCHAR its printing it differently. I am not able to figure out what I am doing wrong. changed code: Quote:
Thanks for the help d! |
|
#4
|
||||
|
||||
|
Quote:
Yeah, that makes more sense. Sorry, my compiler does not support that and it is new to me. Why don't you just define your own structure and then use it as a 1D array? CPP / C++ / C Code:
I know I am probably missing something, but since VARCHAR is a preprocessor directive anyway, this is what the compiler would see anyway isn't it? BTW - if you enclose your c-code between [c] and [/c] tags you can get C-syntax highlighting which is much easier on the eyes. Also, maybe you could explain why you are null-terminating the strings? Does your compiler not null-terminate string literals? Just curious... Cheers, d |
|
#5
|
||||
|
||||
|
I'm not following a portion of the logic you're using.
I'm making the code here a little simpler just so it can be followed easier, changing: CPP / C++ / C Code:
CPP / C++ / C Code:
strlen[sbuff] returns the value 3 because it stops at the 0x00 sbuff[xxx] = '\0'; replaces the 0x00 with 0x00. There seems to be no reason for the entire second line in this code. remember, the strxxx functions all work based off a trailing '\0' (0x00) in any string. __________________
Age is unimportant -- except in cheese |
|
#6
|
||||
|
||||
|
Quote:
That is absolutely correct. I was thrown off by this as well thinking that for some reason the compiler wasn't null-terminating the literals, but if that were the case, the str functions would just keep going until they arbitrarily hit a null. |
Recent GIDBlog
Toyota - 2008 September Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Revising Script style ?????? | pepee | MySQL / PHP Forum | 4 | 14-Apr-2004 04:59 |
| need help with passing 3 arrays into a function | tommy69 | C Programming Language | 14 | 07-Apr-2004 00:22 |
| Strange behaviour in printf (interesting) | nusstu | C Programming Language | 9 | 05-Apr-2004 13:36 |
| Another problem dealing with main() and driver function | tommy69 | C Programming Language | 4 | 20-Mar-2004 19:46 |
| Calling functions within a function | spudtheimpaler | C Programming Language | 5 | 02-Mar-2004 08:02 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The