Skip to content

Instantly share code, notes, and snippets.

@APIUM
Created July 26, 2018 13:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save APIUM/5eef09edcd34dac090e2ca63b2b8e39c to your computer and use it in GitHub Desktop.
Save APIUM/5eef09edcd34dac090e2ca63b2b8e39c to your computer and use it in GitHub Desktop.
What
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct card {
char suit[10];
int value;
} card;
// hearts, clubs, spades, diamonds
void generateCards(card *deck[52]) {
strcpy( deck[0].suit, "hearts" );
deck[0].value = 1;
for (int i=0; i<4; i++) {
for (int j=0; j<13; j++) {
deck[(i*13)+j]->value = j+1;
switch(i) {
case 0:
strcpy( deck[(i*13)+j]->suit, "hearts" );
break;
case 1:
strcpy( deck[(i*13)+j]->suit, "clubs" );
break;
case 2:
strcpy( deck[(i*13)+j]->suit, "spades" );
break;
case 3:
strcpy( deck[(i*13)+j]->suit, "diamonds" );
break;
}
}
}
}
void printDeck(card *deck[52], int n) {
for (int i=0; i<(n/52); i++) {
printf("%d of %d", deck[(i-1)]->value, deck[(i-1)]->suit);
}
}
int main(void) {
card deck[52];
generateCards(&deck);
printf("Deck printer.\n");
printf("Please enter number n, program will print every nth card of the deck.");
int input = 0;
scanf("%d", &input);
printDeck(&deck, input);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment