Write a program to count comment and copy this code in new file and without comment

 


Input Text File

#include<stdio.h>
int main()
{
int a,b;
/*float c; */
//hi
printf("hai");
/*printf("Hello");*/
}


Create One Output Blank Text File


Code

%{
int com=0;
%}

%%
"/*"[^\n]+"*/" {com++; fprintf(yyout," ");}
"//".* {com++; fprintf(yyout," ");}
%%
int main()
{
extern FILE *yyin;
yyin=fopen("CountCommentInput.txt","r");
if(yyin==NULL){
printf("File Not Found");
}
yyout=fopen("CountCommentOutput.txt","w");
yylex();
printf("Comment=%d\n",com);
return 0;
}
int yywrap(){}

Output




Now Output Text File

#include<stdio.h>
int main()
{
int a,b;


printf("hai");

}

This code is replace comment with white space.

Comments