c程序为什么在windows里运行可以,到linux下就有错误?帮我一下
在线等待,路过的请留下点建议,呵呵,谢谢了!错误如下:
hao@hao-laptop:~/c$ gcc -o procpcb procpcb.c
procpcb.c:24: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:29: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:43: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:54: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:61: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:76: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:105: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:121: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c:139: 错误: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
procpcb.c: 在函数 ‘main’ 中:
procpcb.c:186: 错误: 在 C99 模式之外使用 ‘for’ 循环初始化声明
procpcb.c:175: 警告: ‘main’ 的返回类型不是 ‘int’
源程序如下:
#include<stdio.h>
#include<malloc.h>
typedef char ElemType;
struct PCB
{
int name;
int priority;//优先级别0最小
int procID;//PROCESS ID
int source;//-1:WAITING SOURCE,0:HOLDING SOURCE
int statue;//-1:BLOCKED,0:RUNNING,1:READY
}procPCB;
typedef struct qnode
{
//ElemType data;
struct PCB data;
struct qnode *next;
}QNode;
typedef struct
{
QNode *front;
QNode *rear;
}LiQueue;
void InitQueue(LiQueue *&q)
{
q=(LiQueue*)malloc(sizeof(LiQueue));
q->front=q->rear=NULL;
}
void ClearQueue(LiQueue *&q)
{
QNode *p=q->front,*r;
if(p!=NULL)
{
r=p->next;
while(r!=NULL)
{
free(p);
p=r;r=p->next;
}
}
free(q);
}
int QueueLength(LiQueue *&q)
{
int n=0;
QNode *p=q->front;
while(p!=NULL)
{
n++;
p=p->next;
}
return(n);
}
int QueueEmpty(LiQueue *&q)
{
if(q->rear==NULL)
return 1;
else
return 0;
}
void enQueue(LiQueue *&q,PCB e)
{
QNode *s;
s=(QNode *)malloc(sizeof(QNode));
s->data=e;
s->next=NULL;
if(q->rear==NULL)
q->front=q->rear=s;
else
{
q->rear->next=s;
q->rear=s;
}
}
int dispatch(LiQueue *&q,PCB &e,int &f)
{
QNode *t;
if(q->rear==NULL)
return 0;
if(f==1)
{
printf("cpu繁忙\n");
return 0;
}
if(q->front==q->rear)
{
t=q->front;
q->front=q->rear=NULL;
}
else
{
t=q->front;
q->front=q->front->next;
}
e=t->data;
free(t);
printf("进程%d出就绪队列,ID号为%d,",e.name,e.procID);
printf("进程进驻CPU,RUNNING\n");
f=1;
return 1;
}
void timeout(LiQueue *&q,PCB e,int &f)
{
QNode *s;
s=(QNode *)malloc(sizeof(QNode));
s->data=e;
s->next=NULL;
if(q->rear==NULL)
q->front=q->rear=s;
else
{
q->rear->next=s;
q->rear=s;
}
printf("进程%d时间片用尽,入就绪队列,ID号为%d,进行进程调度\n",e.name,e.procID);
f=0;//释放cpu
}
void waitevent(LiQueue *&q,PCB e,int &f)
{
QNode *s;
s=(QNode *)malloc(sizeof(QNode));
s->data=e;
s->next=NULL;
if(q->rear==NULL)
q->front=q->rear=s;
else
{
q->rear->next=s;
q->rear=s;
}
printf("进程%d等待资源,入等待队列,ID号为%d,进行进程调度\n",e.name,e.procID);
f=0;//释放cpu
}
int eventoccurs(LiQueue *&q,LiQueue *&p,PCB &e)
{
QNode *t; //出队列
if(q->rear==NULL)
return 0;
if(q->front==q->rear)
{
t=q->front;
q->front=q->rear=NULL;
}
else
{
t=q->front;
q->front=q->front->next;
}
e=t->data;
free(t);
printf("进程%d资源到来,出等待队列,ID号为%d\n",e.name,e.procID);
QNode *s; //入队列
s=(QNode *)malloc(sizeof(QNode));
s->data=e;
s->next=NULL;
if(p->rear==NULL)
p->front=q->rear=s;
else
{
p->rear->next=s;
p->rear=s;
}
printf("进程%d入就绪队列,ID号为%d\n",e.name,e.procID);
return 1;
}
void main()
{
LiQueue *WQ;
LiQueue *RQ;
InitQueue(WQ);
InitQueue(RQ);
struct PCB pcb[50];
struct PCB procpcb,runpcb;
int a,b;
int f=0;//cpu标志0表示空闲,0表示繁忙
printf("输入系统进程数最大不超过50: ");
scanf("%d",&b);
for(int i=0;i<b;i++)
{
//printf("进程%d入等待队列,ID号为%d\n",i,i);
pcb[i].name=i+1;
pcb[i].priority=0;//暂无优先级
pcb[i].procID=i+100;
pcb[i].source=0;
pcb[i].statue=1;
enQueue(RQ,pcb[i]);//初始化时进程都在就绪队列中
printf("进程%d入就绪队列,ID号为%d\n",pcb[i].name,pcb[i].procID);
}
printf("输入命令控制进程:1:调度进程入CPU 2:时间片用尽 3: 等待资源 4:资源到来 5:退出\n");
do{
scanf("%d",&a);
switch(a)
{
case 1:
dispatch(RQ,procpcb,f);
break;
case 2:
timeout(RQ,procpcb,f);
dispatch(RQ,procpcb,f);
break;
case 3:
waitevent(WQ,procpcb,f);
dispatch(RQ,procpcb,f);
break;
case 4:
eventoccurs(WQ,RQ,procpcb);
break;
case 5:
//exit(0);
break;
}
}while(a!=5);
ClearQueue(RQ);
ClearQueue(WQ);
}