You need to put them on "stack" while parsing. Push to your stack when having an open tag, remove in reverse order when a closing tag happen. If close-tag <> open tag type you have an error.
Count lines while parsing and when a mismatch occur print the line-number you're at. Count line numbers by counting line-feeds (char 10 for Windows/Linux, use 13 for Mac).
Compare closing tags with "/" + opening-tag
Stack (pesudo-representation to show the "mechanics"):
Parser res Current stack
---------- -------------
Found TR -> TR
Found TD -> TR-TD
Found /TD -> TR (it matched last tag on stack)
Found TD -> TR-TD
Found /TD -> TR (it matched last tag on stack)
Found /TR -> (it matched last tag on stack - stack is empty, all ok)
Found TR -> TR
Found TD -> TR-TD
Found /TD -> TR (it matched last tag on stack)
Found TD -> TR-TD
Found /TD -> TR (it matched last tag on stack)
Found TR -> TR (mismatch! /+TR <> TR as expected), print error + line number