Re: how can we check to not enter the any string or char?



Flash Gordon wrote:
CBFalconer wrote, On 01/11/07 16:12:

.... snip ...

if (((UINT_MAX - ch) / 10) > value) {

This is meant to be a bounded input, pass in and test against the bounds
allowed rather than some other value.

No, this is intended to ensure the value fits into an unsigned int.


/* overflow detected, decide what to do */
ch = ch + '0'; /* restore char value */
break;
}
value = 10 * value + ch;
}
ungetc(ch, f); /* keep exit char for the user */
return err;
} /* untested - you check it out */

Still untested by me.

.... snip ...

Of course, you have just done most of this chaps homework.

No I haven't. The function is incomplete. Nobody seems to notice
that it doesn't bother to return value, as it should, and that err
should be a further parameter (*err). What I have done is
encourage him to develop a standard reusable input mechanism, whose
value can be checked by the caller, and which doesn't require
(possibly) long strings etc.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>



--
Posted via a free Usenet account from http://www.teranews.com

.



Relevant Pages