Re: Trimming GtkEntry Text
- From: John K Luebs <jkluebs luebsphoto com>
- To: Tony Freeman <tony freeman insightbb com>
- Cc: gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Trimming GtkEntry Text
- Date: Thu, 21 Dec 2006 23:12:03 -0500
On Thu, Dec 21, 2006 at 10:26:05PM -0500, Tony Freeman wrote:
Hello,
I have two problems I'm trying to work through that maybe someone here
can help me with.
I have a GtkEntry called a 'custom_command_entry'. I would like to trim
white space from the beginning and end of what a user may enter in this
field. custom_command_entry is a global.
This is what I have so far:
void on_executebutton_clicked (GtkWidget *widget, gpointer data)
{
const gchar *custom_command;
gchar *entry_wfo1, *entry_wfo2;
/* GET THE BACKUP WFO SELECTION */
entry_wfo1 = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox1));
/* GET THE LOCALIZED WFO SELECTION */
entry_wfo2 = gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox2));
/* GET THE CUSTOM COMMAND */
custom_command =
g_strdup(gtk_entry_get_text(GTK_ENTRY(custom_command_entry)));
g_strstrip(custom_command);
if (custom_command == NULL || sizeof(custom_command) <= 0) {
sizeof(custom_command) is the sizeof a const gchar* which will always
be greater than 0.
custom_command will never be NULL. As far as I know, the
defined behavior for g_strdup is to abort or somehow terminate
the application if the necessary memory allocation failed.
So, yes, the condition will always be false.
What you probably want to do is a simple strcmp(custom_command, "").
Also, don't forget to free custom_command.
-jkl
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]