我需要将数组的所有值初始化为0。newCount-> numbers [1] = {0}给出错误“期望表达式”。我将如何处理?
typedef struct count *Count;
struct count{
int numbers[101];
int totalCalls;
int totalCallsEach[101];
};
Count create_Count(void){
Count newCount = malloc(sizeof(struct count));
newCount->numbers[101] = {0};
newCount->totalCalls = 0;
return newCount;
}
最佳答案
使用memset
将数组的值设置为0
。
memset(newCount->numbers, 0, sizeof(newCount->numbers));
memset(newCount->totalCallsEach, 0, sizeof(newCount->totalCallsEach));
聚苯乙烯
typedef struct count *Count;
typedef
不好。采用:typedef struct count Count;
要么
typedef struct count *CountPtr;