Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ Language Reference - strtoul http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
                                 strtoul

   Usage
   #include <stdlib.h>
   unsigned long int strtoul(const char *nptr, char **endptr,int base);

   Description
   Converts  the  ASCII  string pointed to by nptr  to  a  unsigned  long
   decimal.

   It  will  recognize white space then an optionally  signed  string  of
   digits.  It will stop reading the string at the first  character  that
   doesn't  represent a part of the number. A pointer to  that  character
   will be stored in the object endptr if endptr is not NULL.

   If  base  is  zero the first character after the  optional  sign  will
   determine the base of the conversion. If the first character is 0  and
   the second character is not 'x' or 'X', then the string is interpreted
   as octal. If the first character is 0 and the second character is  'x'
   or 'X' it will be interpreted as a hexadecimal integer.

   If  the  first  character is '1' - '9' the string  is  interpreted  as
   decimal  integer. The upper or lower case letters A - Z  are  assigned
   the values from 10 through 35. Only letters with values less than  the
   base  are permitted. If the base is not 0, the base must be between  2
   and 36.

   Return Value
   If correct values would cause overflow ULONG_MAX is returned according
   to  the sign and errno is set to ERANGE. If an unrecognized  character
   is encountered before a legal character, zero is returned.

   Example
   #include <stdio.h>
   #include <stdlib.h>
   char *string,*string2;
   main()
   {
   unsigned long result;
   long result1;
   double result2;
   int base;
        string = "3.1415926Stop here";
        result2 = strtod(string,&string2);
        printf("String [%s] strtod = [%f]\n",string,result2);

        base = 8;
        string = "1011013";
        result1 = strtol(string,&string2,base);
        printf("String [%s] strtol [%ld] (base 8)\n",string,result1);

        base = 2;
        string = "1011013";
        result = strtoul(string,&string2,base);
        printf("String [%s] strtoul [%ld] (base 2)\n",string,result);
   }


See Also: atoi atol strtol scanf

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson