Struct 带变量字符数组的Arduino结构

Struct 带变量字符数组的Arduino结构,struct,arduino,Struct,Arduino,我尝试用变量字符数组填充struct对象,但它不起作用。 结果是随机符号 如果我在MyObject Temp中手动输入“naamBestand”,则会得到正确答案。我做错了什么 struct MyObject { char bestandsnaam[12]; int beginpositie; int lengte; }; void setup() { Serial.begin(9600); updateEEPROM(0, "test", 1, 1); } void lo

我尝试用变量字符数组填充struct对象,但它不起作用。 结果是随机符号

如果我在MyObject Temp中手动输入“naamBestand”,则会得到正确答案。我做错了什么

struct MyObject {
  char bestandsnaam[12];
  int beginpositie;
  int lengte;
};

void setup() {
  Serial.begin(9600);
  updateEEPROM(0, "test", 1, 1);
}

void loop() {
}

void updateEEPROM(int locatie, char naamBestand[12], int positieBestand, int lengteBestand) {
  MyObject temp {naamBestand, positieBestand , lengteBestand};
  Serial.println(temp.bestandsnaam);
  //EEPROM.put(locatie, temp);
}
解决方案

typedef struct MyObject {
  char bestandsnaam[12];
  int beginpositie;
  int lengte;
};MyObject customVar;

void setup() {
  Serial.begin(9600);
  updateEEPROM(0, "test", 1 , 2);
}

void loop() {
}

void updateEEPROM(int locatie, char naamBestand[12], int positieBestand, int lengteBestand) {
  strcpy(customVar.bestandsnaam, naamBestand);
  customVar.beginpositie = positieBestand;
  customVar.lengte = lengteBestand;
  Serial.println(customVar.bestandsnaam);
  //EEPROM.put(locatie, customVar);

如果您想将文本复制到成员
bestandsnaam
中,您必须这样做:
strcpy
我应该如何在updateeprom函数中这样做?谢谢,它成功了!我在这里找到了解决方案:()