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 / palash das

//This works on c-string...


#include <stdio.h>

void remove_cmmnt(char *s)
{
int i,j;
for(i=j=0; s[j] ; )
{
if(s[j]=='/' && s[j+1] && s[j+1]=='/')
for(j+=2; s[j] && s[j++]!='
'; ) ;
else if(s[j]=='/' && s[j+1] && s[j+1]=='*')
for(j+=2; s[j] && s[++j] && (s[j-1]!='*' || s[j]!='/' || !j++); );
else
s[i++]=s[j++];
}
s[i]='';
}

int main()
{
char s[]="/*123***/Hello // Cross
World /* **NachLeCoders";
remove_cmmnt(s);
puts(s);
return 0;
}

Is This Answer Correct ?    2 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what is the best way to comment out a section of code that contains comments?

1108


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

16636


How can I dynamically allocate arrays?

1045


What is a pointer in c?

1458


What are the advantages of c language?

1059


HOW TO SOLVE A NUMERICAL OF LRU IN OS ??????

2654


How do shell structures work?

1082


What is hashing in c language?

1224


Which is an example of a structural homology?

1277


Under what circumstances does a name clash occur?

1170


please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................

1974


Why c is a mother language?

986


How can I find out how much free space is available on disk?

1026


What are the string functions? List some string functions available in c.

955


in ‘C’ language for Matrix Multiplication fails” Introspect the causes for its failure and write down the possible reasons for its failure.

8011