> How strlen() is working ?
strlen() works by finding a \0 character
> unsigned char xx[2] = "ab";
This does NOT have a \0 character, so strlen() just wanders through memory until it finds one, or the OS steps in and kills your program.
unsigned char xx[3] = "ab";
is what you need as a minimum
unsigned char xx[30] = "ab";
initialises the first 2 chars to ab, and the other 28 to \0
unsigned char xx[] = "ab";
reserves just enough space for the string, and a \0
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.