【问题标题】:How to convert int to char* in Ardunio如何在 Arduino 中将 int 转换为 char*
【发布时间】:2021-08-15 09:23:24
【问题描述】:

所以我需要将 int 值转换为 char* 值。到目前为止,这是我的代码:

void setup(void) {
  Serial.begin(115200);
  char* host = "esp32";
  
  SerialBT.begin("test");
  while (!SerialBT.available()) {
    
  }
  char* ssid = SerialBT.read();
  while (!SerialBT.available()) {
    
  }
  char* password = SerialBT.read();
}

我还没有真正找到解决方案,但这是我得到的错误: invalid conversion from 'int' to 'char*'

有没有快速的解决方案?谢谢。

【问题讨论】:

  • 花点时间了解数组,或阅读this 和示例2。
  • 你试图做的是从你的蓝牙端口读取一个字符的内存地址(指针),这当然没有意义。
  • 换句话说,您不想将 int 转换为 char *。检查@hcheung 提供的链接。

标签: arduino char integer


【解决方案1】:

你可以尝试使用 atoi 函数:

int number = atoi( const char * str);

【讨论】:

    猜你喜欢
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-03-21
    • 2011-11-15
    • 2011-04-09
    • 2018-05-15
    • 2012-06-02
    • 2015-04-07
    相关资源
    最近更新 更多