www.digitalmars.com         C & C++   DMDScript  

c++ - strtoul problem

reply "David Grimes" <dgrimes friberg.us> writes:
1.c:
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>

int main(int argc, char *argv[])
{
unsigned long number = strtoul(argv[1], 0, 10);

if (errno)
{
perror("Incorrect integer value");
return 1;
}

printf("number = %lu\n", number);
return 0;
}

dmc 1.c & 1 abc
number = 0

Function strtoul doesn't set errno if the conversion can not be performed.

David
Feb 15 2004
parent "David Grimes" <dgrimes friberg.us> writes:
This is the correct behaviour according to the standard. (There is an
erratum in the description of the function in my C book)

David

"David Grimes" <dgrimes friberg.us> wrote in message
news:c0p42c$2vfh$1 digitaldaemon.com...
 1.c:
 #include <stdio.h>
 #include <stdlib.h>
 #include <errno.h>

 int main(int argc, char *argv[])
 {
 unsigned long number = strtoul(argv[1], 0, 10);

 if (errno)
 {
 perror("Incorrect integer value");
 return 1;
 }

 printf("number = %lu\n", number);
 return 0;
 }

 dmc 1.c & 1 abc
 number = 0

 Function strtoul doesn't set errno if the conversion can not be performed.

 David
Feb 17 2004