I am using this part of c code in carbide c/c++
char c1[]={0x01};
char c2[]={0x02};
char* c [] = {c1,c2};
when i check values of c[0],c[1].. i am seeing two values like this in debug mode
c[0] = \x01\x01 & (x) = *[0] = \x01
c[1] = \x02\x01\x01 & (x) = *[1] = \x02
and if i calculate length like this
int cclen2 = strlen(c[0]);
getting cclen2 = 2; but i should get values as 1.
c1
andc2
do not have null terminators, andstrlen()
requires a null terminator (along with many other C string handling functions, likeprintf("%s", c1)
for example). A null terminator is only implicitly added when a string literal is used to initialise thechar[]
.Change to either:
or: