Re: how can we check to not enter the any string or char?
- From: Flash Gordon <spam@xxxxxxxxxxxxxxxxxx>
- Date: Sat, 03 Nov 2007 23:45:20 +0000
CBFalconer wrote, On 01/11/07 23:47:
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.
Which is not the OPs requirement.
... snip .../* overflow detected, decide what to do */Still untested by me.
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 */
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.
I.e. you have done most of his homework by providing something close to a complete solution. I did NOT say you had done it all nor that I had fully reviewed your code.
--
Flash Gordon
.
- References:
- Re: how can we check to not enter the any string or char?
- From: andreyvul
- Re: how can we check to not enter the any string or char?
- From: Jack Klein
- Re: how can we check to not enter the any string or char?
- From: Philip Potter
- Re: how can we check to not enter the any string or char?
- From: santosh
- Re: how can we check to not enter the any string or char?
- From: emre esirik(hacettepe computer science and engineering)
- Re: how can we check to not enter the any string or char?
- From: CBFalconer
- Re: how can we check to not enter the any string or char?
- From: Flash Gordon
- Re: how can we check to not enter the any string or char?
- From: CBFalconer
- Re: how can we check to not enter the any string or char?
- Prev by Date: Re: Bug/Gross InEfficiency in HeathField's fgetline program
- Next by Date: Re: Meaning of memset (Was: Re: Assigning values to char arrays)
- Previous by thread: Re: how can we check to not enter the any string or char?
- Next by thread: Re: how can we check to not enter the any string or char?
- Index(es):
Relevant Pages
|