-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1-23.c
More file actions
53 lines (48 loc) · 824 Bytes
/
Copy path1-23.c
File metadata and controls
53 lines (48 loc) · 824 Bytes
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
#include <stdio.h>
#define MAXLINE 10000
#define LINES 80
int agetline(char s[], int lim);
void removeComments(char to[]);
int main()
{
int len;
char line[MAXLINE];
agetline(line, MAXLINE);
removeComments(line);
return 0;
}
int agetline(char s[], int lim)
{
int c, i;
for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
s[i] = c;
if (c == '\n') {
s[i] = c;
++i;
}
s[i] = '\0';
return i;
}
void removeComments(char to[])
{
int place, i, j;
int alert;
alert = 0;
char from[MAXLINE];
j = 0;
for(i = 0; to[i] != '\0'; ++i) {
if (to[i] == '/')
if (to[i+1] == '*') {
alert = 1;
}
if (alert != 1) {
from[j] = to[i];
++j;
}
if (to[i] == '/')
if (to[i-1] == '*') {
alert = 0;
}
}
printf("%s", from);
}