RVBTCC/test/misc/escape.c

34 lines
865 B
C
Raw Normal View History

2024-12-08 03:40:47 +00:00
int getchar();
int putchar(int ch);
2024-12-08 07:41:38 +00:00
int fprintf(void* file, char* format, ...);
extern void* stdout;
2024-12-08 03:40:47 +00:00
int main() {
2024-12-08 07:41:38 +00:00
char ch = 0["\t\r\""];;
2024-12-08 03:40:47 +00:00
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 {
2024-12-08 07:41:38 +00:00
fprintf(stdout, "unexpected escaped character: '\\%c'\n", ch);
2024-12-08 03:40:47 +00:00
return 1;
}
}
putchar(ch);
}
return 0;
}