题目链接:
习题11-5 指定位置输出字符串 (20 分)
#include <stdio.h>
#define MAXS 10
char *match( char *s, char ch1, char ch2 );
int main()
{
char str[MAXS], ch_start, ch_end, *p;
scanf("%s\n", str);
scanf("%c %c", &ch_start, &ch_end);
p = match(str, ch_start, ch_end);
printf("%s\n", p);
return 0;
}
/* 你的代码将被嵌在这里 */
char *match( char *s, char ch1, char ch2 ){
int i=0,a=-1;
while(s[i]!=ch1&&s[i]!='\0'){
i++;
}
if(s[i]!='\0'){
a=i;
}
while(s[i]!=ch2&&s[i]!='\0'){
printf("%c",s[i]);
i++;
}
if(s[i]!='\0'){
printf("%c",s[i]);
}
printf("\n");
while(s[i]!='\0'){
i++;
}
if(a>=0){
return &s[a];
}else{
return &s[i];//返回s的最后一位就能通过运行,返回NULL通过不了
}
}