M
MN
I have a question :
How to understand the mean of char** type ?
How to understand the mean of char** type ?
I have a question :
How to understand the mean of char** type ?
MN said:
char is a type - objects of that type are 1 byte in size and can contain as
their value any single member of the execution character set.
char * is a type - objects of that type are sizeof(char *) bytes in size,
and can contain as their value the address of a single char.
char ** is a type - objects of that type are sizeof(char **) bytes in size,
and can contain as their value the address of a single char *.
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
MN said:I have a question :
How to understand the mean of char** type ?
Well, it's a pointer to a pointer to a char. So if char * can
represent a string, char ** points to multiple strings. For example,
to define an array of strings one would usually:
char *arr[] = { "one", "two", "three" };
MN said:
char is a type - objects of that type are 1 byte in size and can contain as
their value any single member of the execution character set.
snip
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.
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[j]. In
this case, you would indeed return a char** (which would point to the
first allocated space).
[...]Barry Schwarz said:char is an integer type and an object of that type can contain any
value between CHAR_MIN and CHAR_MAX, inclusive (independent of whether
the value represents a member of the execution character set).
If I'm reading C99 5.2.1 correctly, the execution character set *is* the
complete set of values from CHAR_MIN to CHAR_MAX. (This is distinct
from the "basic execution character set".)
Harald van Dijk said:The execution character set may also contain multi-byte characters, so the
set of values from CHAR_MIN to CHAR_MAX cannot be the complete set. I am
not sure what is, though.
[...]Barry Schwarz said:char is an integer type and an object of that type can contain any
value between CHAR_MIN and CHAR_MAX, inclusive (independent of whether
the value represents a member of the execution character set).
If I'm reading C99 5.2.1 correctly, the execution character set *is*
the complete set of values from CHAR_MIN to CHAR_MAX. (This is
distinct from the "basic execution character set".)
Malcolm McLean said:#include <stdio.h>MN said:What I want is to use this method. Can you give a small function's
code example?
Thanks for your help
#include <stdlib.h>
#include <string.h>
char **dynarray(int width, int height)
{
char **answer;
int i, ii;
answer = malloc(height * sizeof(char *));
if(!answer)
goto error_exit;
for(i=0;i<height;i++)
answer = 0;
for(i=0;i<height;i++)
{
answer = malloc( (width + 1) * sizeof(char ));
if(!answer)
goto error_exit;
for(ii=0;ii<width;ii++)
answer[ii] = 'a';
/* a a terminal NUL */
answer[width] = 0;
}
return answer;
/* out of memory, clean up */
error_exit:
if(answer)
{
for(i=0;i<height;i++)
free(answer);
free(answer);
}
return 0;
}
I have a question :
How to understand the mean of char** type ?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.