#include <stdio.h>

typedef struct{
	char suit;
	char name;
	int value;
}card;

card drawCard(card cards[], int length);
void shuffle(card cards[], int length);
void printDeck(card cards[], int length);


int main(void){

	card deck[52];
	char suits[]={'H','S','C','D'};

	int currentSuitIndex = 0;
	int currentCardSpot = 0;
	for (currentSuitIndex = 0; currentSuitIndex < 4; currentSuitIndex++){
		char currentSuit = suits[currentSuitIndex];
		int currentValue = 0;
		for (currentValue = 2; currentValue <= 14; currentValue++){
			deck[currentCardSpot].suit = currentSuit;
			deck[currentCardSpot].value = currentValue;
		
			if (currentValue >= 2 && currentValue <=9){
				deck[currentCardSpot].name = '0' + currentValue;
			}
			if (currentValue == 10){
				deck[currentCardSpot].name = 'T';
			}
			if (currentValue == 11){
				deck[currentCardSpot].name = 'J';
			}
			if (currentValue == 12){
				deck[currentCardSpot].name = 'Q';
			}
			if (currentValue == 13){
				deck[currentCardSpot].name = 'K';
			}
			if (currentValue == 14){
				deck[currentCardSpot].name = 'A';
			}
			currentCardSpot++;
		}
	}

	srand(time(NULL));

	int j = 0;
	for (j = 0; j < 5; j++){
		card selectedCard = drawCard(deck,52);
		printf("%c %c %i\n",selectedCard.name, selectedCard.suit, 
selectedCard.value);
	}

	printf("\n\n");

	printDeck(deck,52);
	printf("\n\n");

	shuffle(deck,52);
	printDeck(deck,52);

	return 0;
}

//first parameter is the set of cards to pick a random card out of
//second parameter is how many cards are in that set
card drawCard(card cards[], int length){
	int draw = rand() % length;

	return cards[draw];
}


void shuffle(card cards[], int length){
	int i = 0;
	for (i = 0; i < length; i++){
		int randomCardSpot = rand() % length;
		card temp = cards[i];
		cards[i] = cards[randomCardSpot];
		cards[randomCardSpot] = temp;
	}
}

void printDeck(card cards[], int length){
	int j = 0;
        for (j = 0; j < length; j++){
                printf("%c %c %i\n",cards[j].name, cards[j].suit,cards[j].value);
        }

}
