# When accepting input from STDIN, can it be assumed to terminate with a newline [duplicate]

...or I guess more specifically, can I require that input from STDIN (or closest alternative, e.g. TIO) be newline terminated?

Utilising apps like TIO this isn't added, but if using a terminal with <<< a newline is appended, it can only be omitted using something like echo -n ... | script. I've definitely used either as it suits me, but I don't know if that's appropriate or not.

A specific example of this is my answer to this question which could save two bytes assuming a newline exists on the input, but would necessitate TIO having an explicit terminating newline.

## This has an answer in the I/O defaults

Thanks to @Bubbler for clarifying.

• I think this case is covered by this default I/O. In the challenge, newlines are guaranteed to not appear in the input string, so you can use it as the "sentinel" (which means the input will always be <input string><newline> for your program). Aug 2, 2022 at 22:59