在编译我的代码时,我崩溃了错误分段错误(核心转储)..你可以帮助我吗? 我第一次使用glib.h,我认为我的错误在于代码的那部分。在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);
}