help-flex
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: flex input and output


From: John W. Millaway
Subject: Re: flex input and output
Date: Wed, 28 Nov 2001 19:41:41 -0800 (PST)

--- Andrew Robertson <address@hidden> wrote:
> Hi i have a simple question that I hope someon can answer:
> 
> I want to analyse input from a file and if it contains a certain text
> string output it to a different file.  I think I've worked it all out
> except for writing to the output file. I know I should be using
> yyiput=file(where I have used the correct fopen construct) but I don't
> know what to do with the output. I've read that you could redefine yyout
> in the definition section but I haven't come across any examples. Any help
> would be appreciated.

Just assign whatever value you want to yyin and yyout.  You can reassign yyout
anytime you want, without any problems. But if you reassign yyin, be aware that
flex has already read ahead of the current pattern (unless you've hit EOF of
course), and you may want to flush the buffer. See the manual for this.

However, if it's just a simple text string or pattern you're looking for, then
flex may be overkill for this problem. Look at strstr(3) for finding static
strings, regcomp(3) and pcre(3) for pattern matching in C. If you just need to
pull out lines of a file, then there's trusty ol' grep.

-John


__________________________________________________
Do You Yahoo!?
Yahoo! GeoCities - quick and easy web site hosting, just $8.95/month.
http://geocities.yahoo.com/ps/info1



reply via email to

[Prev in Thread] Current Thread [Next in Thread]