Jan/080
Line Endings
Yesterday when I was coding my 2D graphics engine’s sprite scripting system I came a cross with a problem with line endings.
The thing with line problems is that there is at least 3 different line ending styles : Window(CRLF), Unix(LF) and Mac(CR).
- CR = Carriage return (0×0D, 13)
- LF = Line Feed (0×0A, 10)
Now why does these produce problems?
Well first of all, if you aren’t able to detect when your line ends it is a problem. Another thing is that for example strlen returns the amount of characters before the line end, what if there isn’t one? Disaster.
These values (0×0D, 0×0A) may correspond to characters in the execution character set, and can be represented some other way (such as ‘\r’ or ‘\n’, for example), but this is implementation-dependent.
How does it happen?
- When you write lines to file without putting the end of line in there.
- When you read lines from a file that has a different line ending than what you use.
So be careful when writing those scripts.
Enjoy this article?
No comments yet.
Leave a comment
No trackbacks yet.