OK, I feel really stupid asking this since this is a *really* simple piece of code (this represents a piece of the bigger problem) but I keep segfaulting when I do the av_len() below. Any ideas?

Thanks !
Nitin

------------------------------
use Inline C => DATA =>;
use strict;

my $sentence = "My name is nitin madnani";
&print_words($sentence);

__DATA__
__C__

void print_words(SV* sentence) {
        AV* mywords;
        char *sent, *pch;
        int i;
        SV* myword;
        SV** tmp;

        sent = SvPV_nolen(sentence);
        mywords = newAV();

        pch = strtok(sent," ");
        myword = newSVpvn(pch, strlen(pch));
        SvPOK_on(myword);
        av_push(mywords, myword);

        while (pch) {
                pch = strtok(NULL, " ");
                myword = newSVpvn(pch, strlen(pch));
                SvPOK_on(myword);
                av_push(mywords, myword);
        }

        for(i=0;i<av_len(mywords);i++) {
                tmp = av_fetch(mywords, i, 0);
                printf("%s\n", SvPV_nolen(*tmp));
        }
}
-------------------------------------------




Reply via email to