struct {char symbol; byte count;} input[] = {
{'a', 2}, {'X' ,3} ,{'!', 1}
};
const byte inputcount = sizeof(input)/sizeof(input[0]); // 3 in this test
char expanded[20]; // will get the result
void setup() {
Serial.begin(9600);
char* resultpos = expanded;
for (auto& elem:input) {
for (byte p = 0; p < elem.count; p++) {
*resultpos++ = elem.symbol;
}
}
*resultpos = 0; // to make it a printable char array
Serial.println(expanded); // should give "aaXXX!"
}
void loop() {}
我需要使用整数而不是字符来运行此代码。当我尝试将字符更改为int时,代码将引发错误。我尝试通过将数据类型更改为int
我也在寻找解决方案