Re: GString problem.



Archit Baweja wrote:

> Hi
>
> I'm having some problems in assigning some text to a GString.
> I start with
>
> GString *data;
> data = g_string_new ("");
>
> Then I read data from a file into a gchar *
>
> fread (buffer, sizeof (gchar), 32, fp);
> g_string_append (data, buffer);
>

Modify your code to:
-------------
GString *data;
gint count;

data = g_string_new ("");
count = fread(buffer, sizeof (gchar), 32, fp);

/* fread () reads is a block of binary data and not a NULL terminated string */
/* So you need to explicitly terminate it with NULL, if you want to use it as */
/* NULL terminated string */
buffer [count] = '\0';
..... ..
..... ..


--

Regards,
-Naba

-------------------------------------------------------------
Uh-oh!!  I'm having TOO MUCH FUN!!
-------------------------------------------------------------







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