c写的程序在vc运行出错(急用!谁答出,送500分)

来源:百度知道 编辑:UC知道 时间:2024/05/24 09:34:36
用c编写的多队列轮转法,在W-tc下运行没有问题.
在vc下编译也没有问题,但运行出错,直接关闭了程序.

#include "stdio.h"
#include <stdlib.h>
#include <conio.h>
#define getpch(type) (type*)malloc(sizeof(type))

#define NULL 0

struct pcb { /* 定义进程控制块PCB */

char name[10];

char state;

int num;

int ntime;

int rtime;

struct pcb* link;

}*ready=NULL,*p;

typedef struct pcb PCB;

PCB *last;

void sort() /* 建立对进程进行优先级排列函数*/

{if(ready==NULL)
{ready=p;
last=ready;
}
else
{last->link=p;
last=last->link;
}
last->link=NULL;

}

void input() /* 建立进程控制块函数*/

{

int i,num=5;

for(i=0;i<num;i++)

{

printf("\n 作业号No.%d:\n",i);

p=getpch(PCB);

printf("\n 输入进

while(pr!=NULL)

{

disp(pr);

pr=pr->link;

if(pr->num!=pt->num&&pr!=NULL)

printf("\n ****当前就绪队列%d状态为:\n",pr->num);

pt=pr;

}

pr == NULL时这里出错:
if(pr->num!=pt->num&&pr!=NULL)
我没仔细看,应该很好解决

所以说pr == NULL时,pr->num这一句没有意义
改成下面的试试
if(pr && pr->num!=pt->num && pr!=NULL)
光看注释,不知道你的程序要干什么,看代码太累了

我试过了,可以

ps: w-tc没玩过,可能它这个编译器碰到pr->num(pr==NULL)这种不合法的情况时,自动返回false,于是if条件就不成立了

你建立的是win32程序还是控制台程序?如果是win32的请改成控制台程序.

是不是你多了个.啊

是不是运行环境不同啊?