使用struct将数据类型从char更改为int。有人可以帮助我解决此代码吗?

问题描述 投票:0回答:1
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

c++ c arduino arduino-uno arduino-c++
1个回答
-2
投票

我也在寻找解决方案

© www.soinside.com 2019 - 2024. All rights reserved.