Strtol and arrays

Trying get my head around stuff ..

This is taken from some software I’m trying to work through for my OBD2 project .....If I have a ( hex) character array:

Char X = “ 10FF3212”;

And to get a long number from it using strtol I use a pointer thus :

Long Y = Strtol( &X[3], 0,16)

Then I thought it would only use the contents of X[3] . Is that the case of does it still use all the remaining string from X[3] ? I’m trying to understand the use of “& “ in this context.

Thx .

The first argument for strtol is a pointer to the string. Since the pointer is the address of x[3] then strtol only converts F3212 to a long.

char x[] = "10FF3212";
long y = strtol(&x[3], 0,16);

&X[3] is an address (pointer) of X's fourth element.

  int intVar;
  int* pointerToIntVar = &intVar;

Thx for that . It was what my test showed but disagreed with a Sparkfun example provided with their board.

Trying to add Karma but no button showing !!

I have no idea about Sparkfun example but function strtol(ptr, 0,16); will convert string starting from provided pointer till it find non HEX symbol. BTW is Strl() you mentioned at your first post really started with capital 'S' or it's a typo?

X is a null terminated string. So if you start reading it from some character in the middle, it "sees" that character, and all characters after that, until the terminating null is reached.