gpt4 book ai didi

c - 我怎样才能使这个结构在 C 中工作?

转载 作者:太空宇宙 更新时间:2023-11-04 08:20:44 25 4
gpt4 key购买 nike

我一直在尝试学习 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);

}

最佳答案

首先你需要定义结构:

struct card {
char type[4];
int value;
};

然后你可以声明它:

struct card card1; /*Declaration card1 of type card*/ 

关于c - 我怎样才能使这个结构在 C 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33534812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com