If you're not set on "rolling your own", there are existing Open Source packages that may do what you're looking for.
I use Analog and Webalizer myself. Both are available as source or binaries for *nix, Win32, etc. I can't say for sure if they deal with whatever logfile format IIS 4 uses, though.
cheers,
ybiC
Comment on RE: Parsing a log file (analog, webalizer)