以下程序的功能是输入一个字符串和一个字符,如果该字符在字符串中,就从该字符首次出现的位置开始输出字符串中的字符。例如,如果输入的字符串为“Hello”,输入的字符为’e’,则输出结果为“ello”。请填空。
此处输入答案 match(char *s, char ch) {
while (*s != ‘\0’)
if (*s == ch)此处输入答案;
else s++;
此处输入答案
}
int main()
{
char ch, str[80], *p = NULL;
scanf("%s", str);
getchar();
ch = getchar();
if ((p = match(str, ch)) != NULL)
printf("%s\n", p);
else
printf(“Not Found\n”);
return 0;
}
答案:
char match(char *s, char ch) {
while (*s != '\0')
if (*s == ch)break;
else s++;
return s;
}
int main()
{
char ch, str[80], *p = NULL;
scanf("%s", str);
getchar();
ch = getchar();
if ((p = match(str, ch)) != NULL)
printf("%s\n", p);
else
printf("Not Found\n");
return 0;
}