Your program returns "hello" and "match" for me, and appears to contain no errors.

I suspect tfile.txt does not contain what you think it contains. Your note about getting ".ello" for output makes it look like you've got a "\r" in the buffer somehow - check your file. It should be 5 bytes, exactly. (Use a hex editor to see what's really in the file.)