Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Triple Pointer in C 1

Status
Not open for further replies.

spidervenom

Programmer
Mar 8, 2003
19
0
0
US
int makeargv(char *s, char *delimiters, char ***argvp)

Anyone knows what ***argvp means and what it means if it is **argvp?? Is there an easy way to represent these??

thank you very much!
 
That would be a pointer to a pointer to a character pointer.

You can't go like this:

int makeargv(char* s) {
s = new char[25];
}

Well, actually you can... but since you can't assign the address of the array to s you would have to go like this:
int makeargv(char** s) {
*s = new char[25]; //You now have created an array of 25 characters and you can return the address to the first character.
}

Now if you would like to create an array of pointers to character pointers you would have to go like this:
int makeargv(char*** s) {
*s = new char*[25]; //You now have an array of 25 character pointers

//Which you could then initialize like this:
*s[0] = new char[25]; //You now have an array of 25 characters.
*s[1] = new char[25];
...
etc.
}

Greetings,
Rick
 
The previous post was a little confusing IMO.

The purists will disagree but for practical purposes,
the pointer references can be seen as the 'depth' of
the character array:
char ***argvp = char argvp[0][0][0];
char **argvp = char argvp[0][0];


HTH.

 
Both are pointers to pointers..but they are pointers that is what is requuired...you can easily infer the meaning from the context..internally they are both treated as pointers ..they point to different types of pointers..it may be stupidly confusing..but simplicity is like that
 
>> Anyone knows what ***argvp means

well hopefully the author of that function knows. We certainly don't/can't since we didn't write the function.

I scaned this thread quickly and did not see anyone pointing out that one possibility of that argument is that it represents the "address" of a variable of type "char**", in which case it is an "output" parameter that is allocated and initialized by the function and the "int" return value is the number of char*'s allocated.

-pete

 
ok
char ***argvp means the function expects a pointer to memory containing pointers to char.

Code:
// reserve mem for 10 pointers
char** argv = (char**)malloc( 10 * sizeof( char* ) );

// get the pointer to this mem block
char*** argvp = &argv;
[\code]

i asume that
int makeargv(char *s, char *delimiters, char ***argvp)
expects 's' to be a string containing tokens which are separated by 'delimeters'. 'argvp' is a pointer to memory used to hold the pointer to the created tokens (the number of which resumably returned by makeargv).

[code]
makeargv( "hi there hows it going", " ", &argv );
[\code]

This results in:
argv[0] -> "hi"
argv[1] -> "there"
...

Greetz, 
Tobi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top