#include
int find(char ch[], char data);
void main()
{
char ch[100];
char data;
printf("input ch[]:");
gets(ch);
printf("input data:");
data = getchar();
printf("%d\n", find(ch, data));
}
int find(char ch[], char data)
{
int i;
for (i = 0; ch[i] != '\n'; i++)
{
if (data == ch[i])
{
return (i);
}
}
return (-1);
}
int find( char *words , int length , char word){
//*words用来存放数组的首地址,word 为要查找的字符,length为数组长度
int flag = -1, index = 0; //index为数组的下标,flag 为标志
for(index = 0; index < length; index++){
if(words[index] != word){
}else{ //可以节约判断的次数,减小时空复杂度
flag = index;
break;
}
}
return flag;
}
int find(char *a,char b)
{
for(int i=1;*a!='\0';a++,i++)
if(*a==b)
return i;
return -1;
}
那个2级的写的有点错,应该是return(i+1)
int find(char *s, int length, char tobefound){
int i, j;
j = -1;
for(i = 0; i < length; ++i){
if(s[i] == tobefound){
j = i;
break;
}
}
return j;
}