Saturday, 8 September 2018

Write a LEX program to count total printf and scanf statements from input file. Count should be written in output file.


%{
#include<stdio.h>
int c_s=0,c_p=0;
%}
%%
"scanf" {c_s++;}  
"printf" {c_p++;}
%%
main()
{
yyin=fopen("input.txt","r");
yyout=fopen("output.txt","w");
yylex();
fprintf(yyout,"%d printf's \n",c_p);
fprintf(yyout,"%d scanf's \n",c_s);
}
int yywrap()
{
return(1);
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...