I am trying to initialize struct with a function.
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <stdio.h>
#define NAME_SIZE 20
#define MANA_COST_SIZE 6
#define TYPE_SIZE 20
#define TEXT_SIZE 500
#define FLAVOR_SIZE 500
#define COLOR_SIZE 6
typedef struct card
{
char mana_cost[MANA_COST_SIZE];
char name[NAME_SIZE];
char type[TYPE_SIZE];
char text[TEXT_SIZE];
char flavor[FLAVOR_SIZE];
} card_t;
void init_card(card_t* card, char name[], char mana_cost[], char type[], char text[], char flavor[])
{
strcpy_s(card->name, NAME_SIZE, name);
strcpy_s(card->mana_cost, MANA_COST_SIZE, mana_cost);
strcpy_s(card->type, TYPE_SIZE, type);
strcpy_s(card->text, TEXT_SIZE, text);
strcpy_s(card->flavor, FLAVOR_SIZE, flavor);
}
main()
{
card_t* card;
init_card(card, "Brainstorm", "u", "Instant", "Draw 3 cards, then put two cards from your hand on top of your library", "flavor");
printf("%s\n", card->name);
}
The compiler gives the error: uninitialized local variable "card" used. Everything I have read suggests that this should be possible. I tried changing it to a pointer to a struct instead of the struct itself, but it was the same result. What am I missing?