Reputation: 175
I've been trying to learn structs in C and can't figure out how to make this code to work. 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);
}
Upvotes: 0
Views: 73
Reputation: 537
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*/
Upvotes: 2