0

我正在编写一个对 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 循环内的某个地方,但我无法弄清楚到底哪里出了问题。请帮忙。

4

0 回答 0