UPDATED CODE HERE
Hello!
Today I ordered parts for the proto phase of the plane.
This is a bit of code i’ve found that’s usefully for splitting strings in the arduino C
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
</pre> #include <string.h> #define MAX_STRING_LEN 20 char *inputstring1 = "one,two,three,four,five,six,seven,eight,nine,ten"; //this is the string that will be split. this can be changed! char *p, *i; int x; void setup() { Serial.begin(9600); } void loop () { for (int x = 1; x <= 10; x++) { Serial.println(subStr(inputstring1, ",", x)); delay(1000); } } char* subStr (char* input_string, char *separator, int segment_number) { char *act, *sub, *ptr; static char copy[MAX_STRING_LEN]; int i; strcpy(copy, input_string); for (i = 1, act = copy; i <= segment_number; i++, act = NULL) { sub = strtok_r(act, separator, &ptr); if (sub == NULL) break; } return sub; } //esologic.com |