Let's break it down logically for you.
You have 4 strings, each capable of containing 96 characters:
static char buffer;
That is a block of RAM that covers 4*96=384 bytes. Let's say that block of ram starts at address 0x100.
result = (int)strtod(&buffer[bufindw][strchr_pointer - buffer[bufindw] + 1], NULL)
buffer[x] returns the address of the string number
x in your array of strings. It's the same as
&buffer[x] - the address of the first character in string x.
You also have a pointer
strchr_pointer which contains something - what that is I don't know because you haven't told us. Chances are it's the result of a
strchr() call, which:
returns a pointer to the first occurrence of the character c in the string s.
So you have looked for a character in a string and found that it's at a specific address. Let's say that's address 0x111 for the sake of argument.
Ok, so if we take
bufindw as 0 for the first string in your array, and work from the inside out, we have:
- buffer[bufindw] = 0x100
- strchr_pointer = 0x111
- strchr_pointer - buffer[bufindw] = 0x111 - 0x100 = 0x11
- strchr_pointer - buffer[bufindw] + 1 = 0x100 - 0x111 + 1 = 0x12
- Replace that into the function's parameters:
- &buffer[bufindw][strchr_pointer - buffer[bufindw] + 1] = &buffer[bufindw][0x12]
So you have the address of the 0x12'th (18th) character (or character number 16 since they count from 0 not 1), which is address 0x112.
That address is then passed to strtod() to convert it into a double-precision number:
That value is then cast to an integer:
So the decimal portion is discarded (not rounded, chopped off).
Say your string contains: "
This is the value:23.83589743" and is located at 0x100.
You use strchr() to find the first occurrence of ':', and it finds it at address 0x111, which is the 18th character of the string, so 0x100 + 17 = 256 + 17 = 273 = 0x111. You subtract the start of the string and add one to it, so you end up with 18, which is the start of the numeric value (the 18th character). The string from that point on contains "
23.83589743". That is then passed to
strtod() and cast to an integer, and so is truncated to
It's not surprising you're confused, the whole thing can be re-written much simpler:
strchr_pointer = strchr(buffer[bufdindw], ':');
result = (int)strtod(strchr_pointer, NULL);
All that manipulating of the buffer address is like doing "x = 6 + y - 3 + 4 - 7" - completely pointless, since you might just as well write "x = y".