This lex program will read an input file and copy the content with line number to another file.
%{
#include<stdio.h>
#include<string.h>
char line[20];
int count=0,i=0;
FILE *out;
%}
%%
['\n'] { fprintf(out,"%d %s\n",++count,line);}
(.*) {
strcpy(line,yytext);
}%%
main()
{
yyin=fopen("in.c","r");
out=fopen("out.c","w");
yylex();
getch();
}
int yywrap()
{
return 1;
}
input
main()
{
int i=9, j=900,k=115;
printf("%d,i+j+k);
}
output file
1 main()
2 {
3 int i=9, j=900,k=115;
4 printf("%d,i+j+k);
5 }
6 }
14 comments :
I faced with error which provide me segmentation fault ( core dump ).
program is not running
program is not running
i am not understanding..
@Anonymous
Tell me your doubt!
i am getting error in (.*) part..
actually why we are using (.*)..
Very informative article.Thank you author for posting this kind of article .
http://www.wikitechy.com/view-article/string-copy-program-in-c-example-with-explanation
Both are really good,
Cheers,
Venkat
giving an error on 13th , 17th and 18th line as unrecognized rule
segmentation fault
Respected Sir,
how to install lex programming software in windows 8
and how to do programming well.
please help!!!
lex :can't open this file
this is the output
asdfgth
lol
sdfghjkl
Post a Comment