Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

Explain About fork()?

1127


How can I dynamically allocate arrays?

1114


What does the c in ctime mean?

1107


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)

6889


What are the benefits of organizational structure?

1032


What are the 5 types of organizational structures?

1091


Can you define which header file to include at compile time?

1033


Without Computer networks, Computers will be half the use. Comment.

2325


Which is an example of a structural homology?

1335


What is echo in c programming?

1042


What is the use of gets and puts?

1047


What is an lvalue in c?

1139


What is unary operator?

1118


What is #error and use of it?

1293


‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

2353