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
why to assign a pointer to null sometimes??how can a pointer we declare get assigned with a garbage value by default???
What tq means in chat?
p*=(++q)++*--p when p=q=1 while(q<=6)
exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above
What are the different types of pointers used in c language?
What is unsigned int in c?
what is the significance of static storage class specifier?
What are Macros? What are its advantages and disadvantages?
State two uses of pointers in C?
How do you convert strings to numbers in C?
What is pragma c?
What is the difference between break and continue?
What are qualifiers?
Differentiate between the = symbol and == symbol?
Write a program to swap two numbers without using a temporary variable?