GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Dec 23, 2014 4:27 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Comparing Two Strings
PostPosted: Wed Jan 09, 2008 10:39 pm 
Offline
Familiar Face

Joined: Tue Jan 08, 2008 7:39 pm
Posts: 9
I'm trying to compare two strings in my program and even though the strings are the same, it fails the test.

Code:
   if(curr->next == NULL)
      if(g_ascii_strcasecmp(status_and_combo->data->name, selected_name))
         return status_and_combo->data->mem_add;
        return NULL;


Each time run, it will skip the nested return and return NULL;
Both g_ascii_strcasecmp and g_strcasecmp give the same result. I understand that g_strcasecmp should not be used anymore, so I was wondering if there was any other way to compare. All the letters are ascii so I assumed that g_ascii_strcasecmp would work.

status_and_combo looks as such:
Code:
typedef struct status_and_widget {
   GtkWidget *widget;
   GtkWidget *status_bar;
   bt_node *data;
   gchar* current_selected;
} status_trans;


data looks as such:
Code:
typedef struct bluetooth_node {
   char*            name;
   char*            mem_add;
   struct bluetooth_node*   next;
} bt_node;


and selected_name is a const gchar*.

The only thing I can think that would cause it to fail is that one is a const gchar* and one is a char*. I have attempted to cast the data->name as a const gchar* and that did not work.

If anyone knows what is happening and why it will not work, it would be appreciated.

Thanks
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 09, 2008 11:38 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
1. You can use g_str_equal() which returns a boolean value.
2. g_ascii_strcasecmp() returns 0 if the strings match. A 0 is the same as FALSE. Therefore, you want your if statement to look like:

Code:
if (g_ascii_strcasecmp(status_and_combo->data->name, selected_name) == 0)
            return status_and_combo->data->mem_add;

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 10, 2008 1:17 am 
Offline
Familiar Face

Joined: Tue Jan 08, 2008 7:39 pm
Posts: 9
g_str_equal() works perfectly, thanks.

Brian


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group