我正在尝试编写一个程序,该程序搜索字符串中特定字符的首次出现。但是无论我输入的数字是什么字符,程序都会返回最后一个字符的数字。
int where (char *str,char ltr);
int main () {
char word [80];
char letter;
printf("Type in a word: ");
scanf("%s",word);
printf("Type in a character: ");
scanf("%s",letter);
printf("%d",where(word,letter));
}
int where (char *str,char ltr){
int i = 0;
while(i < strlen(str)){
if(ltr == str[i]){
break;
}
i++;
}
return i;
}