I want to create a multiple array of my structure:
#include <gtk/gtk.h>
#include <glib/gi18n.h>
typedef struct {
gchar icon_name[24];
int response;
gchar label[10];
} button_data;
GtkWidget * create_button_helper (GtkDialog *dialog) {
button_data b[3] = {
{ "dialog-ok", GTK_RESPONSE_YES, _("Yes")},
{ "dialog-close", GTK_RESPONSE_NO, _("No") },
{ "", 0 }
};
gint index;
for (index = 0; b[index].response != 0; index++) {
GtkWidget *tmp;
GtkWidget *i;
tmp = gtk_button_new_with_label (b[index].label);
i = gtk_image_new_from_icon_name (b[index].icon_name, GTK_ICON_SIZE_BUTTON);
gtk_button_set_image (GTK_BUTTON (tmp), i);
gtk_dialog_add_action_widget (GTK_DIALOG (dialog), tmp, b[index].response);
}
}
But I get the error about invalid initializer, any helps?
When compiled with gcc -Wall
the following relevant warnings are given:
./tmp.c: In function ‘create_button_helper’:
./tmp.c:12:9: warning: missing braces around initializer [-Wmissing-braces]
{ "dialog-ok", GTK_RESPONSE_YES, _("Yes")},
^
./tmp.c:12:9: warning: (near initialization for ‘b[0].label’) [-Wmissing-braces]
./tmp.c:12:9: warning: initialization makes integer from pointer without a cast [enabled by default]
./tmp.c:12:9: warning: (near initialization for ‘b[0].label[0]’) [enabled by default]
./tmp.c:13:9: warning: initialization makes integer from pointer without a cast [enabled by default]
{ "dialog-close", GTK_RESPONSE_NO, _("No") },
^
./tmp.c:13:9: warning: (near initialization for ‘b[1].label[0]’) [enabled by default]