鱼C论坛

 找回密码
 立即注册
查看: 4610|回复: 2

出现了Segmentation fault问题

[复制链接]
发表于 2012-12-2 12:35:15 | 显示全部楼层 |阅读模式
1鱼币
#include<stdio.h>#include <stdlib.h> #include <time.h> void guess(int *p);void xh(int h);main(){int x,*y;x=0;y=&x;guess(y);switch(x){case 7:case 11:printf("Win!");break;case 2:case 3:case 12:printf("Lose!");break;case 4:case 5:case 6:case 8:case 9:case 10:xh(x);break;}}//掷骰子void guess(int *p){srand(time(NULL));printf("正在掷骰子ing.....\n");*p=rand()%12+2;printf("两个骰子之和为%d点\n",*p);}//骰子之和为 4 5 6 8 9 10时候 要循环抛void xh(int h){int j=0,i=1,*g;g=j;while(j!=h&&i<=7){guess(g);if(j==h){printf("Win!");break;}else{printf("重新掷,这是第%d次\n",i);i++;}}if(j!=h&&i==8)printf("Lose!\n");}

Output:
1
Segmentation fault

出现了Segmentation fault问题··
怎么解决···



小甲鱼最新课程 -> https://ilovefishc.com
发表于 2012-12-2 12:35:16 | 显示全部楼层
  1. #include<stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4. void guess(int *p);
  5. void xh(int h);
  6. main(){
  7.         int x,*y;
  8.         x=0;
  9.         y=&x;
  10.         guess(y);
  11.         switch(x){
  12.         case 7:case 11:
  13.                 printf("Win!");
  14.                 break;
  15.         case 2:case 3:case 12:
  16.                 printf("Lose!");break;
  17.         case 4:case 5:case 6:case 8:case 9:case 10:
  18.                 xh(x);
  19.                 break;
  20.         }
  21. }
  22. //掷骰子
  23. void guess(int *p){
  24.         srand(time(NULL));
  25.         printf("正在掷骰子ing.....\n");
  26.         *p=rand()%12+2;
  27.         printf("两个骰子之和为%d点\n",*p);
  28. }
  29. //骰子之和为 4 5 6 8 9 10时候 要循环抛
  30. void xh(int h){
  31.         int j=0,i=1,*g;
  32.         //g=j;
  33.         g = &j;
  34.         while(j!=h&&i<=7){
  35.                 guess(g);
  36.                 if(j==h){
  37.                         printf("Win!");
  38.                         break;
  39.                 }else{
  40.                         printf("重新掷,这是第%d次\n",i);
  41.                         i++;
  42.                 }
  43.         }
  44.         if(j!=h&&i==8)printf("Lose!\n");
  45. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2012-12-3 13:10:37 | 显示全部楼层
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-16 15:33

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表