如何在C卡片上打印面孔

时间:2014-03-28 04:04:14

标签: c

我试图打印一副52张牌但却不知道如何打印这些牌。我每个人都正确地打印了这套衣服。我目前的代码是:

#include <stdio.h>
#define SIZE 52

char suits[4][9]= {"Hearts","Diamonds","Clubs","Spades"};   
char faces[13][6]= {"Ace","2","3","4","5","6","7","8","9", "10","Jack",
                "Queen","King"};

int main()
{
    int i;
    char cards[SIZE];

    for(i=0; i<SIZE; i++){
        printf("Card %2d = %s %s\n", i, faces[i%13], suits[i/13]);
    }

    return 0;

}

我放了一个&#34;?&#34;我不确定的地方。我不知道到底发生了什么。我猜测套装它会取值i并除以13以确定它会选择哪4个阵列选择但是我不知道要为faces数组放入什么。

对不起,如果我的问题有问题。我还是使用stackoverflow的新手。请原谅我

1 个答案:

答案 0 :(得分:2)

像这样(check the example)?

#include <stdio.h>
#define SIZE 52

char suits[4][9]= {"Hearts","Diamonds","Clubs","Spades"};   
char faces[13][6]= {"Ace","2","3","4","5","6","7","8","9", "10","Jack",
                "Queen","King"};

int main()
{
    int i;
    char cards[SIZE];

    for(i=0; i<SIZE; i++){
        printf("Card %2d = %s %s\n", i, faces[i % 13], suits[i / 13]);
    }

    return 0;

}

如果您正在寻找这个,那么您只需要使用索引。