i am getting a compiler warning, here’s the code:
uint8 executeSpecialCommand(const char *string)
{
char *parameters;
parameters = strtok(string, "=");
if (parameters)
{
usbSendf("\nProcessing Parameters...");
while(parameters != NULL)
{
parameters = strtok(NULL, " ");
usbSendf("\n%s", parameters);
}
return 1;
}
else
return 0;
}
the error points to line 3 and i think it is because “=”. strtok is expecting a const char* somehow in other parts of the code i use the same and i get no warning. An ideas here to help educate me ?
UPDATE
The error i get is:
warning 196: pointer target lost const qualifier
thanks
The
strtokfunction modifies its first argument. From a man page:This means that you can pass a
const char*as the first argument as you are doing with the variable namedstring.strtokworks by inserting a NULL in the passed string at every delimeter which allows it to return each token without allocating memory for the returned string. I doubt whether SDCC supports the reentrant versionstrtok_rbut it would be possible to use that instead if it existed.Alternatively, create your own copy of the incoming string before parsing. If you know the maximum incoming string size then the string copy can be allocated on the stack at the top of your parsing function.