You got the operator precedence wrong: *vals[i]
evaluates as *(vals[i])
, not as (*vals)[i]
. See http://en.wikipedia.org/wiki/Operators_in_C_and_C%2B%2B#Operator_precedence for details.
The fix is to change *vals[i]
to (*vals)[i]
.
Also, the allocation *vals[i] = (char*) calloc( sizeof( char* ), stringmaxlen );
is wrong. It allocates way too much memory because it allocates space for stringmaxlen
pointers, but you need only stringmaxlen
characters.