appending to uint8_t

Greetings all,

I'm working on a charitable project and have the following causing me to want to rip my hair out!

uint8_t data[] = "zzz";

What I need to do is append "xxxx" to the end of the "zzz"

Further to this Im looking for a very short simple method of accessing the content by means of an index.

For example:

data[1] needs to return a "z"

and data[4] needs to return a "x"

A solution would help me greatly,

Kind Regards

What I need to do is append "xxxx" to the end of the "zzz"

You can not do that. The array data is sized to hold exactly three bytes.

You could:
uint8_t data[20] = "zzz";
...
strcat((cahr *)data, "xxxx");
...

PaulS-
The array is actually 4 bytes (with room for the '\0') but your point is the same.

I was just saying that if you create a string array and let the compiler set the size by providing no size in the [] brackets, it creates a string with the trailing nul, not the exact size of the characters, unless you do this:

char array[3] = "zzz";

which creates a string without the trailing nul.

You asked about indexing, it's easy. You just do this: data[index], where index is a variable.

unless you do this:

char array[3] = "zzz";

which creates a string without the trailing nul.

Actually, it doesn't. What is DOES is this:

sketch_apr16a:1: error: initializer-string for array of chars is too long

C allows you to omit the null terminator in a string initializer like that, but C++ does not.

DRSolomon:
For example:

data[1] needs to return a "z"

and data[4] needs to return a "x"

An array index starts at 0.