DOS: A newbie question about get()
I have a beginner's question about get(0).
I tried to use get(0) to read and check user input from the keyboard,
and I anticipated that if it returned {GET_FAIL, 0}, then it would be a
simple matter for the program to loop and ask the user to input a new
value. I was surprised to find that if the user entered, say, bad
(instead of "bad") then the program automatically looped 3 times - once
for each character - and I couldn't find a way to make it loop only the
once.
Is it possible to get around this behaviour in a simple way? Secondly,
am I perhaps using the wrong tool for the job (of reading and checking
keyboard input) - maybe gets() or getc() etc would be better?
Here's what I did....
include get.e
sequence got
while 1 do
puts(1, "\nEnter something here (enclose words in \" \"): ")
got = get(0)
if got[1] = 1 then
puts(1, "\nInvalid entry - try again")
elsif got[1] = -1 then
puts(1, "\nEOF reached before read - try again")
else
puts(1, "\nValid entry - get() returned ") print(1, got)
exit
end if
end while
Thank you
Alex Caracatsanis
|
Not Categorized, Please Help
|
|