I need to call a function that requires a byte array ('buffer' for FileLogger::append("data.log", buffer, length))
I have a large char array buffer that I use strcat() on to make the string I need.
I can't use strcat() with a byte array, and I can't simply cast the char array at the function ("loss of precision" error).
Is there a way to convert the char array to byte array without creating a new byte array and copying to it with a for loop?
Thanks
An answer in 2 minutes! Thanks!
mem
April 28, 2009, 2:37am
4
why not something like this:
byte byteArray[10];
strcat( (char*)(&byteArray[1]),"test");
Serial.print((char*)byteArray);
I realized my problem was that I was not casting to a pointer.
So result = FileLogger::append("data.log", (byte*)message, length); works.
mem,
If I wanted to go the other way . . .
Isn't strcat( (char*)(&byteArray[1]),"test"); the same as simply
strcat( (char*)byteArray,"test"); ?
mem
April 28, 2009, 3:15pm
6
strcat( (char*)(&byteArray[1]),"test"); is a pointer to the second element in the array
strcat( (char*)byteArray,"test"); is a pointer to the first element
Yes, that makes sense. But then for you suggestion above, why would I want to point to the second element in the array?
mem
April 28, 2009, 5:06pm
8
I was not sure if you were making strings from pieces of other strings. Good to hear that you are not
Have fun!
Thanks! Now it's all clear. :-X