帮我看看怎么会执行不了,并且出现unhandled exception是什么意思??

#include<stdio.h>
#define ARRA_SIZE 100
int Find(char *p,char b);
main()
{
char a[ARRA_SIZE],b;
int i,j,pos;
char *p;

printf("Please input a string:\n");
gets(a);

for(j=0;j<ARRA_SIZE;j++)
{
printf("Please input the found character:\n");
scanf("%c",&b);
p=a;
Find(*p,b);
pos=Find(*p,b);
if(pos!=-1)
{
printf("the pos is:\n",pos);
}
else
{
printf("Not found!\n");
}
}

}
int Find(char *p,char b)
{
int pos,i;

for(i=0;i<ARRA_SIZE;i++)
{
if(*(p+i)==b)
{
pos=i;
return(pos);
}
else
{
return(-1);
}
}
}

鄙人以为,unhandled exception就是系统不能解决的异常,需要用户决定处理方式~~这种情况通常是你的程序读取了系统的内存,而系统的内存收到系统的保护,于是就会弹出这样的提示~~。另外,主函数里面调用时实参类型不匹配,是错误的,Find函数的第一个参数是指针型,调用的时候应该用指针,而不应该用字符 ···以下是我修改过的:

#include<stdio.h>
#define ARRA_SIZE 100
int Find(char *p,char b);
main()
{
char a[ARRA_SIZE],b;
int i,j,pos;
char *p;

printf("Please input a string:\n");
gets(a);

for(j=0;j<3;j++)/*这里应该不用100次吧··LZ自己控制,我改为3次就好了*/
{
printf("Please input the found character:\n");
/*scanf("%c",&b);要考虑上一次输入的回车符,不要单纯的读入*/
if((b=getchar())=='\n') b=getchar();/*这样应该可以了*/
p=a;
Find(p,b);/*应该是p,不是*p,因为p才是指针,或者可以用a,数组名是指针常量*/
pos=Find(p,b);/*同上*/
if(pos!=-1)
{
printf("the pos is:%d\n",pos);/*漏了%d*/
}
else
{
printf("Not found!\n");
}
}

}
int Find(char *p,char b)
{
int pos,i;

for(i=0;i<ARRA_SIZE;i++)
{
if(*(p+i)==b)
{
pos=i;
return(pos);
}
else
{
/*return(-1);如果没有找到应该向后寻找,而不是返回吧···*/
pos = -1;
}
}
return pos;
}来自:求助得到的回答
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-12-10
改了下,至少可以用了。。。。
#include<stdio.h>
#define ARRA_SIZE 100
int Find(char *p,char b);
int main()
{
char a[ARRA_SIZE],b;
int i,j,pos;
char *p;

printf("Please input a string:\n");
gets(a);

for(j=0;j<ARRA_SIZE;j++)
{
printf("Please input the found character:\n");
scanf("%c",&b);
p=a;
//Find(*p,b);
pos=Find(p,b);
if(pos!=-1)
{
printf("the pos is: %i\n",pos);
fflush(stdin);
}
else
{
printf("Not found!\n");
}
}
return 0;
}
int Find(char *p,char b)
{
int pos,i;

for(i=0;i<ARRA_SIZE;i++)
{
if(*(p+i)==b)
{
pos=i;
return(pos);
}
}
return -1;
}
相似回答