m0_58115587 2022-06-07 23:38 采纳率: 0%
浏览 591

C语言报错expected unqualifiled-id before’while‘怎么解决

C语言遇到报这个错误要怎么改while ((temp=PopReady())!=-1)这句一运行就报错expected unqualifiled-id before’while‘

#include<stdio.h>
#include<windows.h>
#define N 10
#define SLOT 5
typedef enum
{
Running,
Aready,
Blocking
} ProStatus;
typedef struct
{
int name;
ProStatus status;
int ax,bx,cx,dx;
int pc;
int psw;
int next;
} PCB;
typedef struct
{
int head;
int tail;
} Ready;

int PSW,AX,BX,CX,DX,PC,TIME;
PCB pcbArea[N];
int run;
Ready ready;
int pfree;
void InitRun()
{
run=-1;
}
void InitReady()
{
ready.head=ready.tail=-1;
}
void InitFree()
{
int temp;
for(temp=0;temp<N-1;temp++)
{
pcbArea[temp].next=temp+1;
}
pcbArea[temp].next=-1;
pfree=0;
}
int PopReady()
{
int temp;
if(ready.head==-1)
{
printf("就绪队列为空,不能出队。\n");
return -1;
}
temp=ready.head ;
ready.head =pcbArea[temp].next ;
if(ready.head ==-1)
ready.tail =-1;
pcbArea[temp].next =-1;
return temp;
}
int PopFree()
{
int temp;
if(pfree==-1)
{
printf("空闲队列为空,不能出队。\n");
return -1;
}
temp=pfree;
pfree=pcbArea[temp].next ;
pcbArea[temp].next =-1;
return temp;
}
void PushReady(int x)
{
int temp;
if(ready.head ==-1)
{
ready.head =x;
ready.tail =x;
}
else
{
temp=ready.tail ;
ready.tail =x;
pcbArea[temp].next=x;
}
pcbArea[ready.tail ].next =-1;
}
void CreatePCB(int x,PCB pcb)
{
pcbArea[x].ax =pcb.ax;
pcbArea[x].bx =pcb.bx ;
pcbArea[x].cx =pcb.cx ;
pcbArea[x].dx =pcb.dx ;
pcbArea[x].name =pcb.name ;
pcbArea[x].next =-1;
pcbArea[x].pc =pcb.pc ;
pcbArea[x].psw =pcb.psw ;
pcbArea[x].status =pcb.status ;
}
void Create(PCB pcb)
{
int temp;
if(pfree==-1)
{
printf("空闲队列为空,不能创建进程。\n");
return;
}
temp=PopFree();
pcb.status =Aready;
CreatePCB(temp,pcb);
PushReady(temp);
}
void Schedule()
{
int temp;
if(ready.head ==-1)
{
printf("系统中没有进程可以调度。");
return;
}
}
//temp=PopReady();
while ((temp=PopReady())!=-1)
{
pcbArea[temp].status =Running;
TIME=SLOT;
Sleep(5000);
AX=pcbArea[temp].ax ;
BX=pcbArea[temp].bx ;
CX=pcbArea[temp].cx ;
DX=pcbArea[temp].dx ;
PC=pcbArea[temp].pc ;
PSW=pcbArea[temp].psw ;

run=temp;
printf("当前运行的程序:\n");
printf("进程号:%d\n",pcbArea[run].name );
printf("进程状态:%d\n",pcbArea[run].status );
printf("寄存器内容:\nAX\tBX\tCX\tDX\tPC\tPSW\n");
printf("%d\t%d\t%d\t%d\t%d\t%d\n",pcbArea[run].ax,pcbArea[run].bx,pcbArea[run].cx,pcbArea[run].dx,pcbArea[run].pc,pcbArea[run].psw);

}
void main()
{
int temp;
PCB tmp_pcb;
printf("请输入进程号,以负数为结束(进程号应保持唯一)。\n\n按任意键进入输入模式:");
getchar();
InitRun();
InitReady();
InitFree();
printf("请开始输入进程号:\n");
while(1)
{
scanf("%d",&temp);
if(temp<0)
break;
tmp_pcb.name=temp;
tmp_pcb.ax=temp;
tmp_pcb.bx=temp;
tmp_pcb.cx=temp;
tmp_pcb.dx=temp;
tmp_pcb.pc=temp;
tmp_pcb.psw=temp;
Create(tmp_pcb);
}
printf("\n");
Schedule();
}

img

  • 写回答

