views:

62

answers:

2

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

+1  A: 

^X has ASCII code 24, try checking for that.

http://www.unix-manuals.com/refs/misc/ascii-table.html

Christian Jonassen
So should I do something like a do-while loop which readS input character by character and checks if ^X is not entered?
Time Machine
Yes, that would work.
Christian Jonassen
+1  A: 

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.

Martin York
^D is not my question. Also, ^D is not in any way involved in HQ9+-ABC
Time Machine