- 论坛徽章:
- 0
|
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define M 3 //define ResouceSetNumber=3
#define N 5 //define ProcessNumber=5
int R[3]={10,5,7}; //define ResouceInstanceNumber
typedef struct Process{
int Max[N][M];
int Allocation[N][M];
int Need[N][M]; int Request[N][M];
}table;
int main(void)
{
table t;
int Available[M],sum;
int i,j;
srand((int)time(0));
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
t.Max[j]=1+rand()%(R[j]+1);
}
for(i=0;i<N;i++)
for(j=0;i<M;j++)
{
t.Allocation[j]=rand()%(t.Max[j]+1); //段错误
t.Need[j]=rand()%(t.Max[j]+1); //段错误
}
for(i=0;i<N;i++)
for(j=0;j<M;j++)
{
if(t.Allocation[j]<t.Need[j])
t.Request[j]=t.Need[j]-t.Allocation[j];
}
for(j=0;j<M;j++)
{
for(i=0;i<N;i++)
sum+= t.Allocation[j];
if(sum<R[j])
Available[j]=R[j]-sum;
}
return 0;
}
请问以下各位大侠 编译后无错
运行时 在程序指定的行发生段错误
怎么解决
[ 本帖最后由 kuluwang 于 2008-11-26 22:28 编辑 ] |
|