Sequential access method in C.

Program:

#include<stdio.h>

int  main(){
int f[50],i,st,len,count,op;

for(i=0;i<50;i++)
f[i]=0;
printf("Files allocated are:\n");
x:
count = 0;
printf("Enter starting block & length of files:\n");
scanf("%d%d",&st,&len);
for(i=st;i<(st+len);i++)
if(f[i] == 0)
count++;
if(len == count){
for(i=st;i<(st+len);i++)
if(f[i]==0){
f[i]=1;
printf("%d\t%d\n",i,f[i]);
}
if(i != (st+len -1))
printf("File allocated\n");
}else
printf("File not allocated\n");

printf("Press 1 to continue.....\n");
scanf("%d",&op);
if(op == 1)
goto x;

return 0;
}

Output:
Files allocated are:
Enter starting block & length of files:
4
4

4       1
5       1
6       1
7       1
File allocated
Press 1 to continue.....
1
Enter starting block & length of files:
4
3
File not allocated
Press 1 to continue.....
3

Comments

Popular posts from this blog

Multi-programming with variable number of tasks(MVT) program in C

Multi-programming with fixed number of tasks(MFT) program in C

Linked file allocation program in C.