[英]How can I make this struct work in C?
I've been trying to learn structs in C and can't figure out how to make this code to work. 我一直在尝试学习C语言中的结构,但无法弄清楚如何使此代码正常工作。 I keep getting this error: 我不断收到此错误:
incomplete type 'struct card' struct card aCard = {"Three", "Hearts"};
^
test.c:2:8:
note: forward declaration of
'struct card'
struct card aCard = {"Three", "Hearts"};
The code: 编码:
#include<stdio.h>
struct card aCard = {"Three", "Hearts"};
int main(void){
printf("%s", aCard.suit);
}
First you need to define the structure: 首先,您需要定义结构:
struct card {
char type[4];
int value;
};
And then you can declare it : 然后可以声明它:
struct card card1; /*Declaration card1 of type card*/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.