Monday, 23 February 2015

//C Programe for  INDEXED  FILE ALLOCATION  //


#include<stdio.h>
#include<conio.h>
main()
{
 int n,m[20],i,j,sb[20],s[20],b[20][20],x;
 clrscr();
 printf("Enter no. of files:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {          printf("Enter starting block and size of file%d:",i+1);
            scanf("%d%d",&sb[i],&s[i]);
            printf("Enter blocks occupied by file%d:",i+1);
            scanf("%d",&m[i]);
            printf("enter blocks of file%d:",i+1);
            for(j=0;j<m[i];j++)
                        scanf("%d",&b[i][j]);
 } printf("\nFile\t index\tlength\n");
 for(i=0;i<n;i++)
 {
            printf("%d\t%d\t%d\n",i+1,sb[i],m[i]);
 }printf("\nEnter file name:");
 scanf("%d",&x);
 printf("file name is:%d\n",x);
 i=x-1;
 printf("Index is:%d",sb[i]);
 printf("Block occupied are:");
 for(j=0;j<m[i];j++)
            printf("%3d",b[i][j]);
 getch();
}

Output



Program in C to show sequential file allocation

#include<stdio.h>
#include<conio.h>
main()
{
 int n,i,j,b[20],sb[20],t[20],x,c[20][20];
 clrscr();
 printf("Enter no.of files:");
 scanf("%d",&n);
 for(i=0;i<n;i++)
 {
          printf("Enter no. of blocks occupied by file%d",i+1);
          scanf("%d",&b[i]);
          printf("Enter the starting block of file%d",i+1);
          scanf("%d",&sb[i]);
          t[i]=sb[i];
          for(j=0;j<b[i];j++)
                   c[i][j]=sb[i]++;
          }
 printf("Filename\tStart block\tlength\n");
 for(i=0;i<n;i++)
          printf("%d\t  %d \t%d\n",i+1,t[i],b[i]);
 printf("Enter file name:");
 scanf("%d",&x);
 printf("File name is:%d",x);
 printf("length is:%d",b[x-1]);
 printf("blocks occupied:");
 for(i=0;i<b[x-1];i++)
          printf("%4d",c[x-1][i]);
 getch();
}

OUTPUT