49 Pnode read_txt(FILE *fp,Pnode p1)//从文件指针fp读取两行内容,分别存储在a1,b两个固定长度数组 50 { int i,m,n; 中,然后动态申请两段内存存储a1,b中的字符串 51 char a1[40] = {0}; 52 char b[100] = {0}; 53 fgets(a1,40,fp); 54 fgets(b,100,fp); 55 i = strlen(a1); 56 n = strlen(b); 57 p1->word_length = i-2; 58 p1->trans_length = n; 59 p1->word = (char*)malloc((i-2)*sizeof(char)); 60 p1->trans = (char*)malloc(n*sizeof(char)); 61 for(m = 0;m < i-2;m++) 62 { 63 (p1->word)[m] = a1[m+1]; 64 } 65 strcpy(p1->trans,b); 66 } 67 68 int insert_txt_after(Pdict p)//构建哈希链表,把fp指针文件中的内容按照每两行内容建立一个结点,存 69 { 到哈希链表中 70 FILE *fp = fopen(FILE_PATH,"r"); 71 int d = 0; 72 if(fp == NULL) 73 { 74 printf("open error\n"); 75 exit(0); 76 } 77 while(!feof(fp)) 78 { 79 Pnode p1 = create_node(); 80 read_txt(fp,p1); 81 d = hash_func(p1->word); 82 insert_list(p->a[d],p1); 83 } 84 fclose(fp); 85 return 0; 86 }但是程序运行一段时候后,出现了内存错误a.out: malloc.c:2451: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) == 0)' failed经检查是59行出现问题,读取到固定单词出现错误如上,文件格式:#wordTrans:单词。。。