I'm reading a text file with this format:
DUMMY,0000000000000100100000000000000000
JOHNDOE,0000000000000010000000100000000100
FOO,0000000000000000000000000100000000
BAR,1000000100000000000000000000000000
When using fgets like this:
while (fgets(line, linelength, stream) != NULL) {
...
}
It always get three junk characters in the first line. I tried deleting the first line with a plain text editor just to test there's nothing like non-printable characters before the text, with no results. They are always the same three chars. The first line, when readed by fgets looks like this in the Visual Studio debugging console:
DUMMY,0000000000000100100000000000000000
When used printf to show on the terminal, it looks like this:
DUMMY,0000000000000100100000000000000000
As said above, if I delete the first line of the input file, then the next line also has the same characters:
JOHNDOE,0000000000000010000000100000000100
Funny thing, if I put an empty line as the first one in the input file, everything seems to be OK.
Byte order mark @Some programmer dude
DUMMY,0000000000000100100000000000000000
^^^
Instead of editing/saving the file as UTF-8
, save the text file as a raw ASCII file.
Other possibility involves using an implementation specific fopen()
- yet some OP code would help to explore that.
See also
How to Read/Write UTF8 text files in C?
,
C how to skip BOM when checking if x is at the start of a file,
Is it possible to prevent adding BOM to output UTF-8 file? (Visual Studio 2005)
.