c - Copy a struct to a struct array -



c - Copy a struct to a struct array -

hey guys need help. i'm trying store scar struct array of scar within sowner structure, each different sowner, though i'm getting error:

incompatible types when assigning type 'scar' type 'struct scar *'

here's code :

typedef struct { char name[40]; scar cars [100]; } sowner; typedef struct { char color[40]; char brand[12]; } scar; sowner *ownerptr; scar *carptr void function(){ for(i=0; i<10 ; i++){ (ownerptr)->cars[i] = (carptr+i); // problem here <<<-- }

is there simple way create work out? thanks

you must dereference pointer on right hand side generate value of type scar.

like so:

ownerptr->cars[i] = carptr[i];

or

ownerptr->cars[i] = *(carptr + i);

but latter more complicated way write former, utilize indexing.

c arrays struct store

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -