-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemovecomments.c
77 lines (76 loc) · 1.24 KB
/
Removecomments.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void is_comment(FILE *,FILE *);
int main(int argc, char *argv[])
{
FILE *fsrc,*fdest;
if(argc!=3)
{
printf("improper no of arguments\n");
printf("Specify input and output file names at command line\n");
exit(0);
}
fsrc=fopen(argv[1],"r"); //opening input file in read mode
fdest=fopen(argv[2],"w");
is_comment(fsrc,fdest);
printf("comments are removed. check it in output file\n");
printf("Thank you\n");
return;
}
void is_comment(FILE *input,FILE *output)
{
char c,s[2]={0};
while((c=fgetc(input))!=EOF)
{
if(c=='/')
{
c=fgetc(input);
if(c=='/')
{
while((c=fgetc(input))!='\n')
{
if(c==EOF)
break;
}
}
else if(c=='*')
{
do
{
s[0]=fgetc(input);
s[1]=fgetc(input);
if(s[0]==EOF || s[1]==EOF)
break;
}while(strcmp(s,"*/"));
}
else
{
fputc('/',output);
fputc(c,output);
}
}//if
fputc(c,output);
if(c=='\"')
{
fputc(c,output);
while(1)
{
c=fgetc(input);
if(c=='\"')
{
fputc(c,output);
break;
}
else if(c==EOF)
{
break;
}
else
{
fputc(c,output);
}
}//while
}//if
}
}