Chinaunix
标题:
这个程序什么问题?
[打印本页]
作者:
green0sky
时间:
2013-09-10 09:43
标题:
这个程序什么问题?
/* Deals a random hand of cards */
#include <stdbool.h> /* C99 only */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_SUITS 4
#define NUM_RANKS 13
int main(void)
{
bool in_hand[NUM_SUITS][NUM_RANKS]={false};
int num_cards, rank, suit;
const char rank_code[]={'2','3','4','5','6','7','8','9','t','j','q','k','a'};
const char suit_code[]={'c','d','h','s'};
srand((unsigned) time(NULL));
printf("Enter number of cards in hand: ");
scanf("%d", &num_cards);
printf("Your hand:");
while (num_cards>0){
suit=rand()%NUM_SUITS;
suit=rand()%NUM_RANKS;
if(!in_hand[suit][rank]){
in_hand[suit][rank]=true;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
}
printf("\n");
return 0;
}
这是书上的一道例题,不知为什么我一运行就出错?
作者:
flyingeagle1015
时间:
2013-09-10 10:01
while (num_cards>0){
suit=rand()%NUM_SUITS;
[color=Red]suit[/color]=rand()%NUM_RANKS; // 这里应该是rank吧
if(!in_hand[suit][rank]){
in_hand[suit][rank]=true;
num_cards--;
printf(" %c%c", rank_code[rank], suit_code[suit]);
}
复制代码
作者:
lenky0401
时间:
2013-09-10 12:46
额 lz可以学一下如何做调试 这样对于一些简单问题 以后可以自己解决问题
linux下调试用gdb
http://www.gnu.org/software/gdb/
作者:
hangkong77
时间:
2013-09-23 23:55
支持3楼 自己动手丰衣足食:wink:
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2