?? tr.c
字號:
/*本程序順序分配空間,所以運(yùn)行后開始幾個數(shù)字都是'1'*/
#include<string.h>
#include<stdio.h>
#define ROW 12
#define COLUMN 16
#define AREA 192
int a[ROW][COLUMN]={1,1,1,0,0,1,0,1,1,1,0,0,1,0,0,0,
1,0,1,0,0,0,1,0,1,0,1,0,1,1,1,1,
1,1,1,0,1,0,1,1,0,1,0,0,1,1,0,1,
0,0,1,0,1,1,0,1,0,1,1,0,1,0,1,0,
1,0,1,1,0,1,0,1,0,1,1,1,1,0,1,0,
1,0,0,1,1,0,1,0,0,0,1,0,1,0,1,0,
0,1,0,1,1,1,0,1,0,0,0,1,0,1,0,1,
0,1,0,1,0,1,0,1,0,1,0,1,0,1,1,1,
1,0,1,1,1,0,1,1,1,0,0,1,0,0,0,0,
0,1,0,1,0,1,1,0,1,0,1,0,1,0,1,0,
1,1,0,0,1,0,1,1,0,0,0,1,0,1,0,0,
0,0,0,1,0,0,0,1,1,1,0,1,0,1,1,0,
};
int b[ROW][COLUMN]={0};int c[AREA][3]={0};int static y;
int input(int p);
void distribute(int p);void callbackall(void);void callbackpointed(int n);
main()
{
static int i,j,n,p;
printf("**********************************");
printf("********designed by weiwei********");
printf("**********************************");
printf("The distribution and callback of disk space.\n");
printf("press any key to display the status of the disk.\n");
getchar();
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
printf("Press any key to apply space from disk.\n");
getchar();
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
if(a[i][j])
continue;
else
{
c[p][0]=p+1;c[p][1]=i*16+j;p++;
}
}
}
y=p;
printf("There are %d blocks to use.",p);
distribute(n);
printf("\nThe next step is callbacking the space,press any key.\n");
printf("You have these choices:\n");
printf("1:\t Free all the disk blocks you apply just now\n");
printf("2:\t Free a disk block that is destined \n");
printf("3:\t Exit\n");
i=input(3);
while(i)
{
switch(i)
{
case 1:
callbackall(n);break;
case 2:
callbackpointed(n);
printf("\n\nYou stil have these choices:\n");
printf("1:\t free all the disk blocks you apply just now\n");
printf("2:\t free a pointed disk block\n");
printf("3:\t esc\n");
printf("Please make a choice:\n");
i=input(3);break;
case 3:
exit(1);break;
}
}
}
int input(int p)
{
static int k;
scanf("%d",&k);
if(k<=0||k>p)
{
printf("Wrong input!!!!please enter a number that is greater than 0 and less than %d:\n",p);
input(p);
}
return k;
}
void distribute(int x)
{
static int i,j,k,p,m,n,q;
printf("Please enter which disk block do you want to free from.\n");
k=input(y);/*輸入開始釋放的量*/
printf("Please enter how many disk blocks do you want to free.\n");
printf("You must enssure the data is right\n");
j=input(y);/*要釋放多少個*/
if(k+j>y)
{
printf("Wrong input!!! The blocks you want to distribute is beyond the mark.\n ");
printf("Please enter another legal number to be the first one and the amount:\n\n ");
distribute(y);
}
else
{
for(i=k;i<k+j;i++)
{
q=c[i-1][1];
m=q/16;
n=q%16;
p=m*16+n;
a[m][n]=1;b[m][n]=1;
printf("%d:\t related block No. %d;cylinder No. %d;track No. %d;physic block No. %d\n",i,p,m,n/4,n%4);
}
printf("Press any key to compare this matrix to the last one\n");
getchar();
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
}
}
void callbackall(int n)
{
int i,j,m;
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
if(!b[i][j])
continue;
else
{
a[i][j]=0;
}
}
}
printf("press any key to compare this matrix to the first one.\n");
getchar();
printf("you can see it recruits:\n");
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
}
void callbackpointed(int n)
{
static int i,k,q,m,j,p;
printf("Please enter which disk block do you want to free from.\n");
k=input(n);/*輸入開始釋放的量*/
printf("Please enter how many disk blocks do you want to free.\n");
printf("You must enssure the data is right\n");
j=input(n);/*要釋放多少個*/
if(k+j>n+1)
{
printf("Wrong input!!! The blocks you want to free is beyond the mark.\n ");
printf("Please enter another legal number to be the first one and the amount:\n\n ");
callbackpointed(n);
}
else
{
for(i=k;i<k+j;i++)
{
q=c[i-1][1];
m=q/16;
p=q%16;
a[m][p]=0;
/*c[i-1][3]=1;c[k-1][3]=1表明已經(jīng)被釋放了*/
}
printf("The pointed disk block has been freeed,press any key to check the result.\n");
getchar();
for(i=0;i<ROW;i++)
{
for(j=0;j<COLUMN;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -