Article View: comp.lang.modula2
Article #235(none)
From: "THE DOCTOR."
Date: Fri, 08 Sep 1989 13:09
Date: Fri, 08 Sep 1989 13:09
32 lines
2313 bytes
2313 bytes
>I have just started taking a class in modula-2 and on our first project I
>noticed a small quirk with CARDINAL and INTEGER numbers. When you are reading
>in a number from the keyboard it seems to work on all types of numbers and
>characters. In doing some further research I found that when a negative number
>was put into a CARDINAL field then it would return a 0 and the program would
>still keep going. When a decimal number such as 9.87 or a series of characters
>were entered then it would return a number between 2014 and 2020 and again it
>kept on running. I was trying my hardest to crash my program with invalid
>input and I couldn't do it no matter how hard I tried. Does anyone out there
>know why this was happening and how you can check to make sure that the number
>inputted is really a CARDINAL or INTEGER number and then have an error message
>register??
>This same problem happened to the whole class and no one knows why.
>Thanks in advance for any help that you can give.
>Ann Schwab
Ann,
The style in Modula is not to dump a program on such an input error, but to
leave some sort of indication that the input was not correct. This way, the
program can take some corrective action like prompting, "Try it again, dummy."
There is usually some variable, like 'IOCheck' exported from the library
module which indicates the success or failure of the input operation. Since
this is a feature of the library module, I can only guess since you did not
say what compiler you are using. I use TopSpeed, and the variable OK is set
to FALSE if the input string was not valid for the type being read.
I hope this helps,
Tom Ruby
MSRS002@ECNCDC
Technical Details
Message-ID:
<INFO-M2%89090809334574@UCF1VM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ECNCDC.BITNET!MSRS002Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!ECNCDC.BITNET!MSRS002
From: MSRS002@ECNCDC.BITNET ("THE DOCTOR.")
Newsgroups: comp.lang.modula2
Subject: (none)
Message-ID: <INFO-M2%89090809334574@UCF1VM>
Date: 8 Sep 89 13:09:00 GMT
Sender: daemon@ucbvax.BERKELEY.EDU
Reply-To: Modula2 List <INFO-M2%UCF1VM.bitnet@jade.berkeley.edu>
Organization: The Internet
Lines: 32