Re: char**
- From: Barry Schwarz <schwarzb@xxxxxxxx>
- Date: Sat, 30 Aug 2008 18:19:00 -0700
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
.
- References:
- Re: char**
- From: Richard Heathfield
- Re: char**
- From: MN
- Re: char**
- Prev by Date: Re: Help with understanding this please
- Next by Date: Re: char**
- Previous by thread: Re: char**
- Next by thread: Re: char**
- Index(es):
Relevant Pages
|