Question

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...

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

Homework Answers

Answer #1

#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;

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions