RE: gint to gchar: g_sprintf



gint add = 10;

you should declare here gchar *addid:
gchar *addid = NULL;

and before the call to g_sprintf you should assign enough 
memory for this
variable too, for example:
addid = (gchar *) g_malloc (25);
will make addid to point to a piece of memory of 25 bytes (of chars)

g_sprintf(gchar *addid,"%d", add);

you should ommit the type specification of addid:
g_sprintf (addid, "%d", add);

OR

you could do:

        gint a = 10;
        gchar *str = NULL;

        str = g_strdup_printf("%d", a);
        
        /* use the str */
        g_message("my new string is: '%s'", str);

        /* clean up */
        g_free(str);


Regards,
Martyn



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