String splitting problem in C
A string like GGB[BD]GB[DC,BD]WGB[BD]B[DC]B[BD]WB[CK,JC,DC,CA,BC]B[FB,EB,BD,BC,AB]
How do I split it to get only whats inside the bracket with C?
so i would get BD, DC, BD, BD,DC,BD, CK, JC, DC, CA, BC, FB, EB, BD, BC, AB
and then get rid of duplicate
and get BD, DC, CK, JC, CA, BC, FB, EB, AB
#include <stdio.h>
#include <string.h>
int main() {
char string[100] = "GGB[BD]GB[DC,BD]WGB[BD]B[DC]B[BD]WB[CK,JC,DC,CA,BC]B[FB,EB,BD,BC,AB]";
char * token = strtok(string, ",");
while( token != NULL ) {
printf( " %s\n", token );
token = strtok(NULL, ",");
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.