Write a program to remove the C comments(/* */) and C++
comments(//) from a file.
The file should be declared in command line.
Answer Posted / vadivel
#include<stdio.h>
int main(int argc,char *argv[])
{
FILE *f;
int flag;
f = fopen(argv[1],"r");
while(!feof(f))
{
ch = fgetc(f),flag = 0;
if(ch == '/')
{
ch = fgetc(f);
if(ch == '*')
{
flag = 1;
while(1)
if(fgetc(f) == '*' && fgetc(f) == '/')
break;
}
else if(ch == '/')
{
flag = 1;
while(fgetc(f)!= '/n');
}
else
printf("/");// if it s division operator
}
if(!flag )
printf("%c",ch);
}
fclose(f);
}
/*
Run d prog as
>./a.out file_name.cpp
*/
| Is This Answer Correct ? | 54 Yes | 47 No |
Post New Answer View All Answers
What is the use of the function in c?
Do you know the use of fflush() function?
Explain how do you declare an array that will hold more than 64kb of data?
Explain the priority queues?
What are header files in c?
What are two dimensional arrays alternatively called as?
Are pointers integers in c?
What is the difference between text and binary i/o?
What does emoji p mean?
How can I prevent another program from modifying part of a file that I am modifying?
Why is it usually a bad idea to use gets()? Suggest a workaround.
What are actual arguments?
Is c a great language, or what?
What are pointers? What are different types of pointers?
What is the difference between exit() and _exit() function?