我正在做一个 arduino 项目,我一直在努力寻找一种方法来为二维指针数组赋值(如果我正确的话)。我有这个数组char* numbers[3][4];
,我希望它有 4 个字符长 - 4 个数字(如代码)。但请注意,我不能更改声明,只能更改字符串的数量。
我尝试使用 strcpy 分配值:
strcpy(*numbers[0], "1234");
strcpy(*numbers[1], "5678");
strcpy(*numbers[2], "9012");
分配值后,该数组应用作函数的参数,该函数
void render_numbers(char** numbers, const int index);
基本上在给定索引处打印 Arduino 串行上的 4 位代码。所以我调用了这个函数:
render_numbers(*numbers, 2);
我的功能:
void render_numbers(char** numbers, const int index){
Serial.println(numbers[index]);
}
所以它通过了编译器,但在串行中它只打印不可读的字符(正方形、问号等)