-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]

tadman
  • 208,517
  • 23
  • 234
  • 262
fpp
  • 31
  • 4
  • 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`](https://stackoverflow.com/questions/4668760/converting-an-int-to-stdstring)? – tadman Oct 01 '22 at 23:38
  • `itoa(LoRa.packetRssi(), (char*)&nodeReceivedData[packetSize+1], 10);` – Igor Tandetnik Oct 02 '22 at 00:19

1 Answers1

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);
Pain67
  • 326
  • 1
  • 9