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

All technical questions

1514


When should the register modifier be used? Does it really help?

622


Explain the meaning of keyword 'extern' in a function declaration.

733


What is the c language function prototype?

651


Explain the ternary tree?

605






Explain what math functions are available for integers? For floating point?

618


What is a program?

669


What is #define in c?

624


What is the purpose of the preprocessor directive error?

687


Explain what is a stream?

613


If I have a char * variable pointing to the name of a function ..

662


What is the difference between test design and test case design?

1578


What is a pointer variable in c language?

649


what are non standard function in c

1441


What is hash table in c?

577