【发布时间】:2011-04-29 10:55:38
【问题描述】:
嘿,我正在尝试存储一个指针数组(指向结构),但我不断收到错误
错误:从类型“struct counter *”分配给类型“struct counter”时类型不兼容
但据我所知,代码是正确的。有什么想法吗?
struct counter
{
long long counter; /* to 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;
for (i = 0; i < ncounters; i++)
{
counters[i] = makeNewCounter(); //This is the line giving the error
}
}
【问题讨论】:
标签: c