结构数组上的类型冲突错误

时间:2015-04-20 19:49:13

标签: c arrays structure

我有以下C代码:

#define total 5

typedef struct data{
    int id;
    int age;
    char name[50];
}groups;

groups people[total];
people[1] = {1, 20, "Joseph"};

但是我收到错误说

  

'人'中的'冲突类型

我不明白为什么。

1 个答案:

答案 0 :(得分:1)

其中任何一个都可以使用:

groups people[total];
people[1] = (groups) {1, 20, "Joseph"};

或:

groups people[total] = {
    [1] = {1, 20, "Joseph"}
};
相关问题