This is one of the ‘gotchas’ that can impact on people when they read files. The underlying commands for loading files in operating systems tend to offer two options:
Read in text mode
Read in binary mode
What text mode does is it will translate newline characters to the local operating system convention for newline characters. See IBM, DOS and Windows Newlines to understand why windows expresses newlines with \r\n
while the rest of then the Unix based world using uses\n
.
Here’s a code fragment which shows the problem on windows:
Expand | ||
---|---|---|
| ||
Take a careful look at how in the non binary mode the new line sequences are translated - |
Expand | ||
---|---|---|
| ||
Notice how when we read in text mode, the |
Expand | |||||
---|---|---|---|---|---|
| |||||
Don’t forget to import the FIL Library.
|