Reputation: 23
when i run the program i get
card.c:3:23: error: dereferencing pointer to incomplete type printf("%i", attacker->power);
main.c:
#include <stdio.h>
#include "card.h"
int main(){
return 0;
}
card.h:
#ifndef CARD_H_FILE
#define CARD_H_FILE
struct card_t {
char name[10];
int power, health, mana_cost;
};
int attack(struct card_t *, struct card_t *);
#endif
card.c:
int attack(struct card_t *attacker, struct card_t *defender){
printf("%i", attacker->power);
return 1;
}
Upvotes: 1
Views: 75
Reputation: 535
card.h
#ifndef CARD_H_FILE
#define CARD_H_FILE
struct card_t {
char name[10];
int power, health, mana_cost;
};
int attack(struct card_t *attacker, struct card_t *defender){
printf("%i", attacker->power);
return 1;
}
#endif
Upvotes: 0
Reputation: 70391
Unless you made omissions when posting your code, card.c
doesn't include card.h
, which means it knows nothing about struct card_t
or its members (->power
). It also doesn't inlucde stdio.h
, which means it does not know about printf()
either.
Remember that C compilers translate source (.c
) files in isolation, they do not concatenate them. This means the includes in main.c
do nothing at all for card.c
.
Upvotes: 3