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
Write a code to generate a series where the next element is the sum of last k terms.
How can I trap or ignore keyboard interrupts like control-c?
What is time null in c?
how can i access hard disk address(physical address)? are we access hard disk by using far,near or huge pointer? if yes then please explain.....
What is a class c rental property?
What is identifier in c?
When was c language developed?
a program that can input number of records and can view it again the record
Can static variables be declared in a header file?
Where does the name "C" come from, anyway?
What does & mean in scanf?
What are volatile variables in c?
A float occupies 4 bytes in memory. How many bits are used to store exponent part? since we can have up to 38 number for exponent so 2 ki power 6 6, 6 bits will be used. If 6 bits are used why do not we have up to 64 numbers in exponent?
i have a written test for microland please give me test pattern
What is main function in c?