3 ms·
Technically, that is one of two possible interpretations, and you seem to have invented a "by definition" out of thin air. Very very technically a "newline" ch
by rerdavies 3y ago
Technically, that is one of two possible interpretations, and you seem to have invented a "by definition" out of thin air.
Very very technically a "newline" character indicates the start of a new line, which is why it is not called the "end-of-line" character.
- cortesoft 3y agoI mean, the person you are responding to didn't invent the definition out of thin air... the POSIX standard did: 3.206 Line A sequence of zero or more non- <newline> characters plus a terminating <newline> character. https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/ https://pubs.opengroup.org/onlinepubs/9699919799.2018edition...
- pepa65 3y agoHow about a null-byte then? That's not a newline character, but all POSIX tools will treat it as EOF.
- pepa65 3y agoSo this is what "3.403 Text File" says: A file that contains characters organized into zero or more lines [so characters with no newlines are OK] No NUL, and lines (delimited by and including newline) not exceeding LINE_MAX bytes.
- nomel 3y agoPosix getline() includes EOF as a line terminator: getline() reads an entire line from stream, storing the address of the buffer containing the text into *lineptr. The buffer is null-terminated and includes the newline character, if one was found. ... ... a delimiter character is not added if one was not present in the input before end of file was reached. EOF seems same as end-of-string.
- lsaferite 3y agoYour quoted documentation says otherwise. It says that a 'line' include the delimiter, '\n', in the line buffer. It also says that is no delimiter is found before the EOF is reached that the line buffer will not include the delimiter. That means the line buffer can clearly indicate an incomplete line by the absence of the delimiter. To be clear, EOF isn't a 'line terminator', it's the end of the data stream.
- mabster 3y agoI don't know why no-one here sees this as a bad design... If a line is missing a newline then we just disregard it?! A way better way to deal with newline is it's a separator like comma. And like in modern languages we allow a final separator, but ignore it so that is easier for tools to generate files. Now all combinations of characters, including newline characters, has an interpretation without dropping anything.
- danbruc 3y agoI also always preferred the interpretation of a newline as a separator instead of as a terminator for files because I never liked the final newline causing a new empty line in the editor and as you thought that it was bad design that you can have a somewhat invalid file. But if you look beyond files, the interpretation as a terminator also makes perfect sense, when you receive text over a serial connection it signals that the line is complete which does not necessarily imply that another line will follow. The same in a file, if the terminating newline is missing, you can deduce that an incomplete write occurred and some data might be missing. If you decide to have a newline as a separator after the last line but to ignore it, then you can not represent an empty last line. I guess you would need two different characters, one terminator and one separator. You could start a line with \n and end it with \r. The \n separates the line from the one before, then \r terminates the line and marks it as complete. You would get \r\n between lines as on Windows and the last line would only have \r if complete or would otherwise count as incomplete. Then again you could almost get the same thing with \n only, you would just have to change the interpretation, instead of \n giving you a line and no \n giving you not a line, you would have to say that \n gives you a complete line and no \n gives you an incomplete line. With that you could however not have an incomplete empty line.
- pepa65 3y agoThis effort of building in redundancy is pointless. We just need a newline to know where to start the output on a new line. If you want to safeguard the proper content of a file, a whole lot more is needed.
- LK5ZJwMwgBbHuVI 3y agoIt doesn't indicate the start of a new line, or files would start with it. Files end with it, which is why it is a line terminator. And it is by definition: by the standard, by the way cat and/or your shell and/or your terminal work together, and by the way standard utilities like `wc` treat the file.