//removes comments from the file and prints to the other file Code: #include<stdio.h> void main(int argc,char *argv[]) { FILE *in,*out; char ch1,ch2; int f=0; in=fopen(argv[1],"r"); out=fopen(argv[2],"w"); while(!feof(in)) { ch1=getc(in); if(ch1=='/') { if((ch2=getc(in))=='/') { while((ch2=getc(in))!='\n') { ; } } else if(ch2=='*') { while((ch2=getc(in))!=EOF) { if(ch2=='*') { if((ch2=getc(in))=='/') f=1; } if(f==1) break; } } } else { putc(ch1,out); } } fclose(in); fclose(out); }
The above solution is not complete. It does not take into account when you have statement like Code: cout<<"/* Please enter your choice */"<<endl;