Check sgetc return value when computing lengths