c incompatible types in assignment, problem with pointers?

Posted by Fantastic Fourier on Stack Overflow See other posts from Stack Overflow or by Fantastic Fourier
Published on 2010-04-05T02:06:23Z Indexed on 2010/04/05 2:13 UTC
Read the original article Hit count: 314

Filed under:
|
|
|

Hi I'm working with C and I have a question about assigning pointers.

struct foo
{
   int _bar;
   char * _car[MAXINT]; // this is meant to be an array of char * so that it can hold pointers to names of cars
}

int foofunc (void * arg)
{
   int bar;
   char * car[MAXINT];

   struct foo thing = (struct foo *) arg;

   bar = arg->_bar; // this works fine
   car = arg->_car; // this gives compiler errors of incompatible types in assignment
}

car and _car have same declaration so why am I getting an error about incompatible types? My guess is that it has something to do with them being pointers (because they are pointers to arrays of char *, right?) but I don't see why that is a problem.

when i declared char * car; instead of char * car[MAXINT]; it compiles fine. but I don't see how that would be useful to me later when I need to access certain info using index, it would be very annoying to access that info later. in fact, I'm not even sure if I am going about the right way, maybe there is a better way to store a bunch of strings instead of using array of char *?

© Stack Overflow or respective owner

Related posts about c

    Related posts about pointer