_10_11.ino: In function 'void loop()':
_10_11:73: error: initializer fails to determine size of 'results'
_10_11.ino: In function 'char getData()':
_10_11:160: error: invalid operands of types 'const char*' and 'const char [5]' to binary 'operator+'
简而言之,我有一个char getData()
返回char output[50] = "1: " + cmOne + " 2: " + cmTwo + " 3: " + cmThree + " 4: " + cmFour;
where的函数int cmOne, cmTwo, cmThree, cmFour
。
在循环中,我称:
char results[] = getData();
client.println("1: %i", results[0]);
client.println("2: %i", results[1]);
client.println("3: %i", results[2]);
client.println("4: %i", results[3]);
我知道我在数据类型,分配等方面错了,但是对于如何做到最好,有什么建议吗?
这是不可能的,创建一个固定大小的数组,并将其作为指针传递给函数,然后在函数中对其进行初始化
char results[4];
getData(results); /* the getData function should take a 'char *' paramenter */
client.println("1: %i", results[0]);
client.println("2: %i", results[1]);
client.println("3: %i", results[2]);
client.println("4: %i", results[3]);
当然,如果数组更大 char results[A_BIGGER_SIZE];
假设获取数据只是将一个字符串"ABC"
放入result
看起来像这样的数组中
void getData(char *dest)
{
dest[0] = 'A';
dest[1] = 'B';
dest[2] = 'C';
dest[3] = '\0';
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句