CAPL Script

Strtol

This reference collection includes Vector documentation reproduced with permission. Snippets may require configuration-specific symbols and are not all standalone programs. Sources and validation limits.

Syntax

int strtol(char s[], long& result);

int strtol(char s[], dword startIndex, long& result);

Function

Converts the stringsto a 32bit integer.The number base is Whitespace (spaces or tabs) at the start of the string is ignored.

Parameters

s String to be converted.

result Contains the converted value after the call. The value is 0 if the string can’t be converted to a number. It is the largest possible positive/negative number in case of overflow.

startIndex Position in s where the conversion shall begin.

Return Values

-2: Ifsis empty orstartIndexis larger thanstrlen(s).

-1: An overflow occurs.

Otherwise, returns the index of the first character after the number.

Reference example from the CANoe 12 help. Check the required configuration, database objects and API availability in your installed version; this is not a recorded compiler or runtime test.

char s[20] = "123 0xFF";
long number1, number2;
int res;
res = strtol(s, number1);
write("number1: %d, res: %d", number1, res); // output: number1: 123, res: 3
res = strtol(s, res, number2);
write("number2: %d, res: %d", number2, res); // output: number2: 255, res: 8