BabyGeezer:
of course it is - i said it was from blindly doing trial and error because i have no idea what the correct way is !
are you sure ?!
Well, I've only been doing c programming for about 35 years, so, yeah, I'm pretty sure.
BabyGeezer:
if it's
char* msg = incomingByte;
...
...
vw_send((uint8_t *)msg, strlen(msg));
the error is "invalid conversion from 'char' to 'char*' "
Of course it is, because you're trying to assign incomingByte, which is a char, to msg, which is a POINTER to a char. The compiler does not know how to convert a char to a pointer to a char, because that conversion makes no sense. If you want to make msg POINT TO incomingByte, then you either:
msg = &incomingByte; // to force msg to point to incomingByte
or,
*msg = incomingByte; // to copy incomingBye to the character pointed to by msg
or,
msg[0] = incomingByte; // to copy incomingBye to the character of the array pointed to by msg
These last two assume msg ALREADY points to a valid char or array. A pointer, if not initialized, points to either whatever is at address 0 in memory, or some random location in memory. Writing to either of those is bad...
BabyGeezer:
if it's
char msg = incomingByte;
...
...
vw_send((uint8_t *)msg, strlen(msg));
the error is "invalid conversion from 'char' to '**const** char*' " (don't know how __*that*__ came into the mix suddenly... :/ )
Because vw_send does NOT take a char as its first argument, it takes a const char *. Again, the conversion you're asking the compiler to make does not make sense.
You can write:
vw_send(&msg, strlen(msg));
But, while that will compile, it will almost certainly not work as you want, since most functions that take a char* as an argument expect a pointer to a NULL-terminated string, NOT to a single char.
BabyGeezer:
no i cannot;
char incomingByte = 0;
incomingByte = Serial.read(); // this is what text_from_somewhere actually is
...
...
vw_send((uint8_t *)incomingByte, strlen(incomingByte));
the error is "invalid conversion from 'char' to 'const char*' "
This is exactly the same problem as the previous example...
BabyGeezer:
and if i change the declaration of incomingByte, then;
char* incomingByte = 0;
incomingByte = Serial.read();
the error is "invalid conversion from 'int' to 'char*' "
Your are creating a pointer to char, and setting it's value to zero, so it points to the first byte of memory. You then attempt to take the result of the Serial.read, and shove it into the pointer, so you now have a poitner that points to somewhere in memory, who knows where. That is a recipe for stomping on random bytes of memory. IF you want to USE the pointer, you must make sure it points to valid, allocated memory. You CAN do this:
char* incomingByte = &0;
*incomingByte = Serial.read();
The first line creates the pointer, then allocates a byte of memory either on the stack or the heap (depending on where in your program this line appears), then sets the value of that byte to 0, and finally sets the value of the pointer incomingByte to the address of that byte. NOW you can assign the value returned by the Serial.read to that byte of memory, as the second line does. The second line says call Serial.read(), then put the value it returns into the memory location pointed to by incomingByte. The '', when it appears in front of the name of a pointer, references the memory location pointed to by the pointer. Without the '' the pointer name references the value of the pointer itself. The '&' character, when it appears in front of any variable name, references the MEMORY ADDRESS of that variable, rather than the variables value. So '&' must be used when setting the value of a pointer so it points to a specific variable.
Regards,
Ray L.
Regards,
Ray L.