Click here to Skip to main content
15,438,202 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Ok, so I have the data type'card' created :

//Data Type "Card"

typedef enum suit 
	Club, Spade, Heart, Diamond
} Suit;

typedef enum rank 
	Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten, Jack, Queen, King, Ace 
} Rank ;

struct card
Suit c_suit;
Rank c_rank;
} Card;

But now I need to create a deck of cards that can support any number of cards(52,104, 156, etc..). I'm not sure how to do this but I need it for my shuffle function to work.

What I have tried:

struct deck
	Card * 52;
} Deck;

But 100% not rigt
Updated 23-Nov-16 7:30am
[no name] 23-Nov-16 11:10am
Richard MacCutchan 23-Nov-16 12:19pm    
You already asked this question and are clearly struggling. May I suggest you find a somewhat simpler project to learn C on.
Member 12864130 23-Nov-16 13:07pm    
I would only it is a project due 2moro for college and everyone is struggling on it
jeron1 23-Nov-16 13:19pm    
'2moro'? really?
Richard MacCutchan 23-Nov-16 13:56pm    
Then I suggest you talk to your professor about all the aspects of this problem that he/she has not explained to you.

card Deck[52];
You then access each card via an index:
card topCard = Deck[0];
card bottomCard = Deck[51];
(once you've filled it with suitable instances, that is!)
Share this answer
Member 12864130 23-Nov-16 11:21am    
Where abouts should I put this in my code? And what do you mean by suitable instances?
OriginalGriff 23-Nov-16 11:28am     CRLF
Where do you want to use it? :laugh: When you create an array of cards, it doesn't populate it with "all different" ones - you need to set it up so it has 13 spades, 13 clubs, 13 diamonds, and 13 hearts, each of which suits has an ace, a two, a three, ... Each different card is "an instance" and is independent of all the others. If you think of a real deck, it has 52 instances of different cards - the computer model is just the same.
2 of your classmate have already asked the same question with same source code, you should team.

We do not do your HomeWork.
HomeWork is not set to test your skills at begging other people to do your work, it is set to make you think and to help your teacher to check your understanding of the courses you have taken and also the problems you have at applying them.
Any failure of you will help your teacher spot your weaknesses and set remedial actions.
So, give it a try, reread your lessons and start working. If you are stuck on a specific problem, show your code and explain this exact problem, we might help.

As programmer, your job is to create algorithms that solve specific problems and you can't rely on someone else to eternally do it for you, so there is a time where you will have to learn how to. And the sooner, the better.
When you just ask for the solution, it is like trying to learn to drive a car by having someone else training.
Creating an algorithm is basically finding the maths and make necessary adaptation to fit your actual problem.
Share this answer
Member 12864130 23-Nov-16 14:03pm    
I'm not asking you to do the program for me, I'm asking about a tiny part that I can't figure out.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900