因为while循环退出的条件就是接受了回车
while循环退出后之后没有输入的语句了所以直接结束了
不要这么写,要检测的字符和字符串分开写比较好,代码参考如下:
#include <stdio.h>
int main() {
char c;
char s[80];
int max = -1;
scanf("%c %s", &c, s);
int i = 0;
while (s[i] != '\0') {
if (c == s[i]) {
max = i;
}
i++;
}
if (max >= 0) {
printf("%d\n", max);
} else {
printf("Not Found\n");
}
return 0;
}