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


Please Help Members By Posting Answers For Below Questions

Write a program to reverse a linked list in c.

639


What is the difference between text files and binary files?

674


Explain modulus operator. What are the restrictions of a modulus operator?

595


write a program fibonacci series and palindrome program in c

630


Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

2552






Explain how do you list a file’s date and time?

615


What does d mean?

581


What is type qualifiers?

653


Is c high or low level?

577


exit () is used to a) exit () terminates the execution of the program itself b) exit () terminates the execution of the loop c) exit () terminates the execution of the block d) none of the above

656


What does do in c?

606


4. main() { int c=- -2; printf("c=%d",c); }

1364


Explain which function in c can be used to append a string to another string?

582


What is the difference between typedef struct and struct?

592


What is file in c preprocessor?

648