strncpy(ver, buffer2 +5,2);

Hi,
Can someone help me understand this code?
strncpy(job, buffer2,5);
strncpy(ver, buffer2 +5,2);

Thanks for all the help!

If we start with this:

char buffer2[]="abcdeFGH";
char job[6];
char ver[3];

then, strncpy(job, buffer2,5); will copy the first 5 characters of buffer2 into job, i.e. "abcde". It will NOT null-terminate it, though. strncpy doesn't NULL-terminate the destination string unless it actually finds the NULL terminator.

Note that buffer2 is an array, and adding an offset to an array moves you farther down that array. So buffer2+5 moves it 5 down, to the"FGH" part. So, strncpy(ver, buffer2 +5,2); will copy 2 characters of "FGH" into ver, but again, doesn't NULL terminate it because it didn't find the NULL terminator.