Re: atoi return
- From: Keith Thompson <kst-u@xxxxxxx>
- Date: Thu, 09 Oct 2008 23:13:41 -0700
"Bill Cunningham" <nospam@xxxxxxxxxxxxx> writes:
I have just read atoi() returns no errors. It returns an int though and
the value of the int is supposed to be the value of the conversion. It seems
to me that right there tells you if there was success or not. Am I wrong?
Yes.
Take a look at the following program and tell me how you'd detect an
error in a call to atoi().
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *good = "0";
char *bad = "bad";
printf("atoi(\"%s\") = %d\n", good, atoi(good));
printf("atoi(\"%s\") = %d\n", bad, atoi(bad));
return 0;
}
--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
.
- Follow-Ups:
- Re: atoi return
- From: Bill Cunningham
- Re: atoi return
- References:
- atoi return
- From: Bill Cunningham
- atoi return
- Prev by Date: Re: thousands of request in one port per second
- Next by Date: Re: thousands of request in one port per second
- Previous by thread: Re: atoi return
- Next by thread: Re: atoi return
- Index(es):
Relevant Pages
|