RVBTCC/test/misc/escape.c
2024-12-24 11:31:50 +08:00

34 lines
865 B
C

int getchar();
int putchar(int ch);
int fprintf(void* file, char* format, ...);
extern void* stdout;
int main() {
char ch = 0["\t\r\""];;
while ((ch = getchar()) != -1) {
if (ch == '\\') {
ch = getchar();
if (ch == 'n') {
ch = '\n';
} else if (ch == 't') {
ch = '\t';
} else if (ch == 'r') {
ch = '\r';
} else if (ch == '0') {
ch = '\0';
} else if (ch == '\\') {
ch = '\\';
} else if (ch == '\'') {
ch = '\'';
} else if (ch == '\"') {
ch = '\"';
} else {
fprintf(stdout, "unexpected escaped character: '\\%c'\n", ch);
return 1;
}
}
putchar(ch);
}
return 0;
}