Re: char**



On Sat, 30 Aug 2008 05:07:54 -0700 (PDT), MN
<mazouz.nezhate@xxxxxxxxx> wrote:

On Aug 30, 2:55 pm, Richard Heathfield <r...@xxxxxxxxxxxxxxx> wrote:

snip

What is the question behind the question?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Please don't quote signatures (the previous 5 lines).


the question is :
I have a function which returns an array of chars with 2 dimensions.
The size of array is dynamically changed by malloc.
To return this array I must declare it as an extern in the header file
like this: extern char** array.
if I use extern char* array, I get error.

I assume you meant dynamically allocated instead of changed.

The return type for your function depends on the method you use to
allocate the array.

One popular method is to dynamically allocate space for a number
of pointers to char (corresponding to each row of your array). Then
allocate space for each of those pointers to hold the number of
characters in each row. This will allow you to refer to an array
element using normal subscript notation of the form array[i][j]. In
this case, you would indeed return a char** (which would point to the
first allocated space).

Another popular method is to compute the total amount of space
needed for the array and allocate it in a single block. You then
refer to the j-th element in the i-th row with syntax of the form
array[i*number_of_columns+j]. In this case, your function would
return a char* which would point to element [0][0].

--
Remove del for email
.



Relevant Pages

  • Re: Returning an array of strings in C
    ... fucntion and return char** type. ... you can't return an array from a C function. ... Now for strings it gets a bit more ... characters and you wrote a str_create to allocate a 1D array and you ...
    (comp.lang.c)
  • Re: Returning an array of strings in C
    ... characters and you wrote a str_create to allocate a 1D array and you ... There's an array of char *, and each element in that array points to ... Looks more like a float variant to me. ...
    (comp.lang.c)
  • Re: Returning an array of strings in C
    ... characters and you wrote a str_create to allocate a 1D array and you ... There's an array of char *, and each element in that array points to ... Looks more like a float variant to me. ...
    (comp.lang.c)
  • Re: Process arbitrary #lists (continued)
    ... Since no-one seems to have been aware that compiler would accept this string ... If the char array is NOT allocatable then following well-known technique ... allocate ) ...
    (comp.lang.pl1)
  • Re: NEWBIE: malloc an array????
    ... >I am having problems properly malloc'ing an array. ... The "word" structure contains a pointer to a char. ... the first of a sequence of such char which can be treated as a string ... To allocate enough space for one "array" ...
    (comp.lang.c)