hello frnd this a c program that removes c c++ style comments
removing comments in c and c++ program
//program to print a file by removing comments
/*program*/
#include<stdio.h>
void main(int argc , char *argv[])
{
FILE *fp,*fp1;
char ch;
clrscr();
fp=fopen(argv[1],"r");
fp1=fopen(argv[2],"w");
while(1)
{
ch=fgetc(fp); /*fgetc*/
if(ch==EOF) //eof
break;
else
{
if(ch=='/')
{
ch=fgetc(fp);
if(ch=='/')
{
while(1)
{
ch=fgetc(fp);
if(ch=='\n')
goto label;
}
}
if(ch=='*')
{
while(1)
{
ch=fgetc(fp);
if(ch=='*')
{
ch=fgetc(fp);
if(ch=='/')
{
while(1)
{
ch=fgetc(fp);
goto label;
}
}
else printf("*");
}
}
}
else printf("/");
}
}
label:fputc(ch,fp1);
}
fclose(fp); /*closes the file*/
fclose(fp1);
}
jain_arhant 0 Newbie Poster
niki01 0 Newbie Poster
hobbes78 0 Newbie Poster
thungmail 0 Newbie Poster
Swathyy 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.