Keil Logo

Technical Support

On-Line Manuals

C166 User's Guide

C166 Introduction Compiling Programs Language Extensions Preprocessor Advanced Programming Error Messages Library Reference Library Files Source Code Standard Types jmp_buf ptrdiff_t size_t va_list wchar_t Macros HARRAY HVAR MARRAY MVAR XARRAY XVAR Routines By Category Buffer Manipulation Routines Character Routines Data Conversion Routines Intrinsic Routines Math Routines Memory Allocation Routines Stream I/O Routines String Routines Variable Length Argument Routines Miscellaneous Routines Include Files SFR Definitions absacc.h assert.h ctype.h float.h intrins.h limits.h math.h membox.h setjmp.h stdarg.h stddef.h stdio.h stdlib.h string.h Reference _alloc_boxf _alloc_boxh _alloc_boxn _atomic_ _bfld_ _calloc_boxf _calloc_boxh _calloc_boxn _chkdouble_ _chkfloat_ _crol_ _cror_ _diswdt_ _einit_ _endatomic_ _free_boxf _free_boxh _free_boxn _getkey _idle_ _init_boxf _init_boxh _init_boxn _irol_ _iror_ _lrol_ _lror_ _nop_ _pop_ _prior_ _priord_ _push_ _pwrdn_ _sof_ _srvwdt_ _testclear_ _testset_ _tolower _toupper _trap_ abs acos asin assert atan atan2 atof atoi atol calloc calloc_b ceil cos cosh exp fabs floor fmemccpy fmemchr fmemcmp fmemcpy fmemmove fmemset fmod free free_b fstrcat fstrchr fstrcmp fstrcpy fstrcspn fstrlen fstrncat fstrncmp fstrncpy fstrpbrk fstrpos fstrrchr fstrrpbrk fstrrpos fstrspn getchar gets hmemcmp hmemcpy hstrcmp hstrcpy init_mempool init_mempool_b isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit labs log log10 longjmp malloc malloc_b memccpy memchr memcmp memcpy memmove memset modf offsetof pow printf putchar puts rand realloc realloc_b scanf setjmp sin sinh sprintf sqrt srand sscanf strcat strchr strcmp strcpy strcspn strlen strncat strncmp strncpy strpbrk strpos strrchr strrpbrk strrpos strspn strstr strtod strtol strtoul tan tanh toascii toint tolower toupper ungetchar va_arg va_end va_start vprintf vsprintf xcalloc xfree xinit_mempool xmalloc xmemccpy xmemchr xmemcmp xmemcpy xmemmove xmemset xrealloc xstrcmp xstrcpy xstrlen xstrncpy Appendix


#include <stdlib.h>

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

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


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

#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.