Re: [gtk-list] Q: (gtk-entry) convert integer/float to char/string

Daniel Hops wrote:
> in my gtk app I have to calculate digits (integers/floats) and want to
> insert them in entries via "gtk_entry_set_text ()".
> But this method only accepts chars. How can I easily make a function
> like itoa? Or is there another way?

Hi, I use something like this:

/* Set a GtkEntry.
set_gentry( GtkWidget *entry, gchar *fmt, ... )
        va_list ap;
        gchar *str;

        if( !entry )

        if( !fmt )
                fmt = "";

        va_start( ap, fmt );
        str = g_strdup_vprintf( fmt, ap );
        va_end( ap );

        gtk_entry_set_text( GTK_ENTRY( entry ), str ); 

	g_free( str );

Hope this helps,

John Cupitt,, +44 (0)171 747 2570
VASARI Lab, The National Gallery, Trafalgar Square, London, WC2N 5DN

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