Saturday, 17 August 2013

I cant get the result with g_hash_table_look_up

I cant get the result with g_hash_table_look_up

//here is my code,i want to use string for key ,and find my value,my value
mustbe a pointer. Thanks for help!
#include <stdio.h>
#include <glib.h>
int main()
{
GHashTable *hash_list; ///denfine my hashtable
char str1[32];
sprintf(str1, "key");
char str2[32];
sprintf(str2, "key");
hash_list = g_hash_table_new(g_str_hash, g_direct_equal); ///create my
hashtable
g_hash_table_insert(tcp_stream_list, str1, "ssssssssssssssss");
///insert my key and value
char *c = (char*) g_hash_table_lookup(tcp_stream_list, (str2)); ///find
my key
if (c)
{
printf("%s\n", c); ///print the string
}
return 0;
}

No comments:

Post a Comment