Advertisement
I_LIKE_COFFEE

deck

Feb 16th, 2020
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.57 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3. #define SIZE_RANK 13
  4. #define SIZE_SUIT 4
  5. #define SIZE_DECK 52
  6.  
  7. typedef struct {//структура масти карты, используется для последующего помещения каждой масти в массив
  8.     char suit_for_card[10];
  9. } suitStruct;
  10.  
  11. typedef struct {//структура карты
  12.     int rank;
  13.     char* suit_card;//массив не работал, пришлось использовать указатель
  14. } Cards;
  15.  
  16. int main() {
  17.    
  18.     suitStruct peaks = {"peaks"};
  19.     suitStruct hearts = { "hearts" };
  20.     suitStruct cross = { "cross" };
  21.     suitStruct bubi = { "bubi" };
  22.     suitStruct suit[SIZE_SUIT] = { peaks, hearts, cross, bubi };//массив содержит в себе 4 экземляра структуры
  23.     //printf("%s\n", suit[1].suit_for_card); //тест на правильный вывод
  24.  
  25.     int ranks[SIZE_RANK] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14 };//ранки от 2 до туза(14)
  26.    
  27.     Cards deck[SIZE_DECK];//колода, содержит 52 экземпляра структуры(52 карты)
  28.  
  29.  
  30.     int k = 0;//я до сих пор не понял как это работает, но коллода заполняется
  31.     for (int i = 0; i < SIZE_RANK; ++i) {
  32.         for (int j = 0; j < SIZE_SUIT; ++j) {
  33.             deck[k].rank = ranks[i];
  34.             deck[k].suit_card = suit[j].suit_for_card;
  35.             k++;
  36.         }
  37.     }
  38.  
  39.     for (int i = 0; i < 52; i++) {//проверка выхода
  40.         printf("%d", deck[i].rank);
  41.         printf(" %s\n", deck[i].suit_card);
  42.     }
  43.    
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement