C 为什么我的主表在传递给函数时会被重置?

C 为什么我的主表在传递给函数时会被重置?,c,hash,C,Hash,我正在实现一个哈希表,它应该存储指向包含单词及其到特定语言的翻译的节点链表的指针 为此,我从文本文件中读取单词,将它们加载到节点中,对它们进行散列,然后插入到表中。在init函数的末尾,我可以看到通过ddd正确初始化的表。但是,当调用main中的下一个函数并传递表时,它实际上只发送指向空节点而不是表的指针。它去哪里了?它的地址变了吗?传递给函数时是否创建了新指针 //main.c //Cellule definition typedef struct cellule{ char * m

我正在实现一个哈希表,它应该存储指向包含单词及其到特定语言的翻译的节点链表的指针

为此,我从文本文件中读取单词,将它们加载到节点中,对它们进行散列,然后插入到表中。在init函数的末尾,我可以看到通过ddd正确初始化的表。但是,当调用main中的下一个函数并传递表时,它实际上只发送指向空节点而不是表的指针。它去哪里了?它的地址变了吗?传递给函数时是否创建了新指针

//main.c

//Cellule definition
typedef struct cellule{
    char * mot;
    char * trad;
    struct cellule * suiv;
}cellule_t;

//Init and Search

cellule_t * rechercheTable(cellule_t ** tab, const char * mot){
    int ind=hash_string(mot);
    cellule_t * cour = tab[ind];
    bool trouve=false;

    while(cour!=NULL && trouve==false){
        if(cour->mot==mot){
            trouve=true;
        }
        else cour=cour->suiv;
    }
    return cour;
}

void initTable(cellule_t ** t){
    FILE    *   fichier;
    cellule_t *cour;
    char ligne[60];
    char * sep;
    int i,ind;

    for(i=0;i<HASH_MAX;i++){
        t[i]=NULL;
    }

    fichier = fopen("anglais.txt","r");
    if(fichier)
    {
        fscanf(fichier,"%s",ligne);
        while(!feof(fichier))
        {
                cour=(cellule_t *)malloc(sizeof(cellule_t));

                sep=strtok(ligne,";");
                cour->mot=(char *)malloc(sizeof(char)*(((int)strlen(sep))+1));          
                if(sep!=NULL)
                strcpy(cour->mot,sep);
                ind=hash_string(sep);

                sep=strtok(NULL,"\n");
                if(sep!=NULL){
                    cour->trad=(char *)malloc(sizeof(char)*(((int)strlen(sep))+1));
                    strcpy(cour->trad,sep);
                }
                cour->suiv=t[ind];
                t[ind]=cour;
                fscanf(fichier,"%s",ligne);
        }
        fclose(fichier);
    }
}

int main(){
    cellule_t * tableMajeure[HASH_MAX];
    cellule_t * cour;
    initTable(tableMajeure);
    cour = rechercheTable(tableMajeure,"hello");
    printf("Resultat de la recherche de hello : %s \n",cour->mot);
    return 0;
}
//main.c
//细胞定义
类型定义结构单元{
char*mot;
char*trad;
结构细胞*suiv;
}细胞;
//初始化和搜索
单元*rechercheTable(单元**选项卡,常量字符*mot){
int ind=散列字符串(mot);
Cellle_t*cour=制表符[ind];
bool-trouve=false;
while(cour!=NULL&&trove==false){
如果(cour->mot==mot){
trouve=真;
}
else cour=cour->suiv;
}
回报率;
}
无效初始表(单元**t){
文件*fichier;
细胞膜;
木炭[60];
char*sep;
int i,ind;
对于(i=0;imot=(char*)malloc(sizeof(char)*)((int)strlen(sep))+1));
如果(sep!=NULL)
strcpy(cour->mot,sep);
ind=散列字符串(sep);
sep=strtok(空,“\n”);
如果(sep!=NULL){
cour->trad=(char*)malloc(sizeof(char)*((int)strlen(sep))+1));
strcpy(cour->trad,sep);
}
cour->suiv=t[ind];
t[ind]=cour;
fscanf(fichier,“%s”,ligne);
}
fclose(fichier);
}
}
int main(){
赛璐珞t*表[HASH_MAX];
细胞膜;
初始表格(表格);
cour=rechercheTable(表“你好”);
printf(“你好结果:%s\n”,cour->mot);
返回0;
}
Tl;dr:为什么表从Init出来很好,但传递给Recherche的却是空的?
感谢您的帮助

请提供一个。此代码非常不完整。未定义的符号包括:
hash\u string
bool
false
NULL
FILE
hash\u MAX
。问题出现在行
if(cour->mot mot=mot)
。无法将字符串与
==
进行比较。请使用
strcmp
来比较字符串。@user3386109 deal!如果确实使用
fgets
,请确保。