This is a better fix which will cater for the case where the first character encountered is the EOF (-1) character. EOF test now only occurs when loop is exit so this should execute more efficiently.