Richard said:
Eric Sosman said:
Richard Bos wrote:
Using scanf, is it possible to detect input numbers where the
decimal count is too large?
scanf("%19lg",&var);
(and if
1.123456789101212314515324234132132
was put in, it would return a certain error value?
No. It would read as many digits as it needed, and leave the
input stream at that point. A subsequent read would get the
next digit. [...]
Sounds like a broken implementation, because it would
mis-convert
1.12345678910111213141516171819202122232425262e-10
... if it didn't read all the way up to (and through) the
exponent.
All the same, this is how Dev-C++ does it; how Pelles C does
it; and how DJGPP does it.
Can't speak for the first two, but the (rather old) DJGPP
version I have reacts in one of two ways:
- For inputs of up to 63 characters, scanf() with "%lf" or
"%lg" swallows all the digits and correctly converts a
trailing exponent; it does not stop in the middle of a
digit stream after converting "enough" input. A subsequent
getchar() returns whatever follows the number, not an
"insignificant digit."
- For longer inputs, scanf() crashes with a SIGSEGV.
Neither behavior seems to match your description ...