39 lines
875 B
C
39 lines
875 B
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
void output(char* start, char* end) {
|
|
char* ptr = start + 1;
|
|
for (;ptr < end; ptr++) {
|
|
printf("%c",*ptr);
|
|
}
|
|
printf("\n");
|
|
}
|
|
|
|
int main() {
|
|
char* inputStr = NULL;
|
|
char* startIndex = NULL;
|
|
char* p = NULL;
|
|
char startDelimiter, endDelimiter;
|
|
|
|
printf("转译符:");
|
|
scanf("%c", &startDelimiter);
|
|
printf("终止符:");
|
|
scanf(" %c", &endDelimiter);
|
|
getchar();
|
|
inputStr = malloc(141);
|
|
printf("输入文字:");
|
|
scanf("%[^\n]", inputStr);
|
|
p = inputStr;
|
|
while (p - inputStr < strlen(inputStr)) {
|
|
if (*p == startDelimiter) {
|
|
startIndex = p;
|
|
}
|
|
else if (*p == endDelimiter && startIndex != NULL) {
|
|
output(startIndex, p);
|
|
startIndex = NULL;
|
|
}
|
|
p++;
|
|
}
|
|
return 0;
|
|
} |