我試圖增加一些特定鍵的值,如果它被發現。出於某種原因,當我從哈希表中轉儲所有keys:values
時,我總是得到(指針)地址。GLib散列表 - 指針
Output
a: 153654132 // should be 5
b: 1
c: 153654276 // should be 3
d: 1
e: 1
f: 153654420 // should be 3
int proc()
{
struct st stu;
gpointer ok, ov;
//... some non-related code here
if(!g_hash_table_lookup_extended(table, key, &ok, &ov)){
stu.my_int = g_malloc(sizeof(guint));
*(stu.my_int) = 0;
g_hash_table_insert(table, g_strdup(key), GINT_TO_POINTER(1));
}else{
stu.my_int = g_malloc(sizeof(guint));
*(stu.my_int)++;
g_hash_table_insert(table, g_strdup(key), stu.my_int);
}
}
任何想法將不勝感激。
FIXED:我取代所述第二插入件爲: (OV )++; g_hash_table_insert(table,g_strdup(key),ov); – Mike 2010-03-08 03:37:25