-1

Title is a bit messy, but i dont know how to simplify it. This is what i want to do:

nodeReceivedData[packetSize+1] = itoa(LoRa.packetRssi(), [output], 10);
                                   

itoa() always asks for a input variable, output variable and a size modifier. What I want to do, is to avoid having to make a temporary variable to then assign it's value to the actual variable I want that data to be. Is there something that can do this?

I also tried:

itoa(LoRa.packetRssi(), &nodeReceivedData[packetSize+1], 10);

but since nodeReceivedData is a byte type variable, itoa() won't accept it.

Extra info:

int LoRaClass::packetRssi()

byte nodeReceivedData[50]

2
  • What is itoa doing in C++ code? It's not even standard in C. What is the objective here? Why not convert to std::string? Commented Oct 1, 2022 at 23:38
  • itoa(LoRa.packetRssi(), (char*)&nodeReceivedData[packetSize+1], 10); Commented Oct 2, 2022 at 0:19

1 Answer 1

1

Since "itoa" expects the 2nd argument to be "char*" and 'nodeReceivedData' is byte (assuming it is just an "unsigned char"), you can just cast it to a char* and should work as expected:

itoa(LoRa.packetRssi(), (char*)&nodeReceivedData[packetSize+1], 10);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.