For the assignment I am working on, I am required to use functions to manipulate data in an array of strings. So really, an array of arrays of chars. I define the array like so:
char strings[5][100];
So there are presumably 500 contiguous chars in memory. The function I have defined looks like this:
void foo(char *labels[100]);
I think I might have some syntax issues here, but what I think this is doing is saying, “I’m a function that expects a pointer to an array of 100 chars.” So labels* would point to the first array of chars, and (labels + 1)* would point to the second, and so on. I am calling the function like this:
foo(&strings[0]);
What I think this is doing is grabbing the address of the first array of chars in strings. The error message I’m getting tells me the function expects char ** but the argument is char (*)[100]. This is confusing to me as nowhere did I specify that there be a pointer to a pointer of a char.
Any help is greatly appreciated, or if you could pointer me in the right direction :)
stringsis a two dimensional array. So it decays tochar(*)[100]when passed to a function. Instead you can have the prototype like –