Process the line character by character. if the current character is an unoriented double quote, check the switch. if the switch is 0, convert to ``, then switch the switch to 1. If the switch is 1, convert to '', then switch the switch to 0.
Here's a code:
#include
int main() {
char line[100];
int i;
bool x = 0;
while (fgets(line, 100, stdin)) {
for (i = 0; line[i]; i += 1) {
if (line[i] != '\n') {
if (line[i] == '"') {
if (x == 0) {
printf("``");
x = 1;
}
else {
printf("''");
x = 0;
}
}
else {
printf("%c", line[i]);
}
}
}
printf("\n");
}
return 0;
}
No comments:
Post a Comment