Write a C program to get the name, the start block, and length of n files and display the File Allocation table using Contiguous / Sequential Allocation.
Note:
Assume that the disk space from 1 to 1000 is available for file allocation.
Assume that the disk space from 1 to 1000 is available for file allocation.
Input format:
Input consists of a number of files ( int ), Filename (string ), the start of the block ( int ) and length ( int ) of n files.
Output format :
The output consists of the file allocation table using contiguous file allocation technique.
Use printf("%s%40s%40s","File Name","Start Block","Length\n"); to print the table header in the specified format
Use "%s%50d%50d\n" to dipslay the details in the specified format.
Use printf("%s%40s%40s","File Name","Start Block","Length\n"); to print the table header in the specified format
Use "%s%50d%50d\n" to dipslay the details in the specified format.
[ Refer Sample Input and Output for further specifications ]
Sample Input and Output :
[All text in bold corresponds to the input and the rest corresponds to output]
[All text in bold corresponds to the input and the rest corresponds to output]
Enter the number of files to be allocated
3
Enter the name of the file 1
F1
Enter the start block of the file 1
2
Enter the length of the file 1
8
Enter the name of the file 2
F2
Enter the start block of the file 2
5
Enter the length of the file 2
18
F2 cannot be allocated disk space
Enter the name of the file 3
F3
Enter the start block of the file 3
1
Enter the length of the file 3
1
File Allocation Table
File Name Start Block Length
F1 2 8
F3 1 1
F1 2 8
F3 1 1
Answer:
#include<stdio.h> int main() { char name[10][30]; int start[10],length[10],num; printf("Enter the number of files to be allocated\n"); scanf("%d",&num); int count=0,k,j; for(int i=0;i<num;i++) { printf("Enter the name of the file %d\n",i+1); scanf("%s",&name[i][0]); printf("Enter the start block of the file %d\n",i+1); scanf("%d",&start[i]); printf("Enter the length of the file %d\n",i+1); scanf("%d",&length[i]); for(j=0,k=1;j<num && k<num;j++,k++) { if(start[j+1]<=start[j] || start[j+1]>=length[j]) { } else { count++; } } if(count==1) { printf("%s cannot be allocated disk space\n",name[i]); } } printf("File Allocation Table\n"); printf("%s%40s%40s\n","File Name","Start Block","Length"); printf("%s%50d%50d\n",name[0],start[0],length[0]); for(int i=0,j=1;i<num && j<num;i++,j++) { if(start[i+1]<=start[i] || start[i+1]>=length[i]) { printf("%s%50d%50d\n",name[j],start[j],length[j]); } } return 0; }
0 Comments