更改结构中的数据

更改结构中的数据

我试图编写一个函数来更改结构中的数据。这是我的代码的一部分。

#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<unistd.h>
#include<pthread.h>
#include<sys/types.h>
#define THREADNUM 20

pthread_mutex_t DeviceMutex ;
struct VirtualPCB
{
    int tid;
    int handlePriority;
    int arrivetime;
    int waittime;
    int runtime;
    int visited;
    int tempruntime;
    int finishtime;
}PCBs[THREADNUM];


void initPCB()
{
    int n;
    srand(time(NULL));
    for(n =0;n<THREADNUM;n++)
    {

        PCBs[n].tid = n + 1;
        PCBs[n].handlePriority = 1 + rand()%19;
        PCBs[n].arrivetime = 1 + rand()%19;
        PCBs[n].tempruntime=PCBs[n].runtime = 1 + rand()%19;
        PCBs[n].waittime = 0;
        PCBs[n].visited =0;
        PCBs[n].finishtime = PCBs[n].arrivetime + PCBs[n].runtime;
    }
}

void change(PCBs[THREADNUM],int i, int j)
{
    int temp;
    temp = PCBs[i].arrivetime;
    PCBs[i].arrivetime = PCBs[j].arrivetime;
    PCBs[j].arrivetime = temp;
    temp = PCBs[i].runtime;
    PCBs[i].runtime = PCBs[j].runtime;
    PCBs[j].runtime = temp;
    temp = PCBs[i].finishtime;
    PCBs[i].finishtime = PCBs[j].finishtime;
}

但有一个错误。
“错误:需要声明说明符或…”
PCBs之前。我在网上搜索过,但找不到有效的方法。你能告诉我怎么纠正吗?

最佳答案

函数定义的语法错误。你需要改变

  void change(PCBs[THREADNUM],int i, int j) { ....


  void change(struct VirtualPCB PCBs[THREADNUM],int i, int j) { ...


void change(struct VirtualPCB PCBs[ ],int i, int j) {....

10-07 18:53