| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 503 人关注过本帖
标题:做课设出现的问题。关于 EXE 停止工作
只看楼主 加入收藏
血肠鸭
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-10-18
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
做课设出现的问题。关于 EXE 停止工作
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册
图片附件: 游客没有浏览图片的权限,请 登录注册


#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define  radix 13

typedef  struct
{
    int  value;
    int  suit;
    char numb;
    char   huase;
    int   num;
    int  order;
    int  key[2];
    int next;
}apoker;
apoker poker[52];

typedef  int  temp[radix];
apoker  *manmakepoker(apoker unsortpoker[], int  t)
{
    int i,n;
    int suit;
    char numb;
    printf("请输入扑克牌花色和面值pS:3为红桃,4为方块,5为梅花,6为黑桃:\n");
    for (i = 0; i < 2*t; i++)//用户输入扑克牌,ASC值
    {   n=i%13;//同一个位置的扑克牌
        scanf("%d%c", &suit, &numb);
        poker[i].huase=suit;
        poker[i].value=numb;
        poker[i].num=i;
        poker[i].order=n;
    }

        printf("输入的扑克为");//(结构体赋值)
        for (i = 0; i<=2*t; i++)
        {
            n = rand() % 51;
            unsortpoker[i].huase = poker[i].huase;
            unsortpoker[i].value = poker[i].value;
            unsortpoker[i].num = poker[i].num;
            unsortpoker[i].order = poker[i].order;
            unsortpoker[i].key[0] = unsortpoker[i].huase;
            unsortpoker[i].key[1] = unsortpoker[i].order;
            printf("%c%c", poker[i].huase, poker[i].value);
        
        }

   
    return unsortpoker;
}

    apoker  *createpoker(apoker unsortpoker[], int  t)//(生成扑克)
    {
        int i, j, k, m;
        int n;
        for(i=0;i<52;i++)/*建立整副扑克*/
        {     j=i/13;/*将扑克分为四种花色*/
                k=(i+2)%13; /*控制面值的输出形式*/
               m=i%13;/*同一花色中所处的位置*/
            poker[i].order=m;
               if(j==0) poker[i].huase=3;/*花色赋值*/
               else if(j==1) poker[i].huase=4;
              else if(j==2) poker[i].huase=5;
              else poker[i].huase=6;
             if(k==0) poker[i].value=75;/*面值赋值*/
                   else if(k==1) poker[i].value=65;
                else if(k==11) poker[i].value=74;
                else if(k==12)  poker[i].value=81;
                else  poker[i].value=k;
                 poker[i].num=i;
}

        printf("随机生成的扑克:\n");

        for(i=1;i<=t;i++)/*生成t张扑克*/
        {  
                     n=rand()%51; /*随机生成52以内的数*/
                unsortpoker[i].huase=poker[n].huase;/*结构体赋值*/
                   unsortpoker[i].value=poker[n].value;
               unsortpoker[i].num=poker[n].num;
              unsortpoker[i].order=poker[n].order;
              unsortpoker[i].key[0]=unsortpoker[i].huase;  /*关键字赋值*/
               unsortpoker[i].key[1]=unsortpoker[i].order;
                k=(n+2)%13;     /*用num控制value输出形式*/
                   if(k==0||k==1||k==11||k==12)  
                 printf ("%c%c ",poker[n].huase,poker[n].value);
                  else  printf ("%c%d  ",poker[n].huase,poker[n].value);
        }

        return unsortpoker;
    }


     void  distribute(apoker r[],int i,temp head,temp tail)
    {    int  j,p;
            for(j=0;j<radix;j++)
            {head[j]=0;tail[j]=0;}  /*将个队列初始化为空队列*/
                 p=r[0].next; /*p指向链表中的第一个记录*/
                 while(p!=0)
                {
                    j=r[p].key[i];/*用记录中第i位关键字求相应队列号*/
              if(head[j]==0)
                   head[j]=p;/*将p所指向的结点加入第i个结点中*/
                   else  r[tail[j]].next=p;
                  tail[j]=p;
                  p=r[p].next;
                }
    }

         void   collect(apoker r[],temp head,temp tail)
         {
                int j;
                     int t;
                    j=0;
                    while(head[j]==0)/*找第一个非空队列*/
                           j++;
                     r[0].next=head[j];
                t=tail[j];
                    while(j<radix-1)/*寻找并串接所有非空队列*/
                    {
                          j++;
                         while((j<radix-1)&&(head[j]==0))/*找下一个非空队列*/
                           j++;
                     if(head[j]!=0)/*链接非空队列*/
                     {
                  r[t].next=head[j];
                 t=tail[j];
                     }
                    }
           r[t].next=0;/*t指向最后一个非空队列中的最后一个结点*/
         }

            void  valuepresort(apoker r[],int len)
            {
                 int  i,n,k;
                n=len;
                   temp  head,tail;
                 n=len;
              for(i=0;i<=n-1;i++)
                 r[i].next=i+1;/*构造静态链表*/
                r[n].next=0;
               for(i=0;i<=1;i++)/*从最低位关键字开始,进行分配收集*/
            {
                     distribute(r,i,head,tail);
                 collect(r,head,tail);
            }
             printf("按面值优先排序后的扑克:\n");
              for(i=r[0].next;i!=0;i=r[i].next)
              {  k=(r[i].num+2)%13; /*用num控制value输出形式*/
               if(k==0||k==1||k==11||k==12)  
            printf ("%c%c  ",r[i].huase,r[i].value);
              else  printf ("%c%d  ",r[i].huase,r[i].value);
              }
            }

              void  huasepresort(apoker r[],int len)
              {
                 int  i,n,k;
                   n=len;
                   temp  head,tail;
                    n=len;
                for(i=0;i<=n-1;i++)
                      r[i].next=i+1;   /*构造静态链表*/
                r[n].next=0;
                for(i=1;i>=0;i--)    /*从最低位关键字开始,进行分配收集*/
                {
                   distribute(r,i,head,tail);
                  collect(r,head,tail);
                }
               printf("按花色排序后的扑克:\n");
             for(i=r[0].next;i!=0;i=r[i].next)
             {  k=(r[i].num+2)%13;   /*用num控制value输出形式*/
                if(k==0||k==1||k==11||k==12)  printf ("%c%c  ",r[i].huase,r[i].value);
  
             else  printf ("%c%d  ",r[i].huase,r[i].value);
             }
              }

    void  main()
    {
        int i, N;
        char  ch;
        char  cha;
        apoker unsortpoker[100];
        printf("说明:花色顺序:%c<%c<%c<%c,    面值顺序%d<%d<...<%c<%c<%c<%c", 3, 4, 5, 6, 2, 3, 74, 81, 75, 65);
        printf("\n    a.用户选择输入扑克牌      b.随机生成扑克牌\n");
        printf("\n    A.花色优先排序        B.面值优先排序       C.退出系统\n");
        for (i = 0; i<100; i++)
        {
            printf("\n请选择生成扑克牌方式 :   \n");
            scanf("%c", &cha);
            getchar();
            switch (cha)
            {
            case 'a':{
                         int t;
                         printf("请输入扑克牌的张数:");
                         scanf("%d", &t);
                         getchar();
                         apoker unsortpoker[100];
                         manmakepoker(unsortpoker, t);
            }break;
            case 'b':printf("\n输入扑克张数:  \n"); scanf("%d", &N); createpoker(unsortpoker, N); break;
            }
            getchar();
            printf("\n输入要进行的操作:\n");
            scanf("%c", &ch);
            switch (ch)
            {
            case'A':huasepresort(unsortpoker, N); break;
            case'B':valuepresort(unsortpoker, N); break;
            case'C':break;
            default:printf("输入有误请重新输入");
                printf("\n");
            }
        }
    }
搜索更多相关主题的帖子: include 扑克牌 
2014-10-18 16:53
血肠鸭
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-10-18
收藏
得分:0 
在随机生出扑克牌然后调运函数排序的时候没有问题,但是在用户自己输入扑克牌的时候调用函数会出现****.EXE停止工作,求大神解答
2014-10-18 16:57
hackrol
Rank: 4
来 自:世界和平组织
等 级:业余侠客
帖 子:62
专家分:267
注 册:2014-9-6
收藏
得分:20 
应该是使用了没有定义的内存位置..具体没有看..自己查查!
2014-10-18 17:43
血肠鸭
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-10-18
收藏
得分:0 
回复 3 楼 hackrol
基础不是很好,能解释下么?还有这个原因是怎么出现的?
2014-10-18 17:46
血肠鸭
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2014-10-18
收藏
得分:0 
谁能告诉我QAQ
2014-10-19 11:53
快速回复:做课设出现的问题。关于 EXE 停止工作
数据加载中...
 
   



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

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