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

Re: label with format string



On Sun, 7 Sep 2003 17:29:43 +0200
Johannes Weißl <jargon@hurg.org> wrote:

> Hello,
> 
> is it possible to print text in a GtkLabel like the function
> "printf" does?
> 
> e.g.:
> void gtk_label_printf (GtkLabel *label, const gchar *format, ...);

Yes. The following should work.

#define _GNU_SOURCE	/* for vasprintf */
#include <stdio.h>
#include <stdarg.h>	/* for va_* */
#include <gtk.h>

int gtk_label_printf (GtkLabel *label, const gchar *format, ...) {
	char *str;
	int rv = 0;
	va_list ap;

	va_start(ap, format);
	rv = vasprintf(&str, format, ap);
	va_end(ap);
	if (rv != -1) {
		gtk_label_set_text(label, str);
		free(str);
	}
	return rv;
}

Roland
-- 
R.F. Smith                           /"\    ASCII Ribbon Campaign
r s m i t h @ x s 4 a l l . n l      \ /    No HTML/RTF in email
http://www.xs4all.nl/~rsmith/         X     No Word docs in email
                                     / \    Respect for open standards

PGP signature



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