简体   繁体   中英

Arduino - String Array with integer

In Arduino i need a simple array. The keys have to be a string and the values an integer. In PHP it would look like this:

$array["name"] = array(8,4);    
$array["second"] = array(1,6);

Is there any way to solve this with Arduino?

Array of struct would be better:

typedef struct keyAndValue_ {
    int key;
    char value[NAMELENMAX+1];
} keyAndValue_t;

keyAndValue_t myArray[] = {
   {123, "Bob"},
   {345, "Harry"}
};

for (int x = 0; x <= sizeof(myArray)/sizeof(myArray[0]); x++) {
    if (myID == myArray[x].key) {
        Serial.println(myArray[x].value);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM