gpt4 book ai didi

c - 从不兼容的指针类型 struct c 赋值

转载 作者:太空宇宙 更新时间:2023-11-04 04:25:06 25 4
gpt4 key购买 nike

我正在学习 C 中的结构和指针。我尝试使用节点表来创建哈希函数。我仍然收到警告。我一直在寻找答案,但找不到。

主要内容:

int *T[N];
inittab(T);
chhinsert(T,206);

结构:

typedef struct{
int key;
struct node *next;
}node;

功能:

void chhinsert(int **T,int k){
node *x=NULL;
x=(node*)malloc(sizeof(node));
x->next=NULL;
x->key=k;
int p=h(k);
//two lines below generates warning: assignment from incompatible pointer type
x->next=T[p];
T[p]=x;
}

我也试过

typedef struct node{...}node;

然后

void chhinsert(int **T,int k){
struct node *x=NULL;
x=(node*)malloc(sizeof(node));
x->next=NULL;
x->key=k;
int p=h(k);
x->next=T[p];
T[p]=x;
}

每次我将 x 分配给表中的值,反之亦然,都会显示警告

最佳答案

void chhinsert(int **T,int k) 行中,您将 T 声明为指向 int 的指针,而不是指针到节点。将您的声明更改为 void chhinsert(struct node **T,int k)

关于c - 从不兼容的指针类型 struct c 赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42468690/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com