Skip to main content

strtoll

Open topic with navigation CAPL Functions » General » Function Overview » strtoll

Function Syntax

int strtoll(char s[], int64& result); // from 1
int strtoll(char s[], dword startIndex, int64& result); // from 2

Description

Converts the string s to a 64bit integer. The number base is:
  • Hexadecimal if the string starts with ‘0x’
  • Octal if it starts with ‘0’
  • Decimal otherwise
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: If s is empty or startIndex is larger than strlen(s).
  • -1: An overflow occurs.
Otherwise, returns the index of the first character after the number.

Example

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