修改文件结构。
This commit is contained in:
39
POP/12/Exercise03.c
Normal file
39
POP/12/Exercise03.c
Normal file
@@ -0,0 +1,39 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user