-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path10_indexedFile.c
51 lines (49 loc) · 1.26 KB
/
10_indexedFile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
10. Write a C program to simulate the indexed file allocation strategy.
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
int f[50], index[50], i, n, st, len, j, c, k, ind, count = 0;
for(i = 0; i < 50; i++) {
f[i] = 0;
}
x: printf("Enter the index block: ");
scanf("%d", &ind);
if(f[ind] != 1) {
printf("Enter number of blocks needed and number of files for the index %d on the disk : \n", ind);
scanf("%d", &n);
}
else {
printf("%d index is already allocated \n",ind);
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("Allocated\n");
printf("File Indexed\n");
for(k = 0; k < n; k++) {
printf("%d-------->%d : %d\n", ind, index[k], f[index[k]]);
}
} else {
printf("File in the index is already allocated \n");
printf("Enter another file indexed");
goto y;
}
printf("Do you want to enter more file(Yes - 1/No - 0): ");
scanf("%d", &c);
if(c == 1) {
goto x;
} else {
exit(0);
}
return 0;
}