从条目文本中获取数字

Getting a number from an entry text

我正在使用 GTK 和 C 创建一个界面。我在我的界面中放置了一个条目文本,用户将只键入数字。我需要获取输入的数字以便稍后使用。但是,使用函数 gtk_entry_get_text 会将输入的文本存储在 const gchar 变量中。我怎样才能得到用户输入的数字?

获取文本的代码是:

static void ok_clicked(GtkWidget *widget, GtkWidget *entry){ 
const gchar *get_text; 
get_text = gtk_entry_get_text(GTK_ENTRY(entry)); 
printf("entry contents: %s\n",get_text); }

你可以使用 guint64 g_ascii_strtoll (const gchar *nptr,gchar **endptr,guint base); 它将字符串转换为 gint64 值。此函数的行为类似于 C 语言环境中的标准 strtoll() 函数。对于双倍你可以使用

gdouble g_ascii_strtod (const gchar *nptr, gchar **endptr); I hope this helps.