Re: [Anjuta-list] tutorial problem



Hello Kyle,
---8<------------------------------------------
Hours later I localized it to the strcat function, and nothing I could do to the variables or replacing strcat with sprintf or whatever would stop it crashing. If I just used text1 in gnome_app_message or defined text2 as a constant character string it would work.   Finally I thought of a "gnome-way" solution.  I used g_strconcat instead of strcat, and that worked fine.   Here's my replacement code:

void
on_BT_OK_clicked                       (GtkButton       *button,
                                                         gpointer         user_data)
{
GtkWidget *entry = lookup_widget (GTK_WIDGET (button), "ENTRY"); gchar *text1 = "Hello,"; gchar *text2 = gtk_entry_get_text (GTK_ENTRY(entry));

		text1 = g_strconcat (text1, text2, NULL);
	        GtkWidget *msgbox = gnome_app_new("Hello World", "Hello World");
gnome_app_message (GNOME_APP(msgbox), text1); }

Pretty discouraging for a beginner!  I'd still like to know what caused the problem.

It is an casting-problem.
My code:

void on_key_OK_clicked (GtkButton *button, gpointer user_data)
{
  GtkWidget *entry = lookup_widget (GTK_WIDGET(button),"entry");
  /* Gtk_entry returns an "const char" */
  /* Remark: use "const char" or "const gchar" */
  const char *text2 = gtk_entry_get_text (GTK_ENTRY(entry));
  GtkWidget *msgbox = gnome_app_new("","");
  /* makes String with additional items */
  char text[88];
  strcpy(text,"Hello ");
  strcat(text,text2);
  strcat(text," :-)");
  gnome_app_message (GNOME_APP(msgbox),text);	
}
	
Greetings
Ulrich





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