fork download
  1. #include <glib-2.0/glib.h>
  2.  
  3. #define btoa(x) ((x) ? "TRUE" : "FALSE")
  4.  
  5. int main(int argc, char** argv) {
  6. GHashTable* hash = g_hash_table_new((GHashFunc)g_string_hash,
  7. (GEqualFunc)g_string_equal);
  8. g_hash_table_insert(hash, g_string_new("Key1"), g_string_new("val1"));
  9. g_hash_table_insert(hash, g_string_new("Key2"), g_string_new("val2"));
  10. g_hash_table_insert(hash, g_string_new("Key3"), g_string_new("val3"));
  11. g_hash_table_insert(hash, g_string_new("Key4"), g_string_new("val4"));
  12. g_hash_table_insert(hash, g_string_new("Key5"), g_string_new("val5"));
  13. /* キーのリスト */
  14. GList* keys = g_hash_table_get_keys(hash);
  15. /* 値のリスト */
  16. GList* values = g_hash_table_get_values(hash);
  17. /* 位置の対応関係はあるか? */
  18. for (gsize i = 0; i < g_list_length(keys); i++) {
  19. g_print("%s\n", btoa(g_string_equal((GString*)g_hash_table_lookup(hash, g_list_nth_data(keys, i)), (GString*)g_list_nth_data(values, i))));
  20. }
  21. g_list_free(keys);
  22. g_list_free(values);
  23. g_hash_table_destroy(hash);
  24. return EXIT_SUCCESS;
  25. }
  26.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:10: fatal error: glib-2.0/glib.h: No such file or directory
 #include <glib-2.0/glib.h>
          ^~~~~~~~~~~~~~~~~
compilation terminated.
stdout
Standard output is empty