- 论坛徽章:
- 0
|
环境:RedHat 9
代码:
int main()
{
char str[2000];
FILE * fp;
int i,j;
fp=fopen("./meta.dat","wb");
if(fp=NULL)
{
printf("open meta.dat failed\n");
return -1;
}
struct hashTable * ht = (struct hashTable *)malloc(sizeof(struct hashTable));
ht->count = 0;
ht->next = NULL;
ht->AnodeType= lh_strhash(str);
struct hashTable * list;
memset(str,0,sizeof(str));
strcat(str,"ab");
for(i=1; i<11; i++)
{
for(j = 0;j<10; j++)
{
hashTableInsert(str, (unsigned int)(i*100+j), ht);
}
strcat(str,"ab");
}
list = ht->next;
for(; list->next!=NULL;list=list->next)
{
fwrite(list,sizeof(struct hashTable),1,fp); <---程序到这里发生错误
}
printf("writing to disk````\n"); //按道理说list已经是一个指针,传应该是没问题的了,但是怎么就出错了?
//还是我理解错误传递了错误的参数呢?那应该怎么传?
for(ht->next; ht->next!=NULL;ht->next=ht->next->next)
{
free(ht);
}
}
编译成功,但是运行时出错,用gdb调试提示:
fwrite(list,sizeof(struct hashTable),1,fp);
Program received signal SIGSEGV, Segmentation fault.
ox42062986 in fwrite() from /lib/tls/libc.so.6
有人遇过这样或类似的问题吗?有的请通传一声,谢谢了
在线等
[ 本帖最后由 hinku 于 2007-5-27 00:14 编辑 ] |
|