-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.23.c
61 lines (56 loc) · 1.08 KB
/
1.23.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "stdio.h"
void read_comment(char c);
void echo_quote(char c);
void in_comment();
int main() {
char c;
while((c = getchar()) != EOF) {
read_comment(c);
}
return 0;
}
void read_comment(char c) {
char d;
if (c == '/') {
d = getchar();
if (d == '/') {
putchar(c);
read_comment(d);
} else if (d == '*') {
in_comment();
} else {
putchar(c);
putchar(d);
}
} else if (c == '"' || c == '\'') {
echo_quote(c);
} else {
putchar(c);
}
}
void in_comment() {
char c;
char d;
while((c = getchar()) != EOF) {
if (c == '*') {
if ((d = getchar()) == '/') {
break;
}
}
}
}
void echo_quote(char c) {
char d;
putchar(c);
while((d = getchar()) != EOF) {
if (d == c) {
putchar(d);
return;
} else if (d == '\\') {
putchar(d);
putchar(getchar());
} else {
putchar(d);
}
}
}