0

I crushed with the error segmentation fault (core dumped) while compiling my code.. can you help me with that? I'm using glib.h for the first time, I think my error is in that part of code. while using pointers in Ghash.

# include <stdio.h>
# include <glib.h>

char filename[] = "blacklist";

char *t = filename;

FILE * fi;
FILE * fi2;
FILE * fo;

GHashTable *hash = g_hash_table_new(g_str_hash,g_str_equal);

void load_domain_black_list(char *t)
{
    fi = fopen(t,"r");
    char *s;
    while(1)
    {
        fscanf(fi,"%s",s);

        if(feof(fi)>0) break;

        g_hash_table_add(hash,s);
    }
    fclose(fi);
}

int check_domain_blacklist(char *domain)
{
    return g_hash_table_contains(hash,domain);
}

main()
{
    fi2 = fopen("domains_for_check","r");
    fo = fopen("result","w");

    load_domain_black_list(t);

    char *domain;

    while(1)
    {
        fscanf(fi2,"%s",domain);

        if(feof(fi2)>0)
            break;

        fprintf(fo,"%d",check_domain_blacklist(domain));
    }

    fclose(fi2);
    fclose(fo);
}
merdan
  • 3
  • 2

0 Answers0