1

topicArray defined as follows:

const char* msgTopic = "Home/Messages";
const char* groupTopic = "Home/All";
char* deviceName = deviceTopic;
const char* topicArry[2] = {deviceTopic, groupTopic};

But deviceTopic can be changed during code run, and I wish that topicArray containg deviceTopic will have the correct value after deviceTopic has changed.

What is the right way doing so ?

put on hold as off-topic by Juraj, sempaiscuba, per1234, MatsK, gre_gor Jan 12 at 21:44

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question does not appear to be about Arduino, within the scope defined in the help center." – Juraj, sempaiscuba, per1234, MatsK, gre_gor
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    don't make the array 'constant' with const and you can change the values (pointers) it contains – Juraj Jan 11 at 20:00
  • @Juraj I did remove const ouf of array and all other variable, but still array is not changed – Guy . D Jan 11 at 20:03
  • do you change it? – Juraj Jan 11 at 20:23
  • as said " I did remove const" – Guy . D Jan 11 at 20:24
  • to be able to set the value topicArray[0] = "something" – Juraj Jan 11 at 20:26
3

You may try something like this:

const char* topicArry[2] = {NULL, groupTopic};
const char** const pDeviceTopic = &topicArry[0];
#define deviceTopic (*pDeviceTopic)

Arguably not very elegant, but now when you assign, e.g.

deviceTopic = msgTopic;

you are actually writing into topicArry[0].

Not the answer you're looking for? Browse other questions tagged or ask your own question.