| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 459 人关注过本帖
标题:为什麽指针没有传递过去,请大虾指点
只看楼主 加入收藏
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
结帖率:94.44%
收藏
已结贴  问题点数:20 回复次数:5 
为什麽指针没有传递过去,请大虾指点
//  为什麽question1,answer没有传递过去,请大虾指点

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include<windows.h>
#include <string.h>
#define michael  while(getchar()!='\n')  //剔除多余输入
#define jackson  printf("请输入答案")
char (*answer)[81],(*question1)[81],  (*compar)[81];;
static char *question[]={"what the name of mine","who i like the most","when i"
   "first do the\" 1+1\",it is"," yourself question"};
void input1(char *quetion[81]);     //预设问题
int input2();         //问题个数
int judge1(int hh,int ss);      //判断1,2,3,4
void choice(int funny,char (*question1)[81],char (*answer)[81]);  
void output(int a,char (*question1)[81],char (*answer)[81]);

int main(void)
{
  int x=0,a,num[3];
  char ch;

printf("这是一个类似qq密码的程序.\n");
a=input2();
if(a=2)  compar=question1=answer=(char (*)[81])malloc(2*81*sizeof(char));
else   compar=question1=answer=(char (*)[81])malloc(3*81*sizeof(char));
input1(question);
srand((unsigned int)time(0));
printf("请选择第一个问题:(输入1,2,3,4):");
num[0]=judge1(0,0);
choice(num[0],question1,answer);
num[1]=judge1(num[0],0);
choice(num[1],question1,answer);
if(a==3)
  {num[2]=judge1(num[0],num[1]);
  choice(num[2],question1,answer); }
while(printf("你已经记住问题啦吗?(y或n):")&&getchar()!='y')
{michael;
Sleep(5000);
}
system("cls");
printf("警告:请不要有任何 动作\n");
for(int b=0;b<50;b++)
 {
 Sleep(1000);
 if(b!=0&&!(b%10))
  printf("还有%d秒",(50-b));
 if(getchar())
  {x=1;
  break;}
 }
 if(x==0)
  {printf("你好心耐心哦,一般很少有人这麽有耐心,呵呵");
  getchar();
  printf("天才即耐心."); }
 if(x==1)
  printf("哦,这麽急");
 output(a,question1,answer);

return 0;
}


  void input1(char *question[81])
  {
      printf("预设问题是:\n");
    for(int a=0;a<4;a++)
     printf("%d.%s\n",a+1,question[a]);
  }
  int input2()
  {void input1(char *quetion[81]);   
      int a;
   printf("你准备输入几个问题(2或3):");
   while(!scanf("%d",&a)||(a!=2&&a!=3))
    {michael;
     printf("请输入2或3,呵呵:");}
   
  return a;
  }
  
  
  int judge1(int hh,int ss)           //判断输入1234的正确性
{
  int a;
  static int b=1;
  
  
  if(b==1)
   while(!scanf("%d",&a)||a<1||a>4)
   {  michael;
        printf("请输入数字1,2,3,4::");}        
  
  else if(b==2&&printf("请选择第二个问题:"))
    while(!scanf("%d",&a)||a==hh||a<1||a>4)
       {michael;
       printf("请输入其他数字 :");}
 else  if(printf("请选择第三个问题:"))
 while((!scanf("%d",&a)||a==hh||a==ss||a<1||a>4))
      {michael;
      printf("请输入其他数字");}
 michael;
b++;
 return a;  
}
void choice(int funny,char (*question1)[81],char (*answer)[81])           //选择答案。
{
   static int a=0;
    printf("%s \n",question[funny-1]);
      if(funny==4)
       {printf("输入你的问题:");
        gets(question1[a]);}
     jackson;
     gets(answer[a]);
     a++;
}

void output(int a,char (*question1)[81],char (*answer)[81])
{
 int b[3],f[3],c,e;
 
  for(c=1,e=0;c<=a;c++)
 {   
  b[0]=rand()%a;
    printf("第1个 问题:%s",question1[b[0]]);
    jackson;
    gets(compar[b[0]]);
   while((b[1]=rand()%a)==b[0]);
   printf("第2个 问题:%s",question1[b[1]]);
   jackson;
   gets(compar[b[1]]);
   if(a=3)
     {
     while((b[2]=rand()%a)==b[0]||b[2]==b[1]);
     printf("第三个问题:%s",question1[b[2]]);
     jackson;
     gets(compar[b[2]]);
     }
  for(int d=0;d<a;d++)
   {
   if(strcmp(compar[b[d]],answer[b[d]]))
    f[e]=d; e++;
   }
   if(e==0) break;
   else
     printf("请重新输入 ,你还有%d次机会\n" ,a-c);
 }
}
 
  
 
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 指针 
2010-04-18 16:55
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
收藏
得分:0 

[b] 你要有勇气去听从你直觉和心灵的指示,所有其他的事情都是次要的。
2010-04-18 18:41
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:7 
扫了眼
void input1(char *question[81])
这块也应该是void input1(char (*question)[81])吧

[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2010-04-19 10:31
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
收藏
得分:0 
回复 3楼 succubus
那不是问题,,,,,,,,就没人看看吗?

[b] 你要有勇气去听从你直觉和心灵的指示,所有其他的事情都是次要的。
2010-04-19 12:30
mywaylgh
Rank: 8Rank: 8
来 自:厨房
等 级:蝙蝠侠
威 望:5
帖 子:188
专家分:729
注 册:2010-3-10
收藏
得分:7 
compar=question1=answer=(char (*)[81])malloc(2*81*sizeof(char));

这三个是同一个东西,它们指向同一个块内存
改变三个中的任意一个对象,其它两个所指的对象也跟着改变...

还有,你动态二维数组的的定义方法实在让人无语....

应该这样定义:
char **p;
p = (char **)malloc(m*sizeof(char *));
for (int i=0;i<m;i++)
   p[i] = (char *)malloc(n*sizeof(char));

人生就像茶几 上面放着许多杯具

人生也像厨房 里面总有一些洗具
2010-04-19 13:37
何少仪
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:91
专家分:170
注 册:2010-3-6
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册







还是不对啊,问题还没传递过去。。
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <conio.h>
#include<windows.h>
#include <string.h>
#define michael  while(getchar()!='\n')  //剔除多余输入
#define jackson  printf("请输入答案")
char (*answer)[81],(*question1)[81],  (*compar)[81];;
static char *question[]={"what the name of mine","who i like the most","when i"
   "first do the\" 1+1\",it is"," yourself question"};
void input1(char *quetion[81]);     //预设问题
int input2();         //问题个数
int judge1(int hh,int ss);      //判断1,2,3,4
void choice(int funny,char (*question1)[81],char (*answer)[81]);  
void output(int a,char (*question1)[81],char (*answer)[81]);

int main(void)
{
  int x=0,a,num[3];
  char ch;

printf("这是一个类似qq密码的程序.\n");
a=input2();
if(a==2)  {answer=(char (*)[81])malloc(2*81*sizeof(char));
         question1=(char (*)[81])malloc(2*81*sizeof(char));
         compar=(char (*)[81])malloc(2*81*sizeof(char));}
else   {answer=(char (*)[81])malloc(3*81*sizeof(char));
        question1=(char (*)[81])malloc(2*81*sizeof(char));
         compar=(char (*)[81])malloc(2*81*sizeof(char));}
input1(question);
srand((unsigned int)time(0));
printf("请选择第一个问题:(输入1,2,3,4):");
num[0]=judge1(0,0);
choice(num[0],question1,answer);
num[1]=judge1(num[0],0);
choice(num[1],question1,answer);
if(a==3)
  {num[2]=judge1(num[0],num[1]);
  choice(num[2],question1,answer); }
while(printf("你已经记住问题啦吗?(y或n):")&&getchar()!='y')
{michael;
Sleep(5000);
}
system("cls");
printf("警告:请不要有任何 动作\n");
for(int b=0;b<50;b++)
 {
 Sleep(1000);
 if(b!=0&&!(b%10))
  printf("还有%d秒",(50-b));
 if(getchar())
  {x=1;
  break;}
 }
 if(x==0)
  {printf("你好心耐心哦,一般很少有人这麽有耐心,呵呵");
  getchar();
  printf("天才即耐心."); }
 if(x==1)
  printf("哦,这麽急");
 output(a,question1,answer);

return 0;
}


  void input1(char *question[81])
  {
      printf("预设问题是:\n");
    for(int a=0;a<4;a++)
     printf("%d.%s\n",a+1,question[a]);
  }
  int input2()
  {void input1(char *quetion[81]);   
      int a;
   printf("你准备输入几个问题(2或3):");
   while(!scanf("%d",&a)||(a!=2&&a!=3))
    {michael;
     printf("请输入2或3,呵呵:");}
   
  return a;
  }
  
  
  int judge1(int hh,int ss)           //判断输入1234的正确性
{
  int a;
  static int b=1;
  
  
  if(b==1)
   while(!scanf("%d",&a)||a<1||a>4)
   {  michael;
        printf("请输入数字1,2,3,4::");}        
  
  else if(b==2&&printf("请选择第二个问题:"))
    while(!scanf("%d",&a)||a==hh||a<1||a>4)
       {michael;
       printf("请输入其他数字 :");}
 else  if(printf("请选择第三个问题:"))
 while((!scanf("%d",&a)||a==hh||a==ss||a<1||a>4))
      {michael;
      printf("请输入其他数字");}
 michael;
b++;
 return a;  
}
void choice(int funny,char (*question1)[81],char (*answer)[81])           //选择答案。
{
   static int a=0;
    printf("%s \n",question[funny-1]);
      if(funny==4)
       {printf("输入你的问题:");
        gets(question1[a]);}
     jackson;
     gets(answer[a]);
     a++;
}

void output(int a,char (*question1)[81],char (*answer)[81])
{
 int b[3],f[3],c,e;
 
  for(c=1,e=0;c<=a;c++)
 {   
  b[0]=rand()%a;
    printf("第1个 问题:%s",question1[b[0]]);
    jackson;
    gets(compar[b[0]]);
   while((b[1]=rand()%a)==b[0]);
   printf("第2个 问题:%s",question1[b[1]]);
   jackson;
   gets(compar[b[1]]);
   if(a==3)
     {
     while((b[2]=rand()%a)==b[0]||b[2]==b[1]);
     printf("第三个问题:%s",question1[b[2]]);
     jackson;
     gets(compar[b[2]]);
     }
  for(int d=0;d<a;d++)
   {
   if(strcmp(compar[b[d]],answer[b[d]]))
    {f[e]=d; e++;}
   }
   if(e==0) break;
   else
     printf("请重新输入 ,你还有%d次机会\n" ,a-c);
 }
}

[b] 你要有勇气去听从你直觉和心灵的指示,所有其他的事情都是次要的。
2010-04-19 17:43
快速回复:为什麽指针没有传递过去,请大虾指点
数据加载中...
 
   



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

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