Jsem se nudil :-)
#include <stdio.h> #include <glib.h>
int main() {
FILE *f = fopen("in.txt", "rt"); if (!f) { fprintf(stderr, "Cannot open in.txt"); return 1; }
GHashTable *table; table = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free);
while(!feof(f)) { int i; char s[100]; fscanf(f, "%x %s", &i, s); printf("%x, %s\n", i, s); g_hash_table_insert(table, GINT_TO_POINTER(i), g_strdup(s)); } printf("Zadej hexa klic: "); int i; scanf("%x", &i); char* p = g_hash_table_lookup(table, GINT_TO_POINTER(i)); if (p) { printf("\n\n%s\n", p); } else { printf("\n\n%s\n", "Neni"); }
g_hash_table_destroy(table); return 0; }
|