Write a program to add line number in input program

 


Input Text File

#include<stdio.h>
int main()
{
int a=10,b=20;
int c=a+b;
printf("Addition of a and b is:%d",c);
return 0;
}

Code


%{
#include<stdio.h>
int line_number = 1;
%}
line .*\n
%%
{line} { printf("%d %s", line_number++, yytext); }
%%
int yywrap(){}
int main()
{
extern FILE *yyin;
yyin=fopen("SimpleCodeInput.txt","r");
if(yyin==NULL){
printf("File Not Found");
}
yylex();
return 0;
}

Output



Comments