STRTOL()

 

语句:

result=strtol(nptr,& endptr, base)

 

参数:

nptr and endptr are strings and base is an integer

 

返回值:

result is a signed long int.

returns the converted value in result , if any. If no conversion could be performed, zero is returned.

 

功能:

The strtol function converts the initial portion of the string pointed to by nptr to a signed long int representation in some radix determined by the value of base. The part of the string after conversion is stored in the object pointed to endptr, provided that endptr is not a null pointer. If nptr is empty  or does not have the expected form, no conversion is performed and the value of nptr is stored in the object pointed to by endptr, provided endptr is not a null pointer.

 

有效性:

所有单片机

 

要求

STDLIB.H must be included

 

范例:

signed long result;

char str[2]="123hello";

char *ptr;

result=strtol(str,&ptr,10);

//result is 123 and ptr is "hello"

 

范例文件:

 

参见: 

strtod(), strtoul()