Keil Logo

strtoul

Summary
#include <stdlib.h>

unsigned long strtoul (
  const char *string,   /* string to convert */
  char **ptr,           /* ptr to subsequent characters */
  intbase);             /* number base for conversion */
Description

The strtoul function converts string into an unsigned long value. The input string is a sequence of characters that can be interpreted as an integer number. Whitespace characters at the beginning of string are skipped. An optional sign may precede the number.

The value of *ptr is set to point to the first character in string immediately following the converted part of string. If ptr is NULL, no value is assigned to *ptr. If no conversion is possible, *ptr is set to the value of string and the value 0 is returned by the strtol function.

If the base is zero, the syntax expected is similar to that of integer constants, which is formed by a succession of:

  • An optional prefix indicating octal ("0") or hexadecimal ("0x") base.
  • A sequence of decimal digits (if no base prefix was specified) or either octal or hexadecimal digits if a specific prefix is present.

The radix of the number is deduced from its format.

If the value of base is in the range 2-36, the number in string must consist of a non-zero sequence of letters and digits representing an integer in the specified base. The letters a-z (or A-Z) represent the values 10-36. Only those letters representing values less than the base are permitted. If the base is 16, the number may begin with 0x or 0X, which is ignored.

The strtol function requires string to have the following format:

whitespace〛 〚{+|-}〛 digits

Where

whitespace May be any whitespace characters.
digits May be one or more decimal digits (0-9).
Return Value

The strtoul function returns the integer value that is produced by interpreting the characters in string as a number. The value ULONG_MAX is returned in case of overflow.

See Also

atof, atoi, atol, strtod, strtol

Example
#include <stdlib.h>
#include <stdio.h> /* for printf */

void tst_strtoul (void) {
  unsigned long ul;
  char s [] = "12345AB next";
  char *p;

  ul = strtoul (s, &p, 16);
  printf ("strtoul(%s) = %lx\n", s, ul);

/* p points to " next" */
}
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.