1条回答 默认 最新

  • 赵4老师 2022-06-08 09:31
    关注
    
    #include<stdio.h>
    #include<windows.h>
    #define N 10
    #define SLOT 5
    typedef enum
    {
        Running,
        Aready,
        Blocking
    } ProStatus;
    typedef struct {
        int name;
        ProStatus status;
        int ax,bx,cx,dx;
        int pc;
        int psw;
        int next;
    }
    PCB;
    typedef struct {
        int head;
        int tail;
    }
    Ready;
    
    int PSW,AX,BX,CX,DX,PC,TIME;
    PCB pcbArea[N];
    int run;
    Ready ready;
    int pfree;
    void InitRun() {
        run=-1;
    }
    void InitReady() {
        ready.head=ready.tail=-1;
    }
    void InitFree() {
        int temp;
        for(temp=0;temp<N-1;temp++) {
            pcbArea[temp].next=temp+1;
        }
        pcbArea[temp].next=-1;
        pfree=0;
    }
    int PopReady() {
        int temp;
        if(ready.head==-1) {
            printf("就绪队列为空,不能出队。\n");
            return -1;
        }
        temp=ready.head ;
        ready.head =pcbArea[temp].next ;
        if(ready.head ==-1)
            ready.tail =-1;
        pcbArea[temp].next =-1;
        return temp;
    }
    int PopFree() {
        int temp;
        if(pfree==-1) {
            printf("空闲队列为空,不能出队。\n");
            return -1;
        }
        temp=pfree;
        pfree=pcbArea[temp].next ;
        pcbArea[temp].next =-1;
        return temp;
    }
    void PushReady(int x) {
        int temp;
        if(ready.head ==-1) {
            ready.head =x;
            ready.tail =x;
        } else {
            temp=ready.tail ;
            ready.tail =x;
            pcbArea[temp].next=x;
        }
        pcbArea[ready.tail ].next =-1;
    }
    void CreatePCB(int x,PCB pcb) {
        pcbArea[x].ax =pcb.ax;
        pcbArea[x].bx =pcb.bx ;
        pcbArea[x].cx =pcb.cx ;
        pcbArea[x].dx =pcb.dx ;
        pcbArea[x].name =pcb.name ;
        pcbArea[x].next =-1;
        pcbArea[x].pc =pcb.pc ;
        pcbArea[x].psw =pcb.psw ;
        pcbArea[x].status =pcb.status ;
    }
    void Create(PCB pcb) {
        int temp;
        if(pfree==-1) {
            printf("空闲队列为空,不能创建进程。\n");
            return;
        }
        temp=PopFree();
        pcb.status =Aready;
        CreatePCB(temp,pcb);
        PushReady(temp);
    }
    void Schedule() {
        int temp;
        if(ready.head ==-1) {
            printf("系统中没有进程可以调度。");
            return;
        }
        //temp=PopReady();
        while ((temp=PopReady())!=-1) {
            pcbArea[temp].status =Running;
            TIME=SLOT;
            Sleep(5000);
            AX=pcbArea[temp].ax ;
            BX=pcbArea[temp].bx ;
            CX=pcbArea[temp].cx ;
            DX=pcbArea[temp].dx ;
            PC=pcbArea[temp].pc ;
            PSW=pcbArea[temp].psw ;
    
            run=temp;
            printf("当前运行的程序:\n");
            printf("进程号:%d\n",pcbArea[run].name );
            printf("进程状态:%d\n",pcbArea[run].status );
            printf("寄存器内容:\nAX\tBX\tCX\tDX\tPC\tPSW\n");
            printf("%d\t%d\t%d\t%d\t%d\t%d\n",pcbArea[run].ax,pcbArea[run].bx,pcbArea[run].cx,pcbArea[run].dx,pcbArea[run].pc,pcbArea[run].psw);
        }
    }
    void main() {
        int temp;
        PCB tmp_pcb;
        printf("请输入进程号,以负数为结束(进程号应保持唯一)。\n\n按任意键进入输入模式:");
        getchar();
        InitRun();
        InitReady();
        InitFree();
        printf("请开始输入进程号:\n");
        while(1) {
            scanf("%d",&temp);
            if(temp<0)
                break;
            tmp_pcb.name=temp;
            tmp_pcb.ax=temp;
            tmp_pcb.bx=temp;
            tmp_pcb.cx=temp;
            tmp_pcb.dx=temp;
            tmp_pcb.pc=temp;
            tmp_pcb.psw=temp;
            Create(tmp_pcb);
        }
        printf("\n");
        Schedule();
    }
    
    
    评论

报告相同问题?

问题事件

  • 创建了问题 6月7日

悬赏问题

  • ¥50 微信聊天记录备份到电脑提示成功了,但还是没同步到电脑微信
  • ¥15 python怎么在已有视频文件后添加新帧
  • ¥20 虚幻UE引擎如何让多个同一个蓝图的NPC执行一样的动画,
  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!