ARM Technical Support Knowledge Articles

STRTOL LIBRARY ROUTINE

Applies to: C166 C Compiler

Answer


Information in this article applies to:


QUESTION

What does the strtol library routine do?

ANSWER

The strtol library routine converts the contents of a string to a 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>
long strtol (
  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_strtol (void)  {
  char buf [] = "  -123456 is a negative number";
  long neck;
  char *p;

  neck = strtol (buf, &p);
}

MORE INFORMATION

SEE ALSO

Article last edited on: 2005-10-20 07:44:19

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential