-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathDeleteComment.cpp
More file actions
78 lines (74 loc) · 1.09 KB
/
DeleteComment.cpp
File metadata and controls
78 lines (74 loc) · 1.09 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* 删除c语言中的单行跟多行注释,注意其中的action
*
*/
#include <stdio.h>
int main(void)
{
char c, state;
state = 0;
while ((c = getchar()) != EOF)
{
if (state == 0)
{
if (c == '/') // 例子: int a = b; /
{
state = 1;
}
else
{
putchar(c); //action
}
}
else if (state == 1)
{
if (c == '/') //例子: int a = b; //
{
state = 2;
}
else if (c == '*') //例子: int a= b; /*
{
state = 3;
}
else //例子: <common/md5.h> or 8/3
{
state = 0;
putchar('/'); //action
putchar(c); //action
}
}
else if (state == 2)
{
if (c == '\n') //例子: int a = b; //hehe<enter>
{
state = 0;
putchar(c); //action
}
//例子: int a = b; //hehe
}
else if (state == 3)
{
if (c == '*') //例子: int a = b; /*heh*
{
state = 4;
}
//例子: int a = b; /*hehe
}
else if (state == 4)
{
if (c == '/') //例子: int a = b; /*hehe*/
{
state = 0;
}
else //例子: int a = b; /*hehe*h
{
state = 3;
}
}
else
{
printf("state error!");
}
}
return 0;
}