RE: DOS: A newbie question about get()

new topic     » goto parent     » topic index » view thread      » older message » newer message

Hi Alex,

What do you want to accomplish?  Do you want to check input per 
character as it's being typed?  Do you just want want to get a whole 
string of characters (without having to use quotes) and then check that 
it's valid?  prompt_string() might be what you're after but it's hard to 
say with the info you've provided.

Example:
----------
include get.e
sequence got

got = prompt_string( "Enter something here: " )
printf(1,"You entered \"%s\".\n",{got})
----------
-- Brian
----------

Alex Caracatsanis wrote:
> 
> 
> 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
> 
>

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu