Write a program to remove the c comments(/* */) and c++ comments(//)from a file.The file should be declared in command line.

Showing Answers 1 - 1 of 1 Answers

rajajayan.j

  • Sep 3rd, 2006
 

#include<stdio.h>
void main()
{
FILE *FI,*FO;
char ch;
FI=fopen("source.c","r");
FO=fopen("target.txt","w");
ch=getc(FI);
while(ch!=EOF)
 {
 if(ch=='/')
  {
  ch=getc(FI);
  if(ch=='/')
   {
   while(ch!='n')
    {
    ch=getc(FI);
    }
   }
  if(ch=='*')
   {
   while(ch!=EOF)
    {
    ch=getc(FI);
    if(ch=='*')
     {
     ch=getc(FI);
     if(ch=='/')
      break;
     }

    }
   }
  ch=getc(FI);
  }


 putc(ch,FO);
 ch=getc(FI);
 }
 close(FI);
 close(FO);
}

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions