[Glade-users] problems with glade

Albert albert@vorwireless.net
09 Nov 2003 12:28:54 +0100


hi all,

Now the program don't return errors, but, the text_view only show the
last line of the file, I think add:: sprintf(magatzem,"%s\n", magatzem);
but text_view only show the last line.

---------- 8< interface.c ----------
[...]

  FILE *correu;
  int a, i;
  char magatzem[1024];
  gchar *out;
  correu = fopen("/tmp/tenes777","r");
  textbox = gtk_text_view_new();
  buffer = gtk_text_buffer_new (NULL);
  while (!feof(correu)) {
  fgets(magatzem, 1000, correu);
  a++;
  if (strstr(magatzem, "[Tenes777]") != NULL) {
    sprintf(magatzem,"%s\n",magatzem);
  out = g_convert(magatzem, -1,"UTF-8","ISO8859-1",NULL,NULL,NULL);
  if (out == NULL) printf("\nerror g_convert\n");

    gtk_text_buffer_set_text (buffer, out, -1);
    g_free(out);
    gtk_text_view_set_buffer (GTK_TEXT_VIEW (textbox), buffer);
    gtk_widget_show (textbox);
    i++;
  }
 }

[ ... ]
--------------------- 8< interface.c -------------

thanks for your time.

Albert

El vie, 07 de 11 de 2003 a las 01:34, Tomi Manninen escribió:
> On Fri, 2003-11-07 at 01:49, Albert wrote:
> 
> > Thanks Damon, 
> > I try to convert the string to UTF-8 but the program return the same
> > error:
> 
> >   out = g_convert(magatzem, -1,"UTF-8","ISO8859-1",NULL,NULL,NULL);
> > 
> >     gtk_text_buffer_set_text (buffer, magatzem, -1);
> 
> You are still passing the unmodified string (magatzem) to
> gtk_text_buffer_set_text(). It's `out' that has the converted string.
> And remember to free it later. So something like this:
> 
>   out = g_convert(magatzem, -1,"UTF-8","ISO8859-1",NULL,NULL,NULL);
> 
>   if (out == NULL) {
>     /* handle error */
>   }
> 
>   gtk_text_buffer_set_text (buffer, out, -1);
>   g_free(out);
> 
>   ...