Re: atoi return
- From: "Bill Cunningham" <nospam@xxxxxxxxxxxxx>
- Date: Fri, 10 Oct 2008 21:37:40 -0400
"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:ln1vyokqw1.fsf@xxxxxxxxxxxxxxxxxx
[snip]
Here's the point. If you give atoi() a string that doesn't represent
a number, such as the string "bad", it returns 0. If you give it the
string "0", which does represent a number it returns 0. If atoi()
returns 0, you *can't tell* whether it successfully converted the
string "0" or failed to convert the string "bad".
Even worse, if atoi() is given a string that represents a number
that's too big to hold in an int, it invokes undefined behavior. For
example, there's no telling what atoi("99999999999999999999") will do;
it could crash your program or worse.
I see. Must be a left over dinosaur like gets().
Bill
.
- Follow-Ups:
- Re: atoi return
- From: CBFalconer
- Re: atoi return
- From: Keith Thompson
- Re: atoi return
- References:
- atoi return
- From: Bill Cunningham
- Re: atoi return
- From: Keith Thompson
- Re: atoi return
- From: Bill Cunningham
- Re: atoi return
- From: Keith Thompson
- atoi return
- Prev by Date: Re: Returning a struct from a function - strange behavior
- Next by Date: Re: help on relational operators
- Previous by thread: Re: atoi return
- Next by thread: Re: atoi return
- Index(es):
Relevant Pages
|