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
Explain About fork()?
How can I dynamically allocate arrays?
What does the c in ctime mean?
Write a program that takes a 5 digit number and calculates 2 power that number and prints it(should not use big integers and exponential functions)
What are the benefits of organizational structure?
What are the 5 types of organizational structures?
Can you define which header file to include at compile time?
Without Computer networks, Computers will be half the use. Comment.
Which is an example of a structural homology?
What is echo in c programming?
What is the use of gets and puts?
What is an lvalue in c?
What is unary operator?
What is #error and use of it?
‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.