程序填空题:字符定位函数
在主函数中输入一个字符串和一个字符,调用match函数,如果该字符在字符串中,就从该字符首次出现的位置开始输出字符串中的字符。如果未找到,输出“Not Found”。
本题要求:根据main函数的程序实现,完成match函数的定义。
```c++
int main(void )
{
char ch, str[80], *p = NULL;
scanf("%s", str);
getchar();
while((ch = getchar())!='\n')
{
if((p = match(str, ch)) != NULL)
printf("%s\n", p);
else
printf("Not Found\n");
}
return 0;
}
@@[char *match(char *s, char ch)](2) /* 字符定位函数定义:match函数*/
{
while (@@[*s != '\0'](1))
if (*s == ch)
@@[return s](1);
else
s++;
return @@[NULL](1);
}
```
答案:
第1空:char *match(char *s, char ch)
第2空:*s != '\0'
第3空:return s
第4空:NULL
本题要求:根据main函数的程序实现,完成match函数的定义。
```c++
int main(void )
{
char ch, str[80], *p = NULL;
scanf("%s", str);
getchar();
while((ch = getchar())!='\n')
{
if((p = match(str, ch)) != NULL)
printf("%s\n", p);
else
printf("Not Found\n");
}
return 0;
}
@@[char *match(char *s, char ch)](2) /* 字符定位函数定义:match函数*/
{
while (@@[*s != '\0'](1))
if (*s == ch)
@@[return s](1);
else
s++;
return @@[NULL](1);
}
```
答案:
第1空:char *match(char *s, char ch)
第2空:*s != '\0'
第3空:return s
第4空:NULL