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

What is the use of parallelize in spark?

570


What is the scope of an external variable in c?

563


What is %d called in c?

752


What does %c do in c?

580


For what purpose null pointer used?

606






What type of function is main ()?

581


Explain enumerated types.

595


Explain how do I determine whether a character is numeric, alphabetic, and so on?

648


What's a good way to check for "close enough" floating-point equality?

621


what is the significance of static storage class specifier?

1657


how much salary u want ? why u join in our company? your domain is core sector why u prefer software ?

1503


What is the difference between far and near ?

678


What is the value of a[3] if integer a[] = {5,4,3,2,1}?

664


When is the “void” keyword used in a function?

826


How can you call a function, given its name as a string?

710