NO

Author Topic: Better String Library: bsplit problem  (Read 4365 times)

Offline jj2007

  • Member
  • *
  • Posts: 536
Better String Library: bsplit problem
« on: May 31, 2013, 05:05:21 PM »
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

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: Better String Library: bsplit problem
« Reply #1 on: May 31, 2013, 07:53:18 PM »
Code: [Select]
..
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: Better String Library: bsplit problem
« Reply #2 on: May 31, 2013, 09:49:23 PM »
Or
Code: [Select]
      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

Offline jj2007

  • Member
  • *
  • Posts: 536
Re: Better String Library: bsplit problem
« Reply #3 on: May 31, 2013, 11:23:50 PM »
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]));