Advertisement
Guest User

Untitled

a guest
Nov 27th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<time.h>
  4.  
  5. struct card {
  6. const char *face;
  7. const char *suit; };
  8.  
  9. typedef struct card Card;
  10.  
  11. void fillDeck (Card * const, const char *[],
  12. const char *[]); void shuffle (Card * const); void deal (const Card * const, const, const, const, const);
  13.  
  14. int main() {
  15. Card deck [52];
  16. const char *face[] = { "Ace", "Deuce", "Three", "Four", "Five",
  17. "Six", "Seven", "Eight", "Nine",
  18. "Ten", "Jack", "Queen", "King"};
  19. const char *suit[] = { "Hearts", "Diamonds", "Clubs", "Spades"};
  20. const aDeck[13], bDeck[13], cDeck[13], dDeck[13];
  21.  
  22. srand (time(NULL));
  23.  
  24. fillDeck (deck, face, suit);
  25. shuffle (deck);
  26. deal (deck, aDeck, bDeck, cDeck, dDeck);
  27. openCard (aDeck, bDeck, cDeck, dDeck);
  28. return 0; }
  29.  
  30. void fillDeck (Card * const wDeck, const char * wFace[], const char * wSuit[]) {
  31. int i;
  32.  
  33. for (i=0; i<=51; i++)
  34. {
  35. wDeck[i].face = wFace[i%13];
  36. wDeck[i].suit = wSuit[i/13];
  37. } }
  38.  
  39. void shuffle (Card * const wDeck) {
  40. int i, j;
  41. Card temp;
  42.  
  43. for (i=0; i<=51; i++)
  44. {
  45. j = rand() %52;
  46. temp = wDeck [i];
  47. wDeck[i] = wDeck[j];
  48. wDeck[j] = temp;
  49. } }
  50.  
  51. void deal (const Card * const wDeck, const aDeck , const bDeck , const cDeck , const dDeck) {
  52. int i, a, b, c, d;
  53.  
  54. for (i=0; i<=51; i++)
  55. for (a=0; a<=12; a++){
  56. aDeck [a].face = wDeck[i%4].face;
  57. aDeck [a].suit = wDeck[i/4].suit;
  58. }
  59. for (b=0; b<=12; b++){
  60. bDeck [b].face = wDeck[i%4+1].face;
  61. bDeck [b].suit = wDeck[i%4+1].suit;
  62. }
  63. for (c=0; c<=12; c++){
  64. cDeck [c].face = wDeck[i%4+2].face;
  65. cDeck [c].suit = wDeck[i%4+2].suit;
  66. }
  67. for (d=0; d<=12; d++){
  68. dDeck [d].face = wDeck[1%4+3].face;
  69. dDeck [d].suit = wDeck[1%4+3].suit;
  70. } }
  71.  
  72. void openCard (const aDeck, bDeck, cDeck, dDeck) {
  73. int i;
  74. for (i=0; i<=13; i++)
  75. printf ("Player one:n"
  76. "%5s of %-8sn", aDeck[i].face, aDeck[i].suit)
  77.  
  78. for (i=0; i<=13; i++)
  79. printf ("Player two:n"
  80. "%5s of %-8sn", bDeck[i].face, bDeck[i].suit)
  81.  
  82. for (i=0; i<=13; i++)
  83. printf ("Player three:n"
  84. "%5s of %-8sn", cDeck[i].face, cDeck[i].suit)
  85.  
  86. for (i=0; i<=13; i++)
  87. printf ("Player four:n"
  88. "%5s of %-8sn", dDeck[i].face, dDeck[i].suit) }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement