Sequential File Allocation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1: //3.3.

1 SEQUENTIAL FILE ALLOCATION


2: #include<iostream>
3: using namespace std;
4: #include<conio.h>
5: #include<string.h>
6: struct fileTable
7: {
8: char name[20];
9: int sb, nob;
10: } ft[30];
11: int main()
12: {
13: int i, j, n;
14: char s[20];
15: // clrscr();
16: cout<<"Enter no of files :";
17: cin>>n;
18: for(i=0; i<n; i++)
19: {
20: cout<<"\nEnter file name "<<i+1<<" :";
21: cin>>ft[i].name;
22: cout<<"Enter starting block of file "<<i+1<<" :";
23: cin>>ft[i].sb;
24: cout<<"Enter no of blocks in file "<<i+1<<" :";
25: cin>>ft[i].nob;
26: }
27: cout<<"\nEnter the file name to be searched -- ";
28: cin>>s;
29: for(i=0; i<n; i++)
30: if(strcmp(s, ft[i].name)==0)
31: break;
32: if(i==n)
33: cout<<"\nFile Not Found";
34: else
35: {
36: cout<<"\nFILE NAME\tSTART BLOCK\tNO OF BLOCKS\tBLOCKS OCCUPIED\n";
37: cout<<"\n"<<ft[i].name<<"\t\t"<<ft[i].sb<<"\t\t"<<ft[i].nob<<"\t\t";
38: for(j=0; j<ft[i].nob; j++)
39: cout<<ft[i].sb+j<<",";
40: }
41: getch();
42: return 0;
43: }

You might also like