Checking for null characters in the middle of a character sequence

Hi Guys,


Im having a text file which its contents looks like following:


Abbcasacacasca NUL Abbcasacacasca


I tried to read from the line but it seems skipped the second part of the string.
Did anyone know how to solve this problem?

:)

Read the file in binary mode. Any file containing unprintable characters should be considered binary, and this is your case.
Hi WebJose,

Thanks for the quick response :) By the way I'm newbie in C++, so what u meant is I can detect and replace null terminator in binary mode?


Normally when you open a stream in text mode, the stream assumes certain things and behaves differently than when opened in binary mode. For example, in text mode null chars could be considered the end of a line, or even an error! Binary files, on the other hand, can have pretty much anything in them.

When you read a file in binary mode, you obtain the data in chunks in a byte array (an array of char, usually). You can examine this array to determine if there are null chars that prevent you from correctly interpreting the data as text, and if there are, you can replace them. Once you do, you are free to reinterpret the data as a string (provided you do have a trailing null char!).
How are you trying to read the line?
Topic archived. No new replies allowed.