Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- struct card{
- int number;
- char suit[9];
- };
- typedef struct card Card;
- typedef char Suit[10];
- void start_cdeck(Card m[], Suit p[]);
- void shuffle(Card m[]);
- void outcard(Card m[]);
- void copycard(char a[], char b[], int name);
- int main() {
- Card cdeck[48];
- Suit p[4] = {"diamonds", "clubs", "hearts", "spades"};
- srand(time(NULL));
- start_cdeck(cdeck, p);
- shuffle(cdeck);
- outcard(cdeck);
- return 0;
- }
- void copycard(char a[], char b[], int name){
- for (int i = 0; i < 9; ++i) {
- a[i] = b[i];
- }
- }
- void start_cdeck(Card m[], Suit p[]){
- for (int i = 0; i < 48; ++i) {
- m[i].number = (i%12)+1;
- copycard(m[i].suit, p[i/12], 9);
- }
- }
- void shuffle(Card m[]){
- int j;
- Card temp;
- for (int i = 0; i < 48; ++i) {
- j = rand()%48;
- temp = m[i];
- m[i] = m[j];
- m[j] = temp;
- }
- }
- void outcard(Card m[]){
- for (int i = 0; i < 48; ++i) {
- printf(" %2i of ", m[i].number);
- printf("%s", m[i].suit);
- printf("\n");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement