Better String Library: bsplit problem

Started by jj2007, May 31, 2013, 05:05:21 PM

Previous topic - Next topic

jj2007

Hi,

Is anybody using Paul Hsieh's Better String Library?

I am a little bit stuck. Here is an example by Paul Hsieh himself but it fails miserably with loads of error messages :(

However, I got this working; it loads the correct #strings, and the timings are plausible, but I can't figure out how to use the 'tokens' for string operations including printing:

/*   called as follows - WinStr is a pointer to a buffer containing Windows.inc:
   bstring MyBuffer = bfromcstr(WinStr);
   rv=ArrayJJ(MyBuffer);
*/

int ArrayJJ(const_bstring src) {     // bstrlib.c, line 2655
   struct bstrList* tokens;
   int ct;
   tokens = bsplit(src, '\n');   // translates source string to an array
   #if 0
      // how can we use the array???
      // compiles but prints garbage:
      printf("T0=%s\n", tokens->entry[0]);
      printf("T1=%s\n", (*tokens).entry[1]);   // different syntax, same garbage
      printf("T2=%s\n", tokens->entry[2]);
   #endif
   return ct;
   }

Grateful for any hint, JJ

TimoVJL

..
printf("T0=%s\n", bdata(tokens->entry[0]));
printf("T1=%s\n", bdata(tokens->entry[1]));
printf("T2=%s\n", bdata(tokens->entry[2]));
...
May the source be with you

frankie

Or
      printf("T0=%s\n", tokens->entry[0]->data);
      printf("T1=%s\n", (*tokens).entry[1]->data);   // different syntax, same garbage
      printf("T2=%s\n", tokens->entry[2]->data);
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

jj2007

Thanks a lot, timovjl & frankie - all three variants work like a charm!

      printf("T0=%s\n", tokens->entry[0]->data);
      printf("T1=%s\n", (*tokens).entry[1]->data);
      printf("T2=%s\n", bdata(tokens->entry[2]));