I have problems when using strtok. I want token to has a reserved size so its contents doesn’t corrupt other data (I have small memory, because I’m working over a MCU, not a PC). Then I decided to declare ir as an array with a declared size.
But then I have this error: Assignment invalid: lvalue is READ ONLY
#DEFINE BUFFER_SIZE 128
static int8 buffer[BUFFER_SIZE]; // Declared as global
void myFunction(){
char separador[3], token[BUFFER_SIZE], cmd[BUFFER_SIZE];
strcpy(cmd, buffer); // buffer is a global variable declared ad
strcpy(separador, ",;");
token = strtok(cmd, separador); // <----- ERROR
//...
}
What does that error exactly mean? Is it because I haven’t initialised the array? If I declare it as static, would it work?
strtokreturns bits ofcmd, so you don’t allocate storage for it’s return value. You just want token to be achar*: