calai
December 22, 2016, 6:10am
1
i have 2 questions here.
void AndeeHelper::setData(char* title)
Does the above code allow me to perform setData(char) and display an array of character? My objective is to display a string, which i intend to display using char array.
char tableSelect;
char locationStatus[6] = "Table ";
char UGVLocation1[sizeof(locationStatus) + sizeof(tableSelect)];
void loop()
{
UGVLocation1 = locationStatus + tableSelect;
locationStatus1.setData(UGVLocation1);
}
The above is a part of my code. The value char of UGVLocation1 is not constant. Therefore, the size of the array is a variable. However, why do i get an error of incompatible types in assignment of 'char*' to 'char [7]' if tableSelect = 1?
Will i be able to display UGVLocation1 in this case with reference to my first question?
Thank you.
char locationStatus[6] = "Table ";
Too small.
However, why do i get an error of incompatible types in assignment of 'char*' to 'char [7]' if tableSelect = 1?
C(++) does not have a copy-assignment operator for arrays. Use strlcpy .
C++ does not have a concatenation operator for arrays of characters (C-style strings). Use strlcat .
jimLee
December 22, 2016, 6:34am
3
char tableSelect;
char locationStatus[6] = "Table ";
char UGVLocation1[sizeof(locationStatus) + sizeof(tableSelect)];
I think UGVLocation1 will always be 7.
locationStatus = 6 bytes 'cause you set it above.
tableSelect is a char so its 1 byte.
Is this what you want?
-jim lee
calai
December 22, 2016, 7:58am
4
Thanks for the replies.
I want it to display "Table " + an int. That is why i code it to be UGVLocation1 = locationStatus + tableSelect;
Can anyone give an example on how to use strlcat to do concatenation?
I want it to display "Table " + an int.
Why concatenate them ?
Output the text then output the int.
Alternatively look at the sprintf() function to get both into a single buffer then output the buffer.
UKHeliBob:
Alternatively look at the sprintf() function to get both into a single buffer then output the buffer.
snprintf . The n is important.
Only if you are careless ...
But I agree. It is safer.
system
December 22, 2016, 12:43pm
8
Only if you are careless ...
Without it, the function name would be snpritf(), which the linker won't be able to find. So, it is important. 8)
What @UKHeliBob said: print your string, and then print your number.