hey, i'm trying store array of pointers (to structs) continually receiving error
error: incompatible types when assigning type 'struct counter' type 'struct counter *'
but far know, code correct. ideas?
struct counter { long long counter; /* store counter */ }; static struct counter* counters = null; struct counter* makenewcounter(void) { struct counter* newcounter = malloc(sizeof(struct counter)); newcounter->counter = 0; return newcounter; } static void setupcounters(void) { counters = malloc(ncounters * sizeof(struct counter*)); int i; (i = 0; < ncounters; i++) { counters[i] = makenewcounter(); //this line giving error } }
counters[i]
of type struct counter
; makenewcounter()
returns value of type struct counter *
, compiler rightfully complains.
try
counters[i] = *makenewcounter();
or
struct counter **counters;
Comments
Post a Comment