使用链表从链表的头部提取数据。数据已经在 Head 中设置,但是当我尝试访问它时,我得到了那个错误。认为指针有问题,但我无法解决。
int main(int argc, char **argv)
{
int i;
struct timeval start, end;
struct element *Head = NULL;
struct element *Tail = NULL;
//creating job queue
for (i = 0; i < NUMBER_OF_JOBS; i++) {
addLast(generateProcess(), &Head, &Tail);
}
//go through job queue running processes and removing processes
while (Head) {
runPreemptiveJob(Head->pData, &start, &end);
int responseTime = getDifferenceInMilliSeconds(Head->pData->oTimeCreated, start);
printf("Response Time is: %d\n", responseTime);
Head = Head->pNext;
}
}
我希望能够通过 head 元素访问 oTimeCreated 中的数据,该元素在其数据字段中具有结构。
错误是在调用 getDifferenceInMilliSeconds 函数时:我在 Head 上收到一个错误,上面写着“表达式必须具有指向结构或联合类型的指针。
元素显示在这里:
struct element
{
void * pData;
struct element * pNext;
};
generateProcess() 返回一个结构体过程,定义如下:
struct process
{
int iProcessId;
struct timeval oTimeCreated;
struct timeval oMostRecentTime;
int iInitialBurstTime;
int iPreviousBurstTime;
int iRemainingBurstTime;
int iPriority;
};
在主函数中,generateProcess() 返回一个指向进程的指针。该指针被放入链接列表中,因此我试图访问 oTimeCreated 变量,该变量是该结构的一部分,该结构是列表的头部。