Re: atoi return




"Keith Thompson" <kst-u@xxxxxxx> wrote in message
news:ln4p3lm0yy.fsf@xxxxxxxxxxxxxxxxxx


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;
}

I can't really read that Keith but if I remember right this was
mentioned before but never really explained. I would've tried something
like this if it's even valid.
....
int i;
if (i=atoi(argv[1]))!=sizeof(int))
fprintf(stderr,"error\n");

*sigh* I dunno. Does this make any sense?

Bill



.



Relevant Pages

  • Re: Meaning of unsigned char
    ... const unsigned long int i = 5; ... I would say virtually "ALL" programmers would agree with Keith... ...
    (comp.lang.c)
  • Table design teaser
    ... A staff member may send a message to a customer or another staff member ... CUSTOMER (ID int pk, Name varchar(50)) ... MESSAGE, FromID int, ToID int) ... 101, message from kenneth to keith, 102, 101 ...
    (microsoft.public.sqlserver.server)
  • Re: 1 byte for character
    ... Keith just states ... Character *constants* are of type ... int, but objects of type char are of type char (which is ... an integer type), which I think is more relevant to what the OP was ...
    (comp.lang.c)
  • Re: sqrt Behaving Unexpectedly --- Short Program Example
    ... Keith wrote: ... > int main{ ... > Thanks for any reasons why this occurs. ... calculations differ in one or two bits. ...
    (comp.lang.c)
  • Re: Linux oddity
    ... Keith S. wrote: ... > When converting a double to an int, ... > I'd expect on Linux: ... > The above code prints 480 on SunOS and Windows, ...
    (comp.lang.cpp)