Update: Changed comparision of pbuff with 0 to BUFFSIZE in ungetch()