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

What is the use of the function in c?

1006


Do you know the use of fflush() function?

1050


Explain how do you declare an array that will hold more than 64kb of data?

1439


Explain the priority queues?

1068


What are header files in c?

1058


What are two dimensional arrays alternatively called as?

1165


Are pointers integers in c?

1059


What is the difference between text and binary i/o?

1038


What does emoji p mean?

1100


How can I prevent another program from modifying part of a file that I am modifying?

1034


Why is it usually a bad idea to use gets()? Suggest a workaround.

1764


What are actual arguments?

1073


Is c a great language, or what?

1094


What are pointers? What are different types of pointers?

1120


What is the difference between exit() and _exit() function?

1025