This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to Split Array value Which send Phone

Hi everyone 

I want to sperate array data. For example phone send sifre[4] = {0x00, 0x01, 0x02, 0x03} and seperate my board 

Fullscreen
1
2
3
static const uint16_t sifre[4] = {0x00, 0x01, 0x02, 0x03};
if(led_state == sifre[4])
bsp_board_led_on(LED_2)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

how can i do it?

Parents
  • This doesn't make much sense. 

    Do you actually want to check led_state against your sifre array? Where does the data array come from? What kind of data type is led_state? If by data[4] you mean sifre[4], then sifre[4] is outside your data array's boundaries. You need to check sifre[3] to get the fourth byte in the array. 

Reply
  • This doesn't make much sense. 

    Do you actually want to check led_state against your sifre array? Where does the data array come from? What kind of data type is led_state? If by data[4] you mean sifre[4], then sifre[4] is outside your data array's boundaries. You need to check sifre[3] to get the fourth byte in the array. 

Children
  • Thanks Martin,

    I want to send a password to the development card from the mobile phone. for example, "1,2,3,4" if the incoming "1,2,3,4" is led_state on. how can i do it?

  • If you simply want to compare two arrays you can do it like suggested here for example: C program to compare two arrays.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    bool compareArray(uint8_t a[], uint8_t b[], uint8_t size)
    {
    for(uint8_t i = 0; i < size; i++)
    {
    if(a[i]!=b[i])
    {
    return false;
    }
    }
    return true;
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX