Pelles C forum
C language => Beginner questions => Topic started by: jj2007 on May 31, 2013, 05:05:21 PM
-
Hi,
Is anybody using Paul Hsieh's Better String Library (http://bstring.sourceforge.net/)?
I am a little bit stuck. Here is an example by Paul Hsieh himself (http://coding.derkeiler.com/Archive/C_CPP/comp.lang.c/2006-06/msg03723.html) 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
-
..
printf("T0=%s\n", bdata(tokens->entry[0]));
printf("T1=%s\n", bdata(tokens->entry[1]));
printf("T2=%s\n", bdata(tokens->entry[2]));
...
-
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);
-
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]));