assistance with unsigned char [251]}' to 'char [251]' error

Hi,

I'm trying to parse an in coming string for example '01:2.7:300:4'.

However, I am get an error

incompatible types in assignment of 'uint8_t [251] {aka unsigned char [251]}' to 'char [251]'

The error is believe is being cause by the line.

 stringToParse = sx1272.packet_received.data;

The type of sx1272.packet_received.data is uint8_t [251].

Could anybody help resolve?

Thanks

const char *delim  = ":";   //a comma is the delimiter
uint8_t stringToParse[251];

/*!
    Setup function
*/
void setup() {

Serial.begin(115200);

  // Power ON the module
  sx1272.ON();

}

//! Main application loop
void loop() {
  
  e = sx1272.receivePacketTimeout(10000);
  e = sx1272.getRSSIpacket();
 
  char *firstItem;
  char *secondItem;
  char *thirdItem;
  char *fourthItem;
  char *fifthItem;
  
  stringToParse = sx1272.packet_received.data;

  firstItem = strtok(stringToParse,delim);
  secondItem = strtok(NULL,delim);
  thirdItem = strtok(NULL,delim);
  fourthItem = strtok(NULL,delim);
  fifthItem = strtok(NULL,delim);
 
 
  Serial.print ("First item in string: ");
  Serial.println(firstItem);
  Serial.print ("Second item in string: ");
  Serial.println(secondItem);
  Serial.print ("Third item in string: ");
  Serial.println(thirdItem);
  Serial.print ("Fourth item in string: ");
  Serial.println(fourthItem);
  Serial.print ("Fifth item in string: ");
  Serial.println(fifthItem);
}

The error is believe is being cause by the line.

You can not assign the contents of one array to another array that way. You could use memcpy() to copy the contents of one array to another.

But why? There appears to be no reason not to parse sx1272.packet_received.data;.

Hi,

To be honest, I don't know how to parse it correctly.

I came across this example and tried to modify it. c - parse an array of string using strtok - Stack Overflow

Basically, I have the variable sx1272.packet_received.data which is of type uint8_t [251].

An example of it is '01:2.7:300:4'.

What I am trying to do is parse it by the colon and assign each number to variables of type char.

The reason I want to do this is because I have code to write those variables to a file.

Could you perhaps demonstrate how to parse it correctly?

Thanks

What I am trying to do is parse it by the colon and assign each number to variables of type char.

The reason I want to do this is because I have code to write those variables to a file.

In some other format?

The strtok() function can do the parsing. There are only 4 tokens, in "01:2.7:300:4", "01", "2.7", "300", and "4".