Try to search your question here, if you can't find : Ask Any Question Now ?

change data in struct

HomeCategory: stackoverflowchange data in struct
Avatarpragati asked 5 months ago

I try to write a function to change data in a struct. Here are part of my code.

#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;
}

but there is an error.

“error:expected declaration specifier or ‘…’

before PCBs. I have searched the Internet, but I can not find an effective way. Can you tell me how to correct them?

1 Answers
Best Answer
AvatarArben answered 5 months ago
Your Answer

3 + 18 =

Popular Tags

WP Facebook Auto Publish Powered By : XYZScripts.com