我正在执行一个C程序,我收到警告: 警告:从不兼容的指针类型
分配我正在复制相关代码:
//Structure I am using:
typedef struct graph_node
{
int id;
int weight;
struct node *next;
}node, dummy;
node *head[10];
// Function which is generating this warning:
void print_list()
{
int i;
for (i = 0;i< vertex; i++)
{
printf ("\n ==>>%d ", head[i]->id);
while (head[i]->next != NULL)
{
head[i] = head[i]->next;
printf ("\t ==>>%d ", head[i]->id); /******This line is generating warning ********/
}
}
}
上面的代码编译好了,抛出下面的警告:
警告:从linklist数组的不兼容指针类型分配
答案 0 :(得分:2)
答案 1 :(得分:0)
检查这段代码。我认为它可能会工作。并发布完整的代码,以便我可以解决完整的问题。
typedef struct graph_node
{
int id;
int weight;
struct node *next;
}node, dummy;
node *head[10];
// Function which is generating this warning:
void print_list()
{
int i;
for (i = 0;i< vertex; i++)
{
printf ("\n ==>>%d ", head[i]->id);
while (head[i]->next->next != NULL)
{
head[i] = head[i]->next;
printf ("\t ==>>%d ", head[i]->id);
if(head[i]->next==NULL)
{
printf ("\t ==>>%d ", head[i]->id);
}
}
}
}