结构数组上的冲突类型错误
Conflicting types error on structure array
我有以下 C 代码:
#define total 5
typedef struct data{
int id;
int age;
char name[50];
}groups;
groups people[total];
people[1] = {1, 20, "Joseph"};
但是我收到一条错误消息
'conflicting types in 'people'
我不明白为什么。
以下任一方法都有效:
groups people[total];
people[1] = (groups) {1, 20, "Joseph"};
或:
groups people[total] = {
[1] = {1, 20, "Joseph"}
};
我有以下 C 代码:
#define total 5
typedef struct data{
int id;
int age;
char name[50];
}groups;
groups people[total];
people[1] = {1, 20, "Joseph"};
但是我收到一条错误消息
'conflicting types in 'people'
我不明白为什么。
以下任一方法都有效:
groups people[total];
people[1] = (groups) {1, 20, "Joseph"};
或:
groups people[total] = {
[1] = {1, 20, "Joseph"}
};