Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm starting to learn C and GTK2. So, I find tutorial at zetcode.com, and try to make a little program, but it doesn't want to start. I'm doing exactly as in tutorial, but there's some bug in my code.

#include <stdio.h>
#include <gtk/gtk.h>

int count = 0;
char buf[5];

void increase(GtkWidget *widget, gpointer label)
{
 count++;

 sprintf(buf, "%d", count);
 gtk_label_set_text(label, buf);
}

void decrease(GtkWidget *window, gpointer label)
{
 count--;

 sprintf(buf, "%d", count);
 gtk_label_set_text(label, buf);
}

int main(int argc, char** argv)
{
 GtkWidget *label;
     GtkWidget *window;
 GtkWindow *frame;
 GtkWindow *plus;
 GtkWindow *minus;

 gtk_init(&argc, &argv);

 window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
 gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
 gtk_window_set_default_size(GTK_WINDOW(window), 200, 100);
 gtk_window_set_title(GTK_WINDOW(window), "Math");

 frame = gtk_fixed_new();
 gtk_container_add(GTK_CONTAINER(window), frame);

 plus = gtk_button_new_with_label("+");
 gtk_widget_set_size_request(plus, 80, 35);
 gtk_fixed_put(GTK_FIXED(frame), plus, 50, 20);

 minus = gtk_button_new_label("-");
 gtk_widget_set_size_request(minus, 80, 35);
 gtk_fixed_put(GTK_FIXED(frame), minus, 50, 20);

 label = gtk_label_new("0");
 gtk_fixed_put(GTK_FIXED(frame), label, 190, 58);

 gtk_widget_show_all(window);

 g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
 g_signal_connect(plus, "clicked", G_CALLBACK(increase), label);
 g_signal_connect(minus, "clicked", G_CALLBACK(decrease), label);

 gtk_main();

 return 0;
}

Pls, help.

share|improve this question
3  
This should be on stack overflow. You could also ask on the 'Programming Talk' section of the forums. –  dv3500ea Nov 5 '10 at 15:03
    
What is the build command you use to compile this source? What is the error message you get? –  Rafał Cieślak Nov 5 '10 at 17:14
add comment

1 Answer 1

This line is wrong:

minus = gtk_button_new_label("-");

It should be:

minus = gtk_button_new_with_label("-");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.