Radix Tree C程序中的总线错误10

时间:2015-04-25 21:30:22

标签: c trie radix

我正在编写一个程序,它在Radix trie上执行操作,而我遇到了add()函数,导致总线错误为10.

void addRec(struct tNode *p, char *w) {

  int matches = prefixMatch(p->word,w);

  bool insert = true;

  if ((p == root) || 
  ((matches > 0) && (matches < strlen(w)) && (matches == strlen(p->word)))) {


    char *updatedWord = &w[matches];    
    printf("%s\n", updatedWord);

    struct tNode *tmp = p->child;
    while (tmp != NULL) {
      if (tmp->word[0] == updatedWord[0]) {
        insert = false;
        addRec(tmp, updatedWord);
      }
      tmp = tmp->brother;
    }
    if (insert) {
      addChild(p,updatedWord);
    } 
    } else if ((matches > 0) && (matches == strlen(w)) && (matches == strlen(p->word))) {
    if (p->count < 0) p->count = ++globalCount;
    else printf("ignored");
    } else if ((matches > 0) && (matches < strlen(w)) && (matches < strlen(p->word))) {
    struct tNode *tmp = malloc(sizeof(struct tNode));
    tmp->word = &p->word[matches];
    p->word[matches+1] = '\0';
    tmp->child = p->child;
    tmp->count = p->count;
    tmp->brother = NULL;
    p->child = tmp;
    p->count = -1;

  } 


}

错误似乎在while循环内部,但我无法弄清楚究竟错误的位置和错误。请帮忙。

0 个答案:

没有答案