| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1217 人关注过本帖
标题:c程序为什么在windows里运行可以,到linux下就有错误?帮我一下
只看楼主 加入收藏
justholdon
Rank: 1
等 级:新手上路
威 望:2
帖 子:69
专家分:0
注 册:2007-4-23
收藏
 问题点数:0 回复次数:2 
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);

}
搜索更多相关主题的帖子: windows token procpcb linux expected 
2008-03-26 16:06
VxWorks
Rank: 3Rank: 3
来 自:WindRiver
等 级:论坛游民
威 望:6
帖 子:859
专家分:68
注 册:2007-11-24
收藏
得分:0 
用这个命令编译:
 g++ -o procpcb procpcb.c

为了防止世界被破坏,为了守护世界的和平,贯彻爱与真实的邪恶,可爱又迷人的反派角色,VxWorks!
Don't ask me any question.I'm just here to buy soy sauce.
2008-03-26 16:12
justholdon
Rank: 1
等 级:新手上路
威 望:2
帖 子:69
专家分:0
注 册:2007-4-23
收藏
得分:0 
太谢谢你了 我真的不知道该说什么好了
我刚刚发完帖子你就给我解答了
真的 谢谢了

just hold on !
2008-03-26 16:23
快速回复:c程序为什么在windows里运行可以,到linux下就有错误?帮我一下
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017578 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved