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

How to create struct variables?

1045


Is there sort function in c?

969


What is meant by gets in c?

1103


Does c have enums?

1027


How can this be legal c?

1043


Explain what is wrong with this statement? Myname = ?robin?;

1523


What is difference between Structure and Unions?

1185


What is pointers in c with example?

1023


Why c is called a middle level language?

1052


What is a structure and why it is used?

1135


What is meant by realloc()?

1084


Add Two Numbers Without Using the Addition Operator

769


Explain function?

1034


Is fortran still used today?

1041


Why are all header files not declared in every c program?

1041