Reputation: 13
I am trying to create a text box in GTK+3.0 (using C, in Linux) that can be read from as a double, where this double will be plugged into an equation and then returned in a different box.
So my question is: what is the best way to create a text box that can be typed into, and then how do I read it as a double?
I am currently trying to use gtk_entry_new()
to initialize and - after a few intermediary steps - *gtk_entry_get_text
to read.
My read line currently looks like this:
double y = (double)*gtk_entry_get_text(GTK_ENTRY(input_y));
I keep getting y as a pointer, and the *gtk_entry_get_text(...)
is of format const gchar*
I believe the best way is to convert const gchar*
into double
, but how?
Upvotes: 1
Views: 1623
Reputation: 495
$ man atof
NAME
atof - convert a string to a double
SYNOPSIS
#include <stdlib.h>
double atof(const char *nptr);
DESCRIPTION
The atof() function converts the initial portion of the string
pointed to by nptr to double. The behavior is the same as
strtod(nptr, (char **) NULL);
except that atof() does not detect errors.
RETURN VALUE
The converted value.
thus:
double y = atof(gtk_entry_get_text(GTK_ENTRY(input_y)));
Upvotes: 1