Below is my code in c++
//The data below r fixed ie the data to be uploaded in the buffer is in this format :KL10<nnnnnn><ssss>
KL (is the ID) , 10 (the total length of n and s), n(6 digit integer), s(4 digit serial no)
case 1:
char InBuffer[64];
BOOL flag=0;
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);
case 2:
char InBuffer[64];
BOOL flag=1;
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);
memcpy(&InBuffer[4],"123456",6);
memcpy(InBuffer[10],"0987",4);
Now, i want to get the length of the buffer now.
I used strlen(InBuffer) and it returned me 21 instead of 14 for case 2:
i want a new line exactly in the 14th offset
ie InBuffer[14] = 0x0A;
so now including the new line i want the len of buffer has 15. I want this len value for further calculation.
But why I am getting 21 as strlen(InBuffer)? Where is my mistake?
char InBuffer[64];
memset(InBuffer,0,64);
memcpy(InBuffer,"KL10",4);
memcpy(&InBuffer[4],"123456",6);
memcpy(InBuffer[10],"0987",4);
InBuffer[14] = 0x0A;
memcpy(&InBuffer[15],"\0",1);
BOOL flag=1;
//When i give
int dlen = strlen(InBuffer);
InBuffer[dlen] = 0x0A;
( the new line in added exactly in the 4th offset for case 1 but the same fails for case 2 )
(so i introd boolean var, which will bypass InBuffer[dlen] = 0x0A for case 2 since have already added the 0A and \0)
if (flag==1)
//i hardcode the buffer length as 15.
Looking for solution that will return the exact length of buffer for case 2.
Thanks.
Anu