Clone Wars
Clone Wars

Reputation: 11

Incompatible type of pointer

When I try to compile and run my program there is a warning in the error box

[Warning] assignment from incompatible pointer type

for this code:

char *A_ptr;

char names[numOfNames][20];

A_ptr = names;

I can't understand why it doesn't accept it.

Upvotes: 1

Views: 62

Answers (1)

klutt
klutt

Reputation: 31429

What you need is a pointer to char array of size 20. The correct declaration is:

char (*A_ptr)[20];

Don't mix it up with this:

char *A_ptr[20];

because that is an array of 20 pointers to char, which is something completely different.

Good site for these kind of stuff: https://cdecl.org/

Upvotes: 1

Related Questions