我一直在尝试用C学习结构,但无法弄清楚如何使这段代码工作。我一直收到这个错误:
incomplete type 'struct card' struct card aCard = {"Three", "Hearts"};
^
test.c:2:8:
note: forward declaration of
'struct card'
struct card aCard = {"Three", "Hearts"};
代码:
#include<stdio.h>
struct card aCard = {"Three", "Hearts"};
int main(void){
printf("%s", aCard.suit);
}
答案 0 :(得分:2)
首先,您需要定义结构:
struct card {
char type[4];
int value;
};
然后你可以声明它:
struct card card1; /*Declaration card1 of type card*/