How do I limit the gtkEntry only to numbers and also how to store the value entered by the user for further calculation.
entry1 = gtk_entry_new();
How do I limit the gtkEntry only to numbers and also how to store the value entered by the user for further calculation.
entry1 = gtk_entry_new();
You can use gtk_entry_get_text()
to get the text, then of course for an integer you need to convert using e.g. strtol()
or some other regular string-to-integer function:
const char *text = gtk_entry_get_text(entry1);
const long value = strtol(text, NULL, 10);
printf("the value is %ld\n", value);
The above isn't 100% rock-solid, you can use the middle argument to strtol()
to make it better but I omitted it for brevity and topicality.