标题:发牌程序,帮忙找错.谢谢
取消只看楼主
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
 问题点数:0 回复次数:3 
发牌程序,帮忙找错.谢谢
DEV C++报错:excess elements in char array initializer
(near initialization for `suit')
excess elements in char array initializer
(near initialization for `face')

#include<stdio.h>
#include<stdlib.h>
#include<time.h>

 struct CARD
{ char suit;
  char face; };

main()
{
 struct CARD card[52];
 struct CARD tempcard;
 int i, j, s=0, f=0;
 char suit[]={"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
 char face[]={"Heart","Club","Diamond","Spade"};
/*初始化牌组*/
 srand(time(NULL));
 for(i=0;i<=51;i++)
    {card[i].suit=suit[s];
     card[i].face=face[f];
     s=(s+1)%13;   
     f=(f+1)%4;}
/*洗牌*/
 for(i=0;i<=51;i++)
  {
   j=rand()%52;
   tempcard.suit=card[i].suit;
   tempcard.face=card[i].face;
   card[i].suit=card[j].suit;
   card[i].face=card[j].face;
   card[j].suit=tempcard.suit;
   card[j].face=tempcard.face;
  }
 
 for(i=0;i<=51;i++)
  printf("%s of %s\n",card[i].suit,card[i].face);
system("pause");
}

[[italic] 本帖最后由 寂寞的天空 于 2008-1-12 17:07 编辑 [/italic]]
搜索更多相关主题的帖子: char CARD 发牌 
2008-01-12 13:22
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
得分:0 
各位有会的么?没人回啊~顶起来!
2008-01-12 16:23
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
得分:0 
那个是结构里的东西,可以和数组重名,只要结构里的元素不重名就可以吧
2008-01-12 18:21
寂寞的天空
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2007-12-22
得分:0 
非常感谢楼上两位,把结构里的元素改成指针就好了.
2008-01-13 10:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-197182-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.047370 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved