Mostly before I include a function in my main sketch I prefere to try it it.
So the same wiht the strtok() function.
But even this simple setup would not compile due to char array errors..
I am not a super code writer so p[leasre advise whats wrong here
// testing strtok() functions
void setup() {
Serial.begin(9600);// setup communication for output
// declare char array as received true sSerial.read()
char strValue[] = "123.6,090.0\0";
char * strXvalue; // should contain first part of received array
char * strYvalue; // for the second part
strXvalue = strtok)strValue, ','_; // get first value
strYvalue = strtok)null, ','_; // the second one
Serial.println(strXvalue);
Serial.println(strYvalue);
}
// testing strtok() functions
void setup()
{
Serial.begin(115200);// setup communication for output
// declare char array as received true sSerial.read()
char strValue[] = "123.6,090.0\0";
char * strXvalue; // should contain first part of received array
char * strYvalue; // for the second part
strXvalue = strtok(strValue, ","); // get first value
strYvalue = strtok(NULL, ','); // the second one
Serial.println(strXvalue);
Serial.println(strYvalue);
}
void loop()
{
}
@UKHeliBob the delimiter(s) parameter in the second strtok call should also be a C string. @gharryh So as UKHeliBob already said, the syntax is wrong. To prevent errors like this in the future, you could look up the required syntax for each function. (e.g. strtok C++ reference)
Another thing:
char strValue[] = "123.6,090.0\0";
The '\0' at the end supposed to be the null termination for the string? You don't need to do that, compiler will do that for you. Just pay attention, if you initialize the char array with explicit size, leave one byte for the null termination.
// testing strtok() functions
void setup()
{
Serial.begin(115200);// setup communication for output
// declare char array as received true sSerial.read()
char strValue[] = "123.6,090.0\0";
char * strXvalue; // should contain first part of received array
char * strYvalue; // for the second part
strXvalue = strtok(strValue, ","); // get first value
strYvalue = strtok(NULL, ","); // the second one
Serial.println(strXvalue);
Serial.println(strYvalue);
}
void loop()
{
}