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


Please Help Members By Posting Answers For Below Questions

When should the volatile modifier be used?

689


Why header file is used in c?

582


What is d scanf?

599


What is static and volatile in c?

785


#include show(int t,va_list ptr1) { int a,x,i; a=va_arg(ptr1,int) printf(" %d",a) } display(char) { int x; listptr; va_star(otr,s); n=va_arg(ptr,int); show(x,ptr); } main() { display("hello",4,12,13,14,44); }

776






What are the 32 keywords in c?

639


what is bit rate & baud rate? plz give wave forms

1524


What is the value of c?

576


write a program to display all prime numbers

1461


Tell me what is the purpose of 'register' keyword in c language?

623


What is a pointer and how it is initialized?

613


What is #include stdlib h?

621


Combinations of fibanocci prime series

1116


Explain what is output redirection?

670


What is #ifdef ? What is its application?

651