invalid conversion from 'uint8_t* {aka unsigned char*}' to 'int' [-fpermissive]

I have this code from a RF receiver:

// Should be a message for us now
    uint8_t buf[RH_RF69_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

and I can use this in a if statement like this:

  if (strstr((char *)buf, "12")) {
      Serial.println("Received 12");

What I would like to do is put in a "int" to use later:

int number = buf; // This is where I get the error

How would I do that?
Thanks

Ad what would that magic number need to be?

Btw, len is not very useful because it will just be RH_RF69_MAX_MESSAGE_LEN

And you do know you don't compare the string but just look for something to be in the string? The string "cgfhjgfhj12vnxbbnjkg" will also return true. Or "16571278634547".

What I would like to do is put in a "int" to use later:

Put what in an int?

You can NOT convert a byte array to an int.

You could convert a string to an int. But, a string is a NULL terminated array of chars. You could NULL terminate your array of bytes, and cast it to a char pointer, making atoi() think it was a string.

  buf[len] = '\0'; // NULL terminate the array
   int val = atoi((char *)buf); // Convert the string to an int

Yeah, buf needs to be null terminated to use any str function otherwise it will just keep on going...

But I would not try to place the null char one place behind the array :stuck_out_tongue:

But I would not try to place the null char one place behind the array :stuck_out_tongue:

True, but the statement that actually assigns data to the buffer returns the number of characters assigned to the buffer, so using that value as an index is correct. Using len, which is assigned the length of the array, is not, unless len gets overwritten before the assignment of the NULL.

Thanks got it.