GLib Hash Table - Pointer

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-08T02:49:16Z Indexed on 2010/03/08 3:51 UTC
Read the original article Hit count: 348

Filed under:
|
|

I'm trying to increment the value of some specific key if it was found. For some reason I keep getting the (pointer) address when I dump all keys:values from the hash table.

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);
    }   
}

Any ideas will be appreciate it.

© Stack Overflow or respective owner

GLib Hash Table - Pointer

Posted by Mike on Stack Overflow See other posts from Stack Overflow or by Mike
Published on 2010-03-08T02:49:16Z Indexed on 2010/03/08 3:02 UTC
Read the original article Hit count: 348

Filed under:
|
|

I'm trying to increment the value of some specific key if it was found. For some reason I keep getting the (pointer) address when I dump all keys:values from the hash table.

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(ht, 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);
    }   
}

Any ideas will be appreciate it.

© Stack Overflow or respective owner

Related posts about glibc

Related posts about gtk