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
Write a program to reverse a linked list in c.
What is the difference between text files and binary files?
Explain modulus operator. What are the restrictions of a modulus operator?
write a program fibonacci series and palindrome program in c
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
Explain how do you list a file’s date and time?
What does d mean?
What is type qualifiers?
Is c high or low level?
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
What does do in c?
4. main() { int c=- -2; printf("c=%d",c); }
Explain which function in c can be used to append a string to another string?
What is the difference between typedef struct and struct?
What is file in c preprocessor?