|
40鱼币
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
- int *xipai(int a[3][18])
- {
- int (*p)[3][18]=&a;// 用于修改数组a中的值
- int i,j,m,n;
- int t;
- int s=100;
- int count=-1;// 后面用来与i比较,作为判断条件。因为是与i比较,所以初始化为-1。
- for(i=0; i<3; i++)// 为每一个a中的元素赋值
- {
- srand(s++);
- for(j=0; j<18; j++)
- {
- t = rand()%54+1;// 用中间变量t存储获得的随机数
- for(m=i; m>=0; m--)// 靠n的值来判断随机数是否与之前获得的所有> 随机数都不相同
- {
- for(n=17; n>=0; n--)
- {
- if(t==a[m][n])
- break;
- }
- if(n==-1)// 说明这一层里没有重复
- count++;// 说明处理完了一层数组
- }
- if(n==-1 && count==i)
- // 这个地方的判断有问题,单纯这一个条件,检测一维数组是否全部不相同没问题,但检测多维数组不行,因为m>0时,每次循环完,n必然为-1
- // 这里的count表示n==-1条件满足了count+1次
- {
- (*p)[i][j]=t;
- }
- else
- {
- srand(s++);
- j--;
- count=-1;// 重置count,这一步很容易忘!!!
- }
- }
- }
- for(i=0; i<3; i++)// 打印a中所有元素
- {
- for(j=0; j<18; j++)
- {
- printf("%d\n", a[i][j]);
- }
- }
- return p;
- }
- char **fapai()
- {
- char *p[3];
- int j;
- for(j=0; j<3; j++)
- {
- printf("请输入%d号玩家的名字:", j+1);
- scanf("%s", *p[j]);
- }
- return p;
- }
- void present(int a[3][18], char **p)
- {
- int i,j;
- printf("方=方块,梅=梅花,红=红桃,黑=黑桃\n");
- for(i=0; i<3; i++)// i对应玩家
- {
- printf("%s手上的牌是:", *p[i]);
- for(j=0; j<18; j++)// j对应每个玩家对应数组的位数
- {
- if(a[i][j]<11)
- {
- printf("方");
- }
- else if(a[i][j]<21)
- {
- printf("梅");
- }
- else if(a[i][j]<31)
- {
- printf("红");
- }
- else if(a[i][j]<41)
- {
- printf("黑");
- }
- printf("%d ", a[i][j]);
- }
- putchar('\n');
- }
- }
- int main()
- {
- int a[3][18]={0};// 用于存放54个不重复的、[1,54]内的整数,并把他们分成三组
- char *name[3];// 为什么 char *name[3]=fapai() 说我初始值无效
- *name=*fapai();
- char c='N';
- present(xipai(a), name);
- do
- {
- printf("重新洗牌(A) or 更换玩家(C) or 结束游戏(O)?");
- scanf("%c", &c);
- if(c=='A')
- present(xipai(a), name);
- else if(c=='C')
- *name = *fapai();
- else if(c=='O')
- {
- printf("再见!\n");
- break;
- }
- }while(c!='N');
- return 0;
- }
复制代码
- 4.c: 在函数‘xipai’中:
- 4.c:8:25: 警告:initialization of ‘int (*)[3][18]’ from incompatible pointer type ‘int (**)[18]’ [-Wincompatible-pointer-types]
- int (*p)[3][18]=&a;// 用于修改数组a中的值
- ^
- 4.c:54:16: 警告:returning ‘int (*)[3][18]’ from a function with incompatible return type ‘int *’ [-Wincompatible-pointer-types]
- return p;
- ^
- 4.c: 在函数‘fapai’中:
- 4.c:68:9: 警告:函数返回局部变量的地址 [-Wreturn-local-addr]
- return p;
- ^
- 4.c: 在函数‘main’中:
- 4.c:110:10: 警告:传递‘present’的第 1 个参数时在不兼容的指针类型间转换 [-Wincompatible-pointer-types]
- present(xipai(a), name);
- ^~~~~~~~
- 4.c:71:18: 附注:需要类型‘int (*)[18]’,但实参的类型为‘int *’
- void present(int a[3][18], char **p)
- ~~~~^~~~~~~~
- 4.c:118:12: 警告:传递‘present’的第 1 个参数时在不兼容的指针类型间转换 [-Wincompatible-pointer-types]
- present(xipai(a), name);
- ^~~~~~~~
- 4.c:71:18: 附注:需要类型‘int (*)[18]’,但实参的类型为‘int *’
- void present(int a[3][18], char **p)
- ~~~~^~~~~~~~
- 请输入1号玩家的名字:小甲鱼
- 段错误 (核心已转储)
复制代码
有人能帮我看看吗,本来有9个错误、12个警告、6个附注,现在改得还剩5个警告、2个附注,不知道怎么改了。。。
写了三个小时,现在很懵逼,对这些返回值、形参很生疏的感觉
|
最佳答案
查看完整内容
https://www.cnblogs.com/weixiaoyu/p/4371806.html
|