0% found this document useful (0 votes)
7 views3 pages

File 2

Uploaded by

cupofcaffrey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views3 pages

File 2

Uploaded by

cupofcaffrey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

#include <stdio.

h>
#include <stdlib.h>
#include<math.h>
int main()
{
int n,l,i=0,j,sbn,fnum,flag,len,ch,ch1,x[100];
int f[50],index[50],k,st,c,ind,count=0;
char name[100];
/*printf("\nRead the number of blocks:\n");
scanf("%d",&n);
int a[n];
for(int i=0;i<n;i++)
{
a[i]=-1;
}
printf("\nRead the number of files:\n");
scanf("%d",&fnum);*/
printf("Enter 1 for contiguous, 2 for linked and 3 for indexed:\n");
scanf("%d",&ch);
do{
switch(ch)
{
/*
case 1:
printf("\nCONTIGUOUS ALLOCATION\n");
while(i<fnum){
printf("\nEnter file name:\n");
scanf("%s",name);
printf("\nRead the starting block :\n");
scanf("%d",&sbn);
printf("\nRead the length of block:\n");
scanf("%d",&len);
l=sbn+len;
for(j=sbn;j<l;j++)
{
if(a[j]==-1)
{
flag=0;
}
else
{
flag=1;
}
}
if(flag==0)
{
for(j=sbn;j<l;j++)
a[j]=1;
printf("\nThe file %s is allocated from %d to %d\n",name,sbn,l-
1);
}
else
{
printf("\nThe file could not be allocated\n");
}
i++;
}
break;

case 2:
printf("\nLINKED ALLOCATION\n");
while(i<fnum){
printf("\nEnter file name:\n");
scanf("%s",name);
printf("\nRead the starting block :\n");
scanf("%d",&sbn);
printf("\nRead the length of block:\n");
scanf("%d",&len);
l=sbn+len;
for(j=sbn;j<l;j++)
{
if(a[j]==-1)
{
flag=0;
}
else
{
flag=1;
}
}
if(flag==0)
{
printf("\nThe file %s is allocated to block %d\n",name,sbn);
a[sbn]=1;
for(j=sbn+1;j<l;j++)
{
x[j]=rand() % 50;
printf("\nThe file %s is allocated to block %d\n",name,x[j]);
a[j]=1;
}
}
else
{
printf("\nThe file could not be allocated as block is filled\
n");
}
i++;
}
break;
*/
case 3:
printf("\nINDEXED ALLOCATION\n");
for(i=0;i<50;i++)
{
f[i]=0;
}
x:printf("\nEnter the index block:\n");
scanf("%d",&ind);
if(f[ind]!=1)
{
printf("\nEnter the number of blocks to be added to index:\n");
scanf("%d",&n);
}
else
{
printf("\nIndex is already allocated\n");
goto x;
}
y:count =0;
for(i=0;i<n;i++)
{
scanf("%d",&index[i]);
if(f[index[i]]==0)
count++;
}
if(count==n)
{
for(j=0;j<n;j++)
{
f[index[j]]=1;
printf("\nFile Allocated\n");
printf("\nIndexed\n");
for(k=0;k<n;k++)
{
printf("\n%d-------->%d:%d\n",ind,index[k],f[index[k]]);
}
}
}
else
{
printf("\nFile in the index is already allocated\n");
printf("\nEnter another file index\n");
goto y;
}
printf("\nEnter 1 to enter more files and enter 0 to exit\n");
scanf("%d",&c);
if(c==1)
{
goto x;
}
else
{
exit(0);
getch();
}
break;
}
printf("\nEnter 1 to continue and 0 to exit:\n");
scanf("%d",&ch1);
}while(ch1==1);

return 0;
}

You might also like