c - How to successfully print out deck of 52 cards and 5 hands of non-repeating cards? -
i want fill , print out deck of 52 cards, , print out 5 hands of 5 non-repeating cards successfully, doesn't work. how able fix that?
code:
#include <stdio.h> #include <stdlib.h> #include <time.h> /* handy typedefs */ typedef unsigned char card; typedef unsigned char pairs; /* arrays names of things */ static char *suits[4] = {"hearts","diamonds","clubs","spades"}; static char *values[13]= {"ace","two","three","four","five","six",/ "seven","eight","nine","ten","jack","queen","king"}; static char *colour[]= {"black","red"}; int main() { card deck[52][24],*deckp; int s, c, a; (s = 0; s < 4; s++) { for(c = 0; c < 13; c++) { sprintf(deck[(s * c) + c], "%s of %s", values[c], suits[s]); } } for(a = 0; < 52; a++) { printf("%s\n", deck[a]); } int hand,cd,winner; int irand; int i; int irand; srand(time(null)); /* seed random number generator */ for(cd=0;cd<5;cd++) { for(hand=0;hand<5;hand++) { /* deal hands here */ } } (hand=0;hand<5;hand++) { printf("hand %i:\n",hand+1 ); ( = 0; < 5; i++) { irand = (rand() % 52); printf(" %s \n ", deck[irand]); } } /* determine winner , print */ return 0; } void filldeck(card deck[52]) { return; } void shuffle(card deck[52]) { int i,rnd; card c; for(i=0;i<52;i++) { /* generate random number between 0 & 51 */ rnd=rand() * 52.0 / rand_max; c = deck[i]; deck[i] = deck[rnd]; deck[rnd] = c; } }
replace deck[(s * c) + c]
deck[s * 13 + c]
.
Comments
Post a Comment