strtold

strtol

#include <stdlib.h>long int strtol(const char *start, char **end, int radix);

The strtol( ) function converts the string representation of a number stored in the string pointed to by start into a long int and returns the result. The base of the number is determined by radix. If radix is zero, the base is determined by the rules that govern constant specification. If radix is other than zero, it must be in the range 2 through 36.

In C99, start and end are qualified by restrict.

The strtol( ) function works as follows. First, any whitespace in the string pointed to by start is stripped. Next, each character that comprises the number is read. Any character that cannot be part of a long integer number will cause this process to stop. This includes whitespace, punctuation, and characters. Finally, end is set to point to the remainder, if any, of the original string. This means that if strtol( ) is called with “ 100 Pliers”, the value 100L will be returned, and end will point to the space that precedes “Pliers”.

If the result cannot be represented by a long int, LONG_MAX or LONG_MIN is returned, and the global errno is set to ERANGE, indicating a range error. If start does not point to a number, no conversion takes place and zero is returned.

Related functions are atol( ) and strtoll( ).




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net