Question

I recently found out that reading SUB character(ASCII code 26) using fgetc(),fscanf()(Common functions in C to scan characters) makes both of the interpret it as an error and return EOF. I was wondering if there is any way to detect SUB character so that I can distinguish between the 'real' end of file and the apparent one.

Note: The conclusion I am presently on is that end of file is detected using an error in scanning, as SUB character is used to represent error the task looks impossible. But as notepad seems to read it correctly, I am anticipating some technique using C language that I am unfamiliar with.

Was it helpful?

Solution

Open the file(s) in binary mode.

...fopen("filename", "rb")...

Don't forget that the library code no longer translates "newlines" in binary mode. If the file has "\r\n" pairs to end lines, you'll get both '\r' and '\n' when reading the file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top