-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempCodeRunnerFile.c
More file actions
44 lines (43 loc) · 922 Bytes
/
tempCodeRunnerFile.c
File metadata and controls
44 lines (43 loc) · 922 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
#include <stdio.h>
int main()
{
FILE *fp1, *fp2;
char c, prev;
int comment = 0;
fp1 = fopen("hello.c", "r");
fp2 = fopen("new_hello.c", "w");
if (fp1 == NULL || fp2 == NULL)
{
printf("Unable to open file.\n");
return 0;
}
while ((c = fgetc(fp1)) != EOF)
{
if (comment == 1)
{
if (prev == '*' && c == '/')
comment = 0;
}
else
{
if (prev == '/' && c == '*')
{
comment = 1;
continue;
}
else if (prev == '/' && c == '/')
{
while ((c = fgetc(fp1)) != '\n');
}
else
{
fputc(prev, fp2);
}
}
prev = c;
}
fclose(fp1);
fclose(fp2);
printf("Comments removed successfully.\n");
return 0;
}