Reputation: 13
I am new to C and I have no idea how to handle this array:
char *args[MAX_LINE/2 + 1];
What does this line mean exactly? Is it a pointer to an array of chars? The assignment given with this was to fill this array with multiple string tokens, but I don't understand how a char pointer can store a whole string?
Upvotes: 1
Views: 74
Reputation: 124692
char *args[MAX_LINE/2 + 1];
args
is an array of pointer to char of size MAX_LINE / 2 + 1
. Each element is a char*
, i.e., each element may be a string. You'll have to initialize them though (i.e., point them somewhere valid.) For example, to read from stdin:
args[0] = malloc(some_size);
/* read a string from standard input */
fgets(args[0], some_size, stdin);
Upvotes: 5
Reputation: 4487
That is basically an array of pointers. Each of the pointer points to a location that holds a char .
Take a look here for more details on handling it. http://www.tutorialspoint.com/cprogramming/c_array_of_pointers.htm
Upvotes: 0