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
Does c have enums?
to find the closest pair
Explain what is output redirection?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
Explain the array representation of a binary tree in C.
Write a simple code fragment that will check if a number is positive or negative.
What are local static variables? How can you use them?
Why isnt there a numbered, multi-level break statement to break out
Why isn't it being handled properly?
In which language linux is written?
Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.
What is bash c?
console I/O functions means a) the I/O operations done on disk b) the I/O operations done in all parts c) the input given through keyboard is displayed VDU screen d) none of the above
What is merge sort in c?
What does char * * argv mean in c?