File Allocation Indexed File Allocation

Write a program to simulate Indexed File Allocation.Indexed file allocation strategy brings all the pointers together into one location: an index block. Each file has its own index block, which is an array of disk-block addresses.

The ith entry in the index block points to the ith block of the file. The directory contains the address of the index block. To find and read the ith block, the pointer in the ith index-block entry is used.

#include <iostream>
using namespace std;
int main() {
int n,*size,**store_val;
    string *alpha,search;
    bool flag = true;
    cin>>n;
    alpha = new string[n];
    size  = new int[n];
    store_val = new int*[n];

    for (int i =0 ;i<n;i++)
      store_val[i] = new int[20];

    for(int i = 0 ; i<n ; i++){
       
       cin>>alpha[i]>>size[i];
        for(int j = 0; j<size[i] ;j++){
       
           cin>>store_val[i][j];
        }
    }
  cin>>search;
  for (int i =0 ;i<n ;i++){
   
       if(search == alpha[i])
       { flag = false;
         cout<<"Filename No.of blocks\n"<<alpha[i]<<' '<<size[i]<<endl<<"Blocks Occupied\n";
       
         for(int j = 0; j<size[i]-1 ;j++){
            cout<<store_val[i][j]<<' ';
         }
         cout<<store_val[i][size[i]-1];
       }
  }
 
  if (flag) {
      cout<<"File Not Found";

  }
return 0;
}

Comments