How to read input until the user enters ^X
I am creating an interpreter for my esolang, and I need the user to enter some text which then will be interpreted as an INTERCAL program. I want the user to enter text, which may contain any character including newlines, until the user presses ^X (Ctrl-X), like this:
Enter your code followed by ^X:
Bla
Blabl开发者_高级运维abla
Bla^X
Thank you for entering your code
(line 2, 3 and 4 were entered by the user)
can anyone explain me how I can read input including newlines till the user enters ^X? Thanks
^X has ASCII code 24, try checking for that.
http://www.unix-manuals.com/refs/misc/ascii-table.html
It would be better to ask the user to use ^D.
On most systems this produces the EOF character and causes the stream to close.
Thus you do not need to do anything special.
You just read until the end of the input stream. Thus your code can be exactly the same for reading standard input and for reading from a file.
精彩评论