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

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).