On Jun 16, 2009, at 12:02 PM, Gary Kline wrote:
this works, but still gives a warning. it's sloppy coding, but as a second version...
You've got some superfluous tests for EOF in some places, and you may also be missing some.
Your approach has been to "look ahead" with an extra getc() when you come across an interesting character. I recommended that instead of doing that you keep a variable "state" to keep track of where you are (and have very recently been) instead of looking ahead.
I haven't tried your code, but I suspect that it behaves incorrectly with input
(1) that has a '<' as a final character (2) that includes things like "<<<<?" (3) that includes things like "??>"There is a systematic (if a bit tedious) way to make sure that you check every condition. When you've worked enough on this, you can peek at an answer which I've attached.
(For the rest of you, I know that it would be more efficient to make the big switch on state instead of on input character, but for pedagogical reasons I did it the other way around. I deliberately avoided other available tunings).
The extensive comments in the code should make it clear what is going on. Once you understand the concepts here it should be very easy to write code to do similar things in the future.
-j -- Jeffrey Goldberg http://www.goldmark.org/jeff/
Description: Binary data
_______________________________________________ email@example.com mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to "freebsd-questions-unsubscr...@freebsd.org"