| ARM Technical Support Knowledge Articles | |
Applies to: C166 C Compiler
Information in this article applies to:
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);
}
Article last edited on: 2005-10-20 07:44:50
Did you find this article helpful? Yes No
How can we improve this article?