【发布时间】:2016-06-06 09:44:53
【问题描述】:
我正在尝试创建 Rummy 纸牌游戏的简化版本。我需要解析卡片缩写,例如 SA 是 Spades Ace。 DT 是钻石 10 等。我知道有一种更简单的方法可以做到这一点,但这就是我的任务希望它完成的方式。
示例执行如下所示
rummy 3 S2 H9 C4...等包含所有 52 张卡片。
argv[1] 中的数字是游戏中的玩家。我应该如何将数字后开始的卡片放入数组中?
到目前为止我的代码
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
int players = *argv[1];
char deck[52];
int i, j, pid, cid;
if (players > '5' || players < '3')
{
printf("%c is not the allowed number of players, min is 3 and max is 5\n",*argv[1]);
exit(0);
}
}
【问题讨论】:
-
argv[1]是指向"3"的指针,argv[2]是指向"S2"等的指针。您应该熟悉字符串和指针。 -
您好,感谢您的评论,我知道 argv[1] 是 3,而 2 是 S2,但是在 C 中我可以将所有卡片 S2、H9 等放入一个数组中。谢谢
标签: c arrays parameter-passing command-line-arguments