i doing sum of two number when show the final answer printf in terminal is ok. but i want to show the final answer in (gtk's label) i having a lot of problem. i had tried to refer the website or other people forum. most of them are too complicated and still error when compile it. does someone can help or giving the solution or correction of these code that i show? please don't add button function in gtk. i had want to try transfer printf sensor value to gtk after all.
how to get just "total = 23" display in gtk?
if someone don't understand can try running 2 code above.
..................................................................................................................................................................
// sample addition of 2 number
#include <stdio.h>
int main()
{
int a, b, c;
a=3;
b=20;
c = a + b;
printf("Sum of numbers = %d\n", c);
return 0;
}
.................................................................................
.................................................................................
// sample gtk
#include <gtk/gtk.h>
void main(int argc, char *argv[])
{
gtk_init (&argc, &argv);
GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win), 250, 150);
GtkWidget *lbl = gtk_label_new ("100 C");
gtk_container_add (GTK_CONTAINER (win), lbl);
gtk_widget_show_all (win);
gtk_main();
}
..................................................................................................................................................................
problem when trying replaced gtk label with printF value
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
int a, b, c;
a = 3;
b = 20;
c = a + b;
gchar* Sumvalue;
Sumvalue = g_strdup_printf ("total = %d", c);
gtk_init (&argc, &argv);
GtkWidget *win = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(win), 250, 150);
GtkWidget *lbl = gtk_label_set_text(GTK_LABEL(*Sumvalue));
gtk_container_add (GTK_CONTAINER (win), lbl);
gtk_widget_show_all (win);
gtk_main();
}
What I have tried:
the above code is my last try or modify, still can't get result. having problem when compile it.
error massage, error, GTK_LABEL undrclared