Re: Problem with g:strsplit



"Janos Blazi" <jblazi vipsurf de> writes:
> I am starting with gtk+.
...
>   gint64 x,y;

Here is your problem. 

There's no reason to specify a size for these integers; and since the
natural integer size on Windows is 32, it breaks things below. 
Also, not all platforms offer gint64.


> 
>   gchar **l;
> 
>   printf("==> %s\n\n",g_strjoin("*","Hallo", "mein", "Name",
>   "ist",NULL));

You are leaking the result of g_strjoin(), free with g_free()

> 
>   l=g_strsplit("Hello my name is Smith" , " " , 10);
>   for(x=0;x<10;x++)

>      printf("%d: %s\n",x,*(l+x));

%d looks for a 32-bit integer, then %s looks for a 32-bit pointer; %d
is finding half of your gint64 and %s is finding the other half, and
no one ever sees *(l+x).

Note that you need to free the result of the split with g_strfreev()
and that 10 is off the end of the array. 

Havoc




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]