-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommentremove.c
More file actions
85 lines (69 loc) · 1.34 KB
/
Copy pathcommentremove.c
File metadata and controls
85 lines (69 loc) · 1.34 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
79
80
81
82
83
84
85
#include "lexer1.h"
void commentremove(FILE *fp){
int starcount = 0;
char nextChar;
int state = 0;
while(1){
nextChar = getCharacter(fp);
switch (state){
case 0:
switch(nextChar){
case '*':
state = 1;
break;
case 26:
return;
default:
state = 0;
printf("%c",nextChar);
break;
}//end inner switch
break;
case 1://something*
switch(nextChar){
case '*':
state = 2;
break;
case 26:
printf("*");
return;
default:
printf("*%c",nextChar);
state = 0;
break;
}//end inner switch
break;
case 2://something**something
switch(nextChar){
case '*':
state = 3;
break;
case 26:
return;
default:
if (nextChar=='\n'){
printf("%c",nextChar);
}
state = 2;
break;
}//end inner switch
break;
case 3://something**something*
switch(nextChar){
case '*':
state = 0;
break;
case 26:
return;
default:
state = 2;
break;
}//end inner switch
break;
}//end outer switch
}printf("seriosly?\n");
}
int main(){
FILE* fp = fopen("t1.txt","r");
commentremove(fp);
}