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
When should the volatile modifier be used?
Why header file is used in c?
What is d scanf?
What is static and volatile in c?
#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); }
What are the 32 keywords in c?
what is bit rate & baud rate? plz give wave forms
What is the value of c?
write a program to display all prime numbers
Tell me what is the purpose of 'register' keyword in c language?
What is a pointer and how it is initialized?
What is #include stdlib h?
Combinations of fibanocci prime series
Explain what is output redirection?
What is #ifdef ? What is its application?