RVBTCC/test/escape.c

32 lines
805 B
C
Raw Normal View History

2024-12-08 03:40:47 +00:00
int getchar();
int putchar(int ch);
int printf(char* format, ...);
int main() {
int ch;
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 {
printf("unexpected escaped character: '\\%c'\n", ch);
return 1;
}
}
putchar(ch);
}
return 0;
}