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

Popular posts from this blog

Write A Program To Print Hello World Using Lex

Create a Student registration form using following tags form,input,textarea,button,select,optio. The registration form must consist of following information: first name,Middle name,last name, gender(use radio button),address,phone no,email id,hobbies(use checkbox),city,state,country,collage name (use dropdown menu).