[LCP] tokening strings in C?
David Nugent
davidn at datalinktech.com.au
Wed Jan 7 09:03:24 EST 2009
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/01/2009, at 4:19 AM, Zach Uram wrote:
> Hi everyone!
>
> I wish to parse a game log file and tokenize the parts I want and then
> save them to an HTML file. Here are some typical lines from the log
> file:
>
> Tue Dec 23 21:29:47 2008
> 09:29:47 Kathy->ALL Robot Annihilator (R3) was ejected to make room
> for a human player.
> 09:29:47 R3->ALL Ensign Annihilator (R3) leaving game (Pre_T_Robot!
> @localhost)
> 09:29:47 R6->ALL Flt. Capt. hyperyoda is now R6
> (ubuntu@=66.207.132.65)
> 09:29:47 R6->R6 @2.5.0.0
> 09:29:47 Kathy->ALL Resetting for real T-mode!
> 09:29:47 Kathy->ALL Restoring previous T-mode galaxy.
> 09:29:48 GOD->ALL Diplomat insults foreign emperor's mother and
> fighting breaks out!
> 09:29:48 GOD->ALL Flt. Capt. hyperyoda is not using a trusted client
> 09:29:56 GOD->ALL Idled [CA] (R7) was kill 1.00 for guest [CA]
> (F2) [photon]
> 09:29:57 GOD->ALL guest [CA] (F2) was kill 1.10 for Idled [CA]
> (R7) [explos]
> 09:30:06 R6->ROM Bombing org @ 8
> 09:30:13 R6->R1 @
> 09:30:14 GOD->R6 R1 is NCC-Voyager
> (play.netrek.org at cpe-24-174-149-36.satx.res.rr.com)
> 09:30:14 GOD->R6 R1 at 24.174.149.36 (IP)
> 09:30:15 R6->R1 t mode!
>
> I am mainly interested in coversations between human players: a->b
> Such as above: 09:30:15 R6->R1 t mode!
> Also I want to preserve the time code.
> Messages that are "GOD->ALL" i wish to save in a different HTML file.
>
> Some messages may have weird characters like "%" in them so how I
> handle these?
% characters are not "weird". :-) You should not have to handle these
in any special way.
> Anyone have any ideas how to do this and even better some code to get
> me started?
There are basically 3 things you want to parse: the timestamp, the
prefix (whatever it means), and the log entry.
strtok() is your friend here and is generally a much more robust
approach than *scanf(). Just parse the tokens and break off the first
two sections and you're left with the rest. Parse the first two
sections individually and error check as required.
Straight from google:
Reference: http://www.opengroup.org/onlinepubs/000095399/functions/strtok.html
Example: http://www.metalshell.com/source_code/31/String_Tokenizer.html
Hope this helps,
David
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)
iEYEARECAAYFAklj1S0ACgkQgyBtWyGDJqUI5wCfQ7DHnDXEmIKodIpPybPDZdvN
BG0AnRPQdkefzyRwOzDdZi/Oq5l8LacB
=Alru
-----END PGP SIGNATURE-----
More information about the linuxCprogramming
mailing list