Write a program to remove the C comments(/* */) and C++
comments(//) from a file.
The file should be declared in command line.
Answer Posted / sahil
/*Improved and working answer*/
#include<stdio.h>
void main()
{
FILE *fd;
int ch,flag,i;
char cc;
i=flag=0;
ch=0;
fd = fopen("file","r+");
// ch=fgetc(fd);
while((ch=fgetc(fd))!=EOF)
{ cc=ch;
flag = 0;
if(ch == '/')
{
ch = fgetc(fd);cc =ch;
if(ch == '*')
{
flag = 1;
while(1){
cc = fgetc(fd);
if(fgetc(fd) == '*' && fgetc(fd) == '/')
break;
}
}
else if(ch == '/')
{
flag = 1;
while(fgetc(fd)!= '/');
}
else{
printf("/");
}
}
if(!flag )
printf("%c",ch);
}
fclose(fd);
}
| Is This Answer Correct ? | 9 Yes | 13 No |
Post New Answer View All Answers
shorting algorithmS
what are bit fields? What is the use of bit fields in a structure declaration?
Differentiate between declaring a variable and defining a variable?
What are c identifiers?
Which programming language is best for getting job 2020?
Can main () be called recursively?
How do I use void main?
What is difference between arrays and pointers?
Hi can anyone tell what is a start up code?
What is storage class?
What is actual argument?
What kind of structure is a house?
What does == mean in texting?
What is wrong with this code?
how to make a scientific calculater ?