C 与指针和链表删除函数不兼容的类型
我得到了这个错误。请帮忙 3.c:在主功能中: 3.c:92:错误:从类型prcmd\u t分配给类型struct prcmd\u t*时,类型不兼容C 与指针和链表删除函数不兼容的类型,c,linked-list,C,Linked List,我得到了这个错误。请帮忙 3.c:在主功能中: 3.c:92:错误:从类型prcmd\u t分配给类型struct prcmd\u t*时,类型不兼容 #include <stdio.h> #include <pthread.h> #include <time.h> #include <stdlib.h> typedef struct pr_struct{ int owner; int burst_time;
#include <stdio.h>
#include <pthread.h>
#include <time.h>
#include <stdlib.h>
typedef struct pr_struct{
int owner;
int burst_time;
struct pr_struct *next_prcmd;
} prcmd_t;
static prcmd_t *pr_head = NULL;
static prcmd_t *pr_tail = NULL;
static int pending_request = 0;
static pthread_mutex_t prmutex = PTHREAD_MUTEX_INITIALIZER;
int add_queue(prcmd_t *node)
{ pthread_mutex_lock(&prmutex);
//code
prcmd_t *curNode = pr_head;
if(pr_head == NULL) { pr_head = node; return;}
while(curNode->next_prcmd)
{
curNode = curNode->next_prcmd;
}
curNode->next_prcmd = node;
//
pending_request++;
pthread_mutex_unlock(&prmutex);
return(0);
}
**//inprogress
int remove_queue(prcmd_t **node)
{
printf("prenull");
pthread_mutex_lock(&prmutex);
prcmd_t *tempNode;
if(node == NULL)
{
//your code
printf("Queue is empty");
//
pthread_mutex_unlock(&prmutex);
return(-1);
}
else
{
printf("in else");
//your code
tempNode =(*node)->next_prcmd;
free(node);
//
pending_request--;
pthread_mutex_unlock(&prmutex);
return(0);
}
}
//end progress**
int main()
{
if (pr_head == NULL)
{
printf("List is empty!\n\n");
}
int i=0;
int length = 4;
prcmd_t *pr[length];
for(i =0;i<length;i++)
{
pr[i] = (prcmd_t*)malloc(sizeof(prcmd_t));
pr[i]->owner = i+1;
pr[i]->burst_time = i + 2;
add_queue(pr[i]);
}
prcmd_t *curNode = pr_head;
while(curNode)
{
printf("%i %i\n", curNode->owner,curNode->burst_time);
curNode = curNode->next_prcmd;
}
**//something is messed up here i think.
curNode = *pr_head;
remove_queue(&curNode);
//**
while(curNode)
{
printf("%i %i\n", curNode->owner,curNode->burst_time);
curNode = curNode->next_prcmd;
}
}
#包括
#包括
#包括
#包括
类型定义结构pr_结构{
业主;
int突发时间;
结构pr_结构*next_prcmd;
}prcmd_t;
静态prcmd_t*pr_head=NULL;
静态prcmd_t*pr_tail=NULL;
静态int挂起_请求=0;
静态pthread\u mutex\u t prmutex=pthread\u mutex\u初始值设定项;
int add_队列(prcmd_t*节点)
{pthread_mutex_lock(&prmutex);
//代码
prcmd_t*curNode=pr_头;
if(pr_head==NULL){pr_head=node;return;}
while(curNode->next_prcmd)
{
curNode=curNode->next\u prcmd;
}
curNode->next_prcmd=node;
//
挂起的_请求++;
pthread_mutex_unlock(&prmutex);
返回(0);
}
**//进展中
int remove_队列(prcmd_t**节点)
{
printf(“prenull”);
pthread_mutex_lock(&prmutex);
prcmd_t*临时节点;
if(node==NULL)
{
//你的代码
printf(“队列为空”);
//
pthread_mutex_unlock(&prmutex);
返回(-1);
}
其他的
{
printf(“在其他情况下”);
//你的代码
tempNode=(*node)->next_prcmd;
自由(节点);
//
待决的请求--;
pthread_mutex_unlock(&prmutex);
返回(0);
}
}
//结束进程**
int main()
{
if(pr_head==NULL)
{
printf(“列表为空!\n\n”);
}
int i=0;
整数长度=4;
prcmd_t*pr[长度];
对于(i=0;所有者=i+1;
pr[i]->突发时间=i+2;
添加_队列(pr[i]);
}
prcmd_t*curNode=pr_头;
while(curNode)
{
printf(“%i%i\n”,curNode->owner,curNode->burst\u time);
curNode=curNode->next\u prcmd;
}
**//我想这里有点混乱。
curNode=*pr_头;
删除队列(&curNode);
//**
while(curNode)
{
printf(“%i%i\n”,curNode->owner,curNode->burst\u time);
curNode=curNode->next\u prcmd;
}
}
curNode的类型为prcmd\u t*
(指针指向prcmd\u t),而pr\u head
的类型也为prcmd\u t*
,因此它们处于相同的引用级别,但您试图将pr\u head
(类型为prcmd\u t
)所指的值分配给curNode
(类型为prcmd\u t*
)这就是不兼容
我不清楚您想做什么,但正确的语法是
curNode = pr_head;
或
curNode的类型为
prcmd\u t*
(指向prcmd\u t的指针),而prcmd\u头
的类型也为prcmd\u t*
,因此它们处于相同的参考级别,但您试图将prcmd头
(类型为prcmd\u t
)指向curNode
(类型为prcmd\u t*/code>)这就是不相容性
我不清楚您想做什么,但正确的语法是
curNode = pr_head;
或