0

In my program I declared the following:

char S[1000][200]; 

an array of strings, and have a function like this:

char** buscar_str(char **S){.......}

But when I try this:

buscar_str(S);

I get the mentioned error note: expected ‘char **’ but argument is of type ‘char (*)[200].

How can I solve this issue?

NAND
  • 663
  • 8
  • 22
Dorknob78
  • 43
  • 4
  • 1
    [C11 Standard - 6.3.2.1 Other Operands - Lvalues, arrays, and function designators(p3)](http://port70.net/~nsz/c/c11/n1570.html#6.3.2.1p3) Only the first level of indirection is converted to a pointer. E.g. `char S[1000][200];` on access is converted to `char (*S)]200];` (a *pointer-to-array* of `char[200]`). `char **` is a *pointer-to-pointer-to* `char`. – David C. Rankin May 27 '20 at 01:50
  • 3
    Does this answer your question? [Why can't we use double pointer to represent two dimensional arrays?](https://stackoverflow.com/questions/4470950/why-cant-we-use-double-pointer-to-represent-two-dimensional-arrays) – NAND May 27 '20 at 11:15

1 Answers1

3

There is not an immediate way to reconcile this. Given char S[1000][200], S is 200,000 bytes of memory organized into 1000 arrays of 200 char. But the routine buscar_str declared with char **buscar_str(char **S) wants a pointer to one or more pointers to char. You do not have any pointers to char in S. You can give one, such as &S[0][0], but you do not have more than one.

To resolve this, you must either allocate space for an array of pointers to char and fill that array with such pointers (perhaps to those various char in S) or you must change buscar_str to accept a pointer to an array, such as char (*S)[200], or, less likely, a pointer to an array of arrays, such as char (*S)[1000][200]). For the former, you would pass S to buscar_str. For the latter, you would pass &S to buscar_str.

We cannot tell you which of these options is suitable for your situation without further information.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312