Re: what is the meaning of "char **option"?



Omats.Z wrote:

what is meaning os "char **option meet"?
I get a function like this:
__________________________________
int getchoice(char *greet, char *choices[])
{
int chosen = 0;
int selected;
char **option; // what is this line mean?

ptr-to-ptr-to-char

a pointer is typically implemented as an address so option will contain
the
address of a location that holds the address of a location of a char.

option is of type char**
*option is of type char* (ptr-to-char)
**option is of type char

do {
printf("Choice: %s\n", greet);
option = choices;

option now points at choices

while (*option) {

*option points to the first entry of the choices array, the loop
continues so
long as the entry is not NULL

printf("%s\n", *option);
option++;

this advances to the next entry in the array

}
selected = getchar();
option = choices;
while (*option) {
if (selected == *option[0]) {
chosen = 1;
break;
}
}
if (!chosen) {
printf("Incorrect choice, select again\n");
}
} while (!chosen);
return selected;
}
__________________________________

I know "char *option" is a pointer. But what is the ** mean? If i
delete one *, this function can't be compiled!
PS: i compile it by GCC 4 on ArchLinux

a good text book should explain all this

--
Nick Keighley

.



Relevant Pages

  • Re: Best way to access this file?
    ... char userType; ... This should not compile due to lacking semicolon ... > class FixedWidthFields ...
    (comp.lang.cpp)
  • Re: freeing memory leads to sig fault
    ... If i have this kind of sudo codeish as i didn't compile it. ... to the freed memory, which may get recycled for other purposes ... char *dosomething ...
    (comp.unix.programmer)
  • LD_PRELOAD odd woes
    ... which I do not have the source code that generates useful information ... static int dyn = 0; ... fopen(const char *path, const char *mode) { ... If I compile this like this: ...
    (comp.os.linux.development.system)
  • Re: Generating code which compiles to a jmphash
    ...   I have a number of small utility functions which I would like to ... (defun move-to-int (move) ... (defun old-char+ (char) ... which given some range of inputs will compile to something similar ...
    (comp.lang.lisp)
  • [RFC] [Patch 4/4] timer_stats slimmed down: using statistics infrastucture
    ... (>80 char lines because of symbol names, ... * tstat entry structs only get allocated while collection is ... -static void reset_entries ... -static struct entry *alloc_entry ...
    (Linux-Kernel)