输入一个字符,再输入一个以回车结束的字符串(少于80 个字符),在字符串中查找该
# include <stdio.h>
int main(void)
{
int i,b=0;
char a,str[80];
printf("Input a character:");
a=getchar();
printf("Input a string:");
for(i=0;i<80;i++){
str[i]=getchar();
if(str[i]=='\n')
break;}
for(i=0;i<80;i++){
if(str[i]==a)
b=i;
}
if(b==0)
printf("NotFound");
else
printf("index=%d",b);
return 0;
}求高手找错
#include <stdio.h>
int main(void)
{
int i,b=-1;
char a,str[80];
printf("Input a character:\n");
scanf("困租世%c", &a);
printf("Input a string:\n");
/*
for(i=0;i<80;i++)
{
str[i]=getchar();
if(str[i]=='\型哗n')
break;
}
*/
scanf("%s", str);
for(i=0;i<80;i++){
if(str[i]==a)
b=i;
}
if(b==-1)
printf("NotFound\n");
else
printf("index=%d\n",b);
return 0;
}
看看吧,调试通过汪肢了