Creating array of buttons gtk in c -


i need create array of buttons in c. not sure missing, please me. here array:

gtkwidget *button[5]; int i; ( =1; i<5; i++)         button[i] = gtk_button_new(); 

then creating rest of buttons... using button [i] , @ end i++; not best way, not sure when create array, how pass button 1, button 2 , etc in rest of statements? please appreciated. p.s. new in c, dont harsh on me, ty:)

 /* creates new button label "button 1". */ button[i] = gtk_button_new_with_label ("button 1");  /* when button clicked, call "callback" function  * pointer "button 1" argiument */ g_signal_connect (button[i], "clicked",                   g_callback (callback), "run button 1");  /* instead of gtk_container_add, pack button invisible  * box, has been packed window. */ gtk_box_pack_start (gtk_box (box1), button[i], true, true, 0);  /* remember step, tells gtk our preparation  * button complete, , can displayed. */ gtk_widget_show (button[i]); i++; 

your loop starts index variable (i) of 1 in computer's memory index array of buttons declared with

gtkwidget *button[5];

starts index of 0 (i = 0) example code should like:

gtkwidget *button[5]; //not necessary since c99 can declare inside for() e.g for(int = 0; < 5; i++) int i; for(i = 0; < 5; i++) {     button[i] = gtk_button_new(); } //do other stuff 

then use buttons access them regular array eg:

 button[0] = gtk_button_new_with_label("button 1"); 

you not need i++ inside of loop because loop automatically increments iterator (i variable) after every loop (this i++ @ end of for(i = 0; < 5; i++) does)


Comments

Popular posts from this blog

html - Styling progress bar with inline style -

java - Oracle Sql developer error: could not install some modules -

How to use autoclose brackets in Jupyter notebook? -