简体   繁体   中英

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
Blablabla
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM