1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| #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, ch1index, ch2index, flag; char *p, ch = '\0'; flag = 0; ch1index = ch2index = 0; for (i=0; s[i] != '\0'; i++) { if (s[i] == ch1) { ch1index = i; flag = 1; break; } } if (!flag) { printf("\n"); p = &ch; return p; } for (; s[i] != '\0'; i++) { if (s[i] == ch2) { ch2index = i; flag = 0; break; } } for (i=ch1index; i<=ch2index; i++) printf("%c", s[i]); if(flag) { for (i=ch1index; s[i] != '\0'; i++) printf("%c", s[i]); } printf("\n"); p = &s[ch1index]; return p; }
|