unsigned long  strtoul ( const char * string, char** endptr, int radix );

Convert string to unsigned long integer.
  Parses string interpreting its content as an integer value until a character that can not be interpreted is found, and returns an unsigned long value.


String representing an integer number. The number is considered until a non-numeric character is found (only the digits from 0 to radix-1 are considered valid numeric characters, signs are considered valid numeric characters for this parameter). The format used is:
(where whitespaces are any tab or space character and nnnnn is a sequence of valid numbers following the specified radix).
  Although the value returned is unsigned, signs in the string will be read and considered.
Address of a pointer. This is filled by the function with the address where scan has ended. Serves to determine where there is the first non-numerical character in the string.
Numeral radix in which the number to be interpreted. Must be 0 or be between 2 and 36. If it is 0 the radix of the string is determined by the initial characters of the string:
initial charsInterpreted by strol as
0xhexadecimal: radix 16
0octal: radix 8
any number from 1 to 9decimal: radix 10

Return Value.
  The converted unsigned long value from the input string.
  If conversion would cause overflow the result is ULONG_MAX.
  If an error occurs or no conversion can be made 0 is returned.

  Defined in ANSI-C.


/* strtoul example */
#include <stdio.h>
#include <stdlib.h>

main ()
  char szInput [256];
  char * pEnd;
  unsigned long ul;
  printf ("Enter an integer value: ");
  gets (szInput);
  ul = strtoul (szInput,&pEnd,0);
  printf ("Value entered: %lu. Its double: %lu\n",ul,ul*2);
  return 0;

See also.
  atof, strtol, strtoul

© The C++ Resources Network, 2000