Keil Logo


Information in this article applies to:

  • C166 Version 4.06


What does the strtoul library routine do?


The strtoul library routine converts the contents of a string to an unsigned long. Leading whitespace is ignored. A base may be specified. If the base specified is between 2 and 36, the conversion is performed in that base. If the base specified is zero, the prefix of the value stored in the string determines the base of the conversion: 0 implies an octal value and 0x or 0X implies a hexadecimal value.

This function is declared as follows:

#include <stdlib.h>
unsigned long strtoul (
  const char *string,  /* string to convert */
  char *endp,  /* ptr to unconverted text */
  int base);  /* the base to convert from */

A pointer to the first character in string that can't be converted is stored in endp unless endp is NULL.

For example:

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

void tst_strtoul (void)  {
  char buf [] = "123456 is a positive number";
  long neck;
  char *p;

  neck = strtoul (buf, &p);


  • Refer to strtoul in the C166 User's Guide.


Last Reviewed: Thursday, October 20, 2005

Did this article provide the answer you needed?
Not Sure
  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.