PDA

View Full Version : sscanf is ugly



Schitso
March 23rd, 2009, 04:45 PM
So, I'm parsing an HTML file with lines that look like this (variable data in caps):

&nbsp;&nbsp; <a href=conversation?time=UNIXTIME&id=HEXID >STRING</A>(INTEGER)<BR>

And I came up with the following line of code to do so:

sscanf(line, "&nbsp;&nbsp; <A HREF=conversation?time=%*d&id=%x >%[^<]</A>(%d)",&id, username, &unread)

Is there a cleaner/nicer(/shorter) way I could do this? I'm told that I should be avoiding *scanf anyway.
(I wish I could use Perl :( )

crazyfuturamanoob
March 23rd, 2009, 04:47 PM
Maybe use an existing XML parsing library?

Simian Man
March 23rd, 2009, 04:50 PM
That's not so bad. Try doing the same with C++'s cin if you want ugly!

Schitso
March 23rd, 2009, 04:50 PM
The page isn't even HTML compliant, would an XML parser work?

nvteighen
March 23rd, 2009, 07:48 PM
This is exactly what you would use Perl for... :p

No great deal, really: you're using what you have available.