So, heres the deal, I’m using GTK on this one.
I’m asking for Name on a set_entry_text. So the user enters his name and I save that variable as a char.
char *jugador1, *jugador2 ///they're in a structure
void obten_nombre (GtkWidget *widget, gpointer info)
{
WIDGETS *elementos = (WIDGETS *)info;
gchar *j1, *j2;
j1=malloc(50 *sizeof(gchar));
j2=malloc(50 *sizeof(gchar));
strcpy(j1,gtk_entry_get_text(GTK_ENTRY( elementos->entry_j1)));
strcpy(j2,gtk_entry_get_text(GTK_ENTRY( elementos->entry_j2)));
strcpy(elementos->jugador1, j1);
elementos->jj1=j1;
// strcpy(elementos->jugador2, j2);
g_print("Jugador1: %s\n", elementos->jugador1);
gtk_widget_hide_all(elementos->ventana_popup2);
gtk_widget_show_all(elementos->ventana_principe);
}
There I’m making elementos->jugador1 a char variable.
I’m making a cast:
gchar auxjugador1;
How can I make
auxjugador1 = elementos->jugador1
so I can do a
gtk_entry_set_text(GTK_ENTRY(elementos->nombre_jugador1),auxjugador1);
Thank you guys!
jugador1is NOT acharvariable. It’s achar *(a pointer).You can’t put a pointer into a
gchar.You can either make another pointer, and point it to the existing data, or declare an array large enough to hold a copy, then use
strcpy.