Character array conversion to an integral value of type long int.
Compatibility:This function is compatible with the following targets:
|
|
long int strtol(const char *nptr,  
char **endptr, int base);
Parameters for this facility are:
This function skips leading white space.
This function sets the global variable errno to ERANGE if there is a conversion error.
#include <stdlib.h>
#include <stdio.h>
int main(void)
{
long int i;
unsigned long int j;
long long int lli;
unsigned long long ull;
static char si[] = "4733 777";
static char sb[] = "0x10*****";
static char sc[] = "66E00M???";
static char sd[] = "Q0N50M abcd";
char *endptr;
i = strtol(si, &endptr, 10);
printf("%ld remainder of string = |%s|\n", i, endptr);
i = strtol(si, &endptr, 8);
printf("%ld remainder of string = |%s|\n", i, endptr);
j = strtoul(sb, &endptr, 0);
printf("%lu remainder of string = |%s|\n", j, endptr);
j = strtoul(sb, &endptr, 16);
printf("%lu remainder of string = |%s|\n", j, endptr);
lli = strtoll(sc, &endptr, 36);
printf("%lld remainder of string = |%s|\n", lli, endptr);
ull = strtoull(sd, &endptr, 27);
printf("%llu remainder of string = |%s|\n", ull, endptr);
return 0;
}
Output:
4733 remainder of string = | 777|
2523 remainder of string = | 777|
16 remainder of string = |*****|
16 remainder of string = |*****|
373527958 remainder of string = |???|
373527958 remainder of string = | abcd|
[ First ] [ Previous ] [ Next ] [ Last ] [ Manuals ]
Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.
Last updated: August 16, 2000