Re: How to change float to char



Skip Montanaro wrote:
> 
>     Flavio> I need to print float numbers in a gtk label and this widget
>     Flavio> only accept gchar in your text parameter, I want to know if
>     Flavio> exists some type of routine that changes float number in format
>     Flavio> a.bcde to char format "a.bcde".
> 
> Check out g_snprintf in the glib reference manual (section: String Utility
> Functions).  I believe you call it pretty much like you would sprintf, with
> the added safety feature that you provide the length of the output buffer so
> it doesn't scribble past the end of it:
> 
>     g_snprintf(buf, len_buf-1, "%6.4f", myfloat);

I find this useful:

--
void
set_labelf( GtkWidget *label, const char *fmt, ... )
{
        va_list ap;
        char *buf;

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

        gtk_label_set_text( GTK_LABEL( label ), buf );
	g_free( buf );
}
--

John




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