From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 31 Oct 92 06:34:42 GMT From: munnari.oz.au!yoyo.aarnet.edu.au!news.adelaide.edu.au!cs.adelaide.edu.au! andrewd@tcgould.tn.cornell.edu (Andrew Dunstan) Subject: Re: DATA_ERROR exception problem Message-ID: <1ct9e2INNajk@huon.itd.adelaide.edu.au> List-Id: In article , weberwu@inf.fu-berlin.de (Debora Weber- Wulff) writes: |> [Now that we have the umlauts sorted out, the next problem!] |> |> I want to write a compeletly safe input procedure for integers: |> I GET an integer, and if DATA_ERROR is raised, I want to loop |> around until I get a decent answer. |> |> My problem is that DATA_ERROR is raised on two different conditions: |> an integer being illegal, i.e. out of bounds, or an illegal |> character being encountered (such as when I enter "1.0" or "z"). |> The problem ist that in the former case, the input buffer has been |> emptied (all digits read); in the latter, the illegal character |> (and all following characters) remain in the input buffer. |> How can I differentiate the two cases, so that I can |> GET_LINE (input_garbage, input_garbage_size) and reprompt for input? |> I don't quite understand this. If you want to get an integer, and the input is "1.0", you should get (at least I get) 1 returned and ".0" left on the input. However, I think the easiest answer to your question is to read the input into a string and then do a get from the string. If the whole string is not used up by the get, you have got some garbage, and you can handle the situation as you wish. -- ####################################################################### # Andrew Dunstan # There's nothing good or bad # # Department of Computer Science # but thinking makes it so. # # University of Adelaide # # # South Australia # - Shakespeare # # net: andrewd@cs.adelaide.edu.au # # #######################################################################