I found the bug. For others facing a similar problem, be careful of the difference in how C handles characters versus integers, especially with characters with ASCII values over 128.