#Add entry at the back of `usigned char *`

15 messages · Page 1 of 1 (latest)

queen grove
#

The title speaks for itself.

What I have tried:

unsigned char * loop_list = {};

for (int i = 0; i < size; i++)
{
    // add byte to list
    loop_list[i] = buffer[i];
}```
But that just glitches out.
ripe tartanBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

nimble parcel
#

You probably want to use a vector for this

#

You can’t do this because you cannot just add elements to an array, the size is fixed

#

If you really have to use pointer arrays for whatever reason, you have to reallocate when the elements surpassed the array size

#

But check out std::vector which handles it all for you

ripe tartanBOT
nimble parcel
#

Oh shoot I just saw the arduino tag

#

For arduino, I would just recommend stack allocating an array (with a large, fixed size) such as 128 or 512

#

If you know the max that size could be, you could set this array size to that maximum

#
unsigned char loop_list[128] = {};

…
#

For normal devices you might use malloc (for c) or vector, but arduino doesn’t support the c++ stl and malloc can lead to heap fragmentation so better safe than sorry

radiant cloud
#

Hi.

queen grove
#

!solved