Re: atoi return



"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"
.



Relevant Pages

  • Re: Problem with linker
    ... but to have actually written a default constructor. ... such as overloading on int and pointer types. ... conversion of 0 to CString requires a user-defined conversion, ... acceleration operator *(distance d, time_squared t2); ...
    (microsoft.public.vc.mfc)
  • Re: Interesting list Validity (True/False)
    ... TypeError: int argument required ... If the gmpy writers are not allowing the conversion, ... it raises an OverflowError and the "%d" formatting ...
    (comp.lang.python)
  • Re: [PATCH 1/2] Add function to convert between calendar time and broken-down time for universal
    ... convert time between calendar time and broken-down time. ... replace `int' with `unsigned int', ... needed of your email client is performing tab-to-space conversion. ... * Library General Public License for more details. ...
    (Linux-Kernel)
  • Re: Re: [PATCH 1/2] Add function to convert between calendar time and broken-down time for unive
    ... A example is my patch for fs/fat/misc.c. ... replace `int' with `unsigned int', ... needed of your email client is performing tab-to-space conversion. ... * Library General Public License for more details. ...
    (Linux-Kernel)
  • Re: if(a);
    ... The type of the octal signed int literal 0 will be compared to the ... 'a' has type unsigned int, in which case 0 is converted to ... is still 0 after undergoing conversion, ...
    (comp.lang.c)