So I have this sample main.c file:
I'm trying to clean it up by splitting it into a header file and two source files, but when I do, I get three errors statingCode:#include <stdio.h> #include <stdlib.h> #include <time.h> void shuffle (int wDeck[][13]); void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[]); int main (void) { /* initialize suit array */ const char *suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"}; /* initialize face array */ const char *face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Size", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; /* initalize deck array */ int deck[4][13] = {0}; srand ((unsigned) time (NULL)); /* see random-number generator */ shuffle (deck); deal (deck, face, suit); return 0; } /* shuffle cards in deck */ void shuffle (int wDeck[][13]) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ /* for each of the 52 cards, choose slot of deck randomly */ for (card = 1; card <= 52; card++) { /* choose new random location until unoccupied slot found */ do { row = rand () % 4; column = rand () % 13; } while (wDeck[row][column] != 0); /* place card number in chosen slot of deck */ wDeck[row][column] = card; } } /* deal cards in deck */ void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[]) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ /* deal each of the 52 cards */ for (card = 1; card <= 52; card++) { /* loop through rows of wDeck */ for (row = 0; row <= 3; row++) { /* loop through columns of wDeck for current row */ for (column = 0; column <= 12; column++) { /* if slot contains current card, display card */ if (wDeck[row][column] == card) { printf ("%5s of %-8s%c", wFace[column], wSuit[row], card % 2 == 0 ? '\n' : '\t'); } } } } }
"error LNK2005:_deal already defined in main.obj"
"error LNK2005:_shuffle already defined in main.obj"
"fatal error LNK1169: one or more multiply defined symbols found"
I can't figure out where the mistake is. The modified files look like this:
poker.h
poker.cCode:#ifndef POKER_H #define POKER_H #include <stdio.h> #include <stdlib.h> #include <time.h> void shuffle (int wDeck[][13]); void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[]); #endif
main.c:Code:#include "poker.h" /* shuffle cards in deck */ void shuffle (int wDeck[][13]) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ /* for each of the 52 cards, choose slot of deck randomly */ for (card = 1; card <= 52; card++) { /* choose new random location until unoccupied slot found */ do { row = rand () % 4; column = rand () % 13; } while (wDeck[row][column] != 0); /* place card number in chosen slot of deck */ wDeck[row][column] = card; } } /* deal cards in deck */ void deal (const int wDeck[][13], const char *wFace[], const char *wSuit[]) { int row = 0; /* row number */ int column = 0; /*column number */ int card = 0; /* card counter */ /* deal each of the 52 cards */ for (card = 1; card <= 52; card++) { /* loop through rows of wDeck */ for (row = 0; row <= 3; row++) { /* loop through columns of wDeck for current row */ for (column = 0; column <= 12; column++) { /* if slot contains current card, display card */ if (wDeck[row][column] == card) { printf ("%5s of %-8s%c", wFace[column], wSuit[row], card % 2 == 0 ? '\n' : '\t'); } } } } }
Can anybody show me where my mistake is?Code:#include "poker.h" int main (void) { /* initialize suit array */ const char suit[4] = {"Hearts", "Diamonds", "Clubs", "Spades"}; /* initialize face array */ const char face[13] = {"Ace", "Deuce", "Three", "Four", "Five", "Size", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"}; /* initalize deck array */ int deck[4][13] = {0}; srand ((unsigned) time (NULL)); /* see random-number generator */ shuffle (deck); deal (deck, face, suit); return 0; }



LinkBack URL
About LinkBacks



