this is my code to try and prinnt out a deck of cards. the print function worked when used inside main without being a function but now i cant get it to work as a function probably since i dont know how to pass a struct array in c. I gave it a shot but i keep getting an assortment of errors. The structure is called card_t and it has a number variable and suit variable which is an enum type.
#include <stdio.h>
#include "shuffle.h"
void print(struct card_t[]);
int main (int argc, char *argv[])
{
card_t cards[52];
int i, type;
int j = 1;
for (i = 0; i < 52; i++)
{
if (j > 13)
{
j = 1;
}
if (i < 13)
{
type = 0;
}
if (i >= 13 && i < 26)
{
type = 1;
}
if (i >= 26 && i < 39)
{
type = 2;
}
if (i > 38)
{
type = 3;
}
cards.number = j;
cards.suit = type;
j++;
}
print(cards);
return 0;
}
void print (struct card_t cards[])
{
int i;
for (i = 0; i < 52; i++)
{
char *types[4];
types[0] = "Clubs";
types[1] = "Diamonds";
types[2] = "Hearts";
types[3] = "Spades";
if (cards.number == 1)
{
printf("Ace of %s\n", types[cards.suit]);
}
else if (cards.number == 11)
{
printf("Jack of %s\n", types[cards.suit]);
}
else if (cards.number == 12)
{
printf("Queen of %s\n", types[cards.suit]);
}
else if (cards.number == 13)
{
printf("King of %s\n", types[cards.suit]);
}
else
{
printf("%d of %s\n", cards.number, types[cards.suit]);
}
}
}
if anyone could please tell me what i can do to let the struct pass into the print function accurately i would greatly appreciate it.
NVM i actually figured it out myself. just had to remove struct from prototype and function def. thanks anyway