-
Notifications
You must be signed in to change notification settings - Fork 0
/
exec1-23.c
37 lines (35 loc) · 956 Bytes
/
exec1-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
#include <stdio.h>
/* 删除C语言程序中所有注释 */
int main() {
int c, prev;
while ((c = getchar()) != EOF) {
if (c == '\'') { /* 字符常量 */
putchar(c);
putchar(c = getchar());
if (c == '\\')
putchar(getchar());
putchar(getchar());
}
else if (c == '\"') { /* 字符串常量 */
putchar(c);
while ((c = getchar()) != '\"') {
putchar(c);
if (c == '\\')
putchar(getchar());
}
putchar(c);
}
else if (c == '/') {
if ((c = getchar()) == '*') { /* 注释 */
prev = getchar();
while ((c = getchar()) != '/' || prev != '*')
prev = c;
}
else
putchar(c);
}
else
putchar(c);
}
return 0;
}