我需要处理矩阵中的数据。我想要这样的东西:
{{"data11", "data12", "data13"},
{"data21", "data22", "data23"},
{"data31", "data32", "data33"}}
我认为"char* matrix[3][3];
“可以做到这一点,但我还没有得到预期的结果。
我需要采取以下行动:
""
)。提前谢谢。
发布于 2015-10-03 14:08:52
以后,您应该使用字符数组,而不是字符串指针来修改其内容。
#include <string.h>
// this will be initialized to "" because this is global variable
// Please allocate enough memory for each elements
// (adjust last number [10]if needed)
char matrix[3][3][10];
void setup() {
// put data in the matrix
strcpy(matrix[0][0], "data11");
strcpy(matrix[0][1], "data12");
strcpy(matrix[0][2], "data13");
strcpy(matrix[1][0], "data21");
strcpy(matrix[1][1], "data22");
strcpy(matrix[1][2], "data23");
strcpy(matrix[1][0], "data31");
strcpy(matrix[1][1], "data32");
strcpy(matrix[1][2], "data33");
}
void loop() {
}
还是要使用String
?
// this will be initialized to "" because this is global variable
String matrix[3][3];
void setup() {
// put data in the matrix
matrix[0][0] = "data11";
matrix[0][1] = "data12";
matrix[0][2] = "data13";
matrix[1][0] = "data21";
matrix[1][1] = "data22";
matrix[1][2] = "data23";
matrix[2][0] = "data31";
matrix[2][1] = "data32";
matrix[2][2] = "data33";
}
void loop() {
}
https://stackoverflow.com/questions/32915088
复制相似问题