Re: [gtk-list] 4am, school tomorrow, and these 5 lines of code are killing me!
- From: johannes nada kth se (Johannes Keukelaar)
- To: gtk-list redhat com
- Subject: Re: [gtk-list] 4am, school tomorrow, and these 5 lines of code are killing me!
- Date: Tue, 07 Apr 1998 12:16:59 +0200
//
//	Help.  I have a text widget, a label widget, and I want the label
//to show the number of characters in my text widget.  I can't find any
//freakin' docs on the Gstring, or gchar, or g_char (or whatever the hell
//I'm supposed to use) so here's my fxn:
//
//
//void message_label_update(GtkWidget *text, GtkLabel *label)
//{
//	guint message_length;
//	GString *the_label_text;   /* what should this be?! */
//	
//	message_length = GTK_TEXT(text)->text_end - GTK_TEXT(text)->gap_size;
//
//	if (message_length == 1)
//	{
//	gtk_label_set(GTK_LABEL(label), "1 character");
//	}
//	else
//	{
//	g_string_sprintf(the_label_text,"%d characters", message_length);
//	gtk_label_set(GTK_LABEL(label), &the_label_text);
//	}	
//
//}
Try:
#define BUFLENGTH 30 /* Or however much you think you'll need. */
gchar the_label_text[ BUFLENGTH ]; 
And then a bit later:
g_snprintf( the_label_text, BUFLENGTH, "%d characters", message_length );
gtk_label_set( GTK_LABEL( label ), the_label_text );
//
//	This is the warning I get when I try to compile:
//
//MessageGordon.c: In function `message_label_update':
//MessageGordon.c:80: warning: passing arg 2 of `gtk_label_set' from
//incompatible pointer type 
Yep. Looking in the include files will tell you that gtk_label_set expects a 
second parameter of the type gchar *.
Good luck,
Johannes.
--
The reason computer chips are so small is computers don't eat much.
<insert funny description here>
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]