Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>strtoul() convert string to an unsigned long decimal integer</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 strtoul()               Convert String to an Unsigned Long Decimal Integer

 #include   <stdlib.h>

 unsigned long  strtoul(nptr,endptr,base);
 const char     *nptr;                   Pointer to string
 char           **endptr;                Pointer to end of scan
 int            base;                    Number base to use

    strtoul() converts a string pointed to by 'nptr' to an unsigned
    long-integer value.  The string is a sequence of characters that can
    be interpreted as a long-integer value.  strtoul() stops reading the
    string at the first character that cannot be recognized as part of a
    long-integer value. 'endptr' points to the character that stopped the
    scan. This character could be the null character that terminated the
    string or the first numeric character greater than or equal to
    'base'.

    The string must match this sequence:

                  [whitespace] [sign] [0] [x] [digits]

    If 'base' is between 2 and 36, then 'base' is the base of the
    long-integer represented in 'nptr'.  If 'base' is 0, the first few
    characters of 'nptr' determine the base: If the first character is 0
    and the second character is '1'-'7', the value is an octal integer;
    if the first character is 0 and the second character is 'x' or 'X',
    the value is a hexadecimal integer; if the first character is '1'-
    '9', the value is a decimal integer.

       Returns:     The unsigned long value represented by the string.

   -------------------------------- Example ---------------------------------

    The following statements convert 'string' to an unsigned long
    integer.


           #include <stdlib.h>
           #include <stdio.h>

           main()
           {
               int bas2 = 2;
               int bas8 = 8;
               int bas16 = 16;
               char *string = "127750a03";
               unsigned long longint;
               char *termn;

               longint = strtoul(string,&termn,bas2);
               printf("%s (base %d) = %u\n",string,bas2,longint);

               longint = strtoul(string,&termn,bas8);
               printf("%s (base %d) = %u\n",string,bas8,longint);
           }



See Also: strtod() strtol() atof() atol()

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