GTK文本框号输入

时间:2012-06-19 14:39:52

标签: c linux gtk special-characters

我正在尝试在GTK + 3.0中创建一个文本框(在Linux中使用C),该文本框可以作为double读取,其中此double将插入等式中,然后在另一个框中返回。

所以我的问题是:创建一个可以输入的文本框的最佳方法是什么,然后我如何将其作为双重读取?

我目前正在尝试使用gtk_entry_new()进行初始化,并在经过一些中间步骤后*gtk_entry_get_text进行初始化。

我的阅读行目前看起来像这样:

double y = (double)*gtk_entry_get_text(GTK_ENTRY(input_y));

我一直将y作为指针,而*gtk_entry_get_text(...)的格式为const gchar *

我认为最好的方法是将const gchar*转换为double,但是如何?

1 个答案:

答案 0 :(得分:1)

$ 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.

因此:

double y = atof(gtk_entry_get_text(GTK_ENTRY(input_y)));
相关问题