为什麽指针没有传递过去,请大虾指点(想啦几天啦

funnyone 2010-04-19 01:30:50
为什麽指针没有传递过去,请大虾指点
// 为什麽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);
}
}

...全文
166 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2010-04-20
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 wx7864566 的回复:]
3楼,我真想打你,你就只会那一句话?CAO!
[/Quote]
不怕千招会,就怕一招鲜。
funnyone 2010-04-19
  • 打赏
  • 举报
回复
哈哈,终于对啦,谢谢大家啦,selooloo谢谢,,很长时间啦。。。。。。。

有时间到qq群111397358,,,
selooloo 2010-04-19
  • 打赏
  • 举报
回复
又看了下,你那问题之所以没显示是因为question1和answer共用内存了,对answer的修改也作用在questionq上,所以看上去是指针没传递过去

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

printf("ÕâÊÇÒ»¸öÀàËÆqqÃÜÂëµÄ³ÌÐò.\n");
a=input2();
if(a=2) {question1=(char (*)[81])malloc(2*81*sizeof(char));
answer=(char (*)[81])malloc(2*81*sizeof(char));
compar=(char (*)[81])malloc(2*81*sizeof(char));}
else {question1=(char (*)[81])malloc(3*81*sizeof(char));
answer=(char (*)[81])malloc(3*81*sizeof(char));
compar=(char (*)[81])malloc(3*81*sizeof(char));}



这个也要改
void choice(int funny,char (*question1)[81],char (*answer)[81]) //Ñ¡Ôñ´ð°¸¡£
{
static int a=0;
printf("%s \n",question[funny-1]);
strcpy(question1[funny-1],question[funny-1]);
if(funny==4)
{printf("ÊäÈëÄãµÄÎÊÌâ:");
//gets(question1[a]);
strcpy(question1[funny-1],question[funny-1]);}
jackson;
gets(answer[a]);
a++;
}

还有LZ的程序估计自己看得也晕吧,命名有点乱;你既然定义了全局变量,就不需要形参传递了,而且形参和实参名字还一样
funnyone 2010-04-19
  • 打赏
  • 举报
回复
可以运行,只是数据有误,在清理界面后。。。。。。。。。。。。。。。
yiruirui0507 2010-04-19
  • 打赏
  • 举报
回复
以上代码在VC6.0下好象没问题啊,请问楼主是什么编译器?
ithiker 2010-04-19
  • 打赏
  • 举报
回复
呵呵,程序很有意思啊,帮顶下...
funnyone 2010-04-19
  • 打赏
  • 举报
回复
谢谢大家,但是问题是


就是问题没有传递过来。。。。。。
netlover2008 2010-04-19
  • 打赏
  • 举报
回复
看着头痛。。。
xinzaiyiqi 2010-04-19
  • 打赏
  • 举报
回复
这程序是干啥的?
selooloo 2010-04-19
  • 打赏
  • 举报
回复
还有answer 和question使用完了记得free
selooloo 2010-04-19
  • 打赏
  • 举报
回复
问题都在output函数里

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-19
  • 打赏
  • 举报
回复
3楼,我真想打你,你就只会那一句话?CAO!
赵4老师 2010-04-19
  • 打赏
  • 举报
回复
单步调试和设断点调试是程序员必须掌握的技能之一。

VC调试时按Alt+8,TC或BC用TD调试,打开汇编窗口看每句C对应的汇编不就啥都明白了吗。
想要从本质上理解C指针,必须学习汇编以及C和汇编的对应关系。
从汇编的角度理解和学习C语言的指针,原本看似复杂的东西就会变得非常简单!
wade_2003 2010-04-19
  • 打赏
  • 举报
回复
问题在哪里呢?
funnyone 2010-04-19
  • 打赏
  • 举报
回复
分数不多,请帮忙

69,373

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