|FROM ||From: "Ruben"
|SUBJECT ||Subject: [hangout] Re: two dimensional arrays passed to functions
|From owner-hangout-destenys-at-mrbrklyn.com Thu Sep 9 23:00:10 2004
Received: from www2.mrbrklyn.com (LOCALHOST [127.0.0.1])
by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with ESMTP id i8A30AWk019587
for ; Thu, 9 Sep 2004 23:00:10 -0400
Received: (from mdom-at-localhost)
by www2.mrbrklyn.com (8.12.11/8.12.3/Submit) id i8A30A8s019586
for hangout-destenys; Thu, 9 Sep 2004 23:00:10 -0400
X-Authentication-Warning: www2.mrbrklyn.com: mdom set sender to owner-hangouts-at-www2.mrbrklyn.com using -f
Received: from www2.mrbrklyn.com (www2.mrbrklyn.com [22.214.171.124])
by mrbrklyn.com (8.12.11/8.11.2/SuSE Linux 8.11.1-0.5) with SMTP id i8A309s5019581
for ; Thu, 9 Sep 2004 23:00:09 -0400
User-Agent: Pan/0.11.3 (Unix)
Subject: [hangout] Re: two dimensional arrays passed to functions
Date: Thu, 09 Sep 2004 23:00:09 -0400
List: New Yorker GNU Linux Scene
Admin: To unsubscribe send unsubscribe name-at-domian.com in the body to hangout-request-at-www2.mrbrklyn.com
X-Spam-Checker-Version: SpamAssassin 2.63 (2004-01-11) on www2.mrbrklyn.com
X-Spam-Status: No, hits=-4.9 required=4.0 tests=BAYES_00 autolearn=ham
[This is an email copy of a Usenet post to "comp.lang.c"]
On Thu, 09 Sep 2004 14:32:51 -0400, Jens.Toerring wrote:
> Ruben wrote:
>> On Thu, 09 Sep 2004 00:42:57 -0400, Ruben wrote:
>>> out of deperation because when I defined it as
>>> char * insert(char table,int cols, char values)
>>> I keep getting no data passed.
>> Actually, I originally defined this function as char * insert(char
>> table,int cols, char **values)
>> Everything I'm reading seems to say I have to define this as char *
>> insert(char table,int cols, char values)
>> but main can be defined as int main (int argv, char **argc) without any
>> This is driving me crazy because I could sware I did this on SCO
>> compilers about 8 years ago without any trouble.
> Sorry, but the URL you gave for the code doesn't work.
Someone else said that you me but it seems to be working now. Covad was
having some troubles over at tellhouse this morning
https://www.freedom-it.com/clinical.tgz is up currently
> The main question
> is: what exactly is it that you want to pass to the function? From what
> you write it looks as if in the caller you have the 'value' array
> defined as
> char values[ N ][ 256 ];
> where I don't know N but it doesn't really matter. If that is the case
> then the form
> char * insert(char table,int cols, char values)
> looks reasonable.
But it's not what I originally wanted. I'm quite sure and relooked at
old code on SCO and I used to just assign a char * to the address of the
array and then send it down as a single dimmensional array. This method
is dead appearently.
> The difference to the way argv is used is comes from
> argv not being a 2-dimensional array but a 1-dimensional array of char
> pointers. I.e. argv is defined similar to this
> char *x[ M ];
> Each of the M pointers may point to a different string.
x is a pointer to an array of chars.
> And that's not a
> 2-dimensional array - it only has room for M char pointers and nothing
But where is it allocated memory for the pointer address?
> All the strings pointed to must get their memory independently of
> that definition
Yes. I was using strcpy of string literals for that. In my main gtk
program, they are coming from editable text objects.
> If you now pass something like argv to a function what the function gets
> is a pointer to the first element of this array, i.e. a pointer to the
> first pointer - that's why argv can be written as either "char **argv"
> or "char *argv[ ]" in the call of main().
> On the other hand
> char values[ N ][ 256 ];
> has room for N strings, each 256 chars long. And it does not get
> converted to a pointer to pointer when passed to a function, since it's
> not a 1-dimensional array (what the function actually gets can be
> treated as a pointer to the first char in the first string, so you could
> define the function as
> char * insert(char table,int cols, char *values)
I thought I tried this variation and it failed.
I'll give it another run.
> But that has the obvious drawback that then the compiler has no idea
> where the strings start and you have to calculate that all by yourself,
> i.e. the start of the n-th string would then be (value + n * 256) if you
> start counting at 0.
> Regards, Jens
> \ Jens Thoms Toerring ___ Jens.Toerring-at-physik.fu-berlin.de
> \__________________________ http://www.toerring.de
NYLXS: New Yorker Free Software Users Scene
Fair Use -
because it's either fair use or useless....
NYLXS is a trademark of NYLXS, Inc