Unexpected output from lex program -


i have written simple lex program perform average of positive numbers , program compiling fine i'm not able expected output.i'm passing input program file giving filename commandline argument.the output of lex program blank showing no result , i'm beginner in lex , appreciated . have attached code below. code written in redhat linux kernel version 2.4.

 %{  #include <stdio.h>  #include <stdlib.h>  %}  %% [0-9]+ return atoi(yytext); %%  void main() {   int val, total = 0, n = 0;   while ( (val = yylex()) > 0 ) {   total += val;   n++; } if (n > 0) printf(“ave = %d\n”, total/n); }  

the input file contains numbers 3,6 , 4 , name of file passed command line argument.

./a.out < input 

your program works me. i'm bit suspicious of yywrap missing, link -lfl (or alike) option. library contains yywrap , main. though i'm not able reproduce see, i'm wary maybe main libfl used. i'm assuming newlines in input file on output. different linkers have different ways of resolving multiple occurrences of same symbol.

all in think have problem in way program built, because specification seems ok. if add int yywrap(void) { return 1; } after main, can without libfl, advise user of lex , gnu-flex.


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -