copying a buffer from a specific location

Hi.
I already wrote:
strncpy(buff2, buff1[i], strlen(buff1)-i );
but this function seem to just copy from the beginning of a buffer to another, not from the ith element.Is there such a function?

Buff1&buff2 are char[10000] and i is declared int, holding the interesting element's position.
Last edited on
That expression should give you an error like: error: invalid conversion from 'char' to 'const char*'

You may write it like so:
strncpy(buff2, buff1 + i, strlen(buff1)-i );
Note that the terminating 0 is omitted

Or so:
strcpy(buff2, buff1 + i);
Why is it that your expression doesn't give the mentioned error?
Because buff[i] is the i-th element of buff, whereas buff + i is a pointer to the i-th element of buff.
The buff[i] is same as writing *( buff + i ), which is different from buff + i.
Topic archived. No new replies allowed.