-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContiguousMemoryAllocation.c
64 lines (61 loc) · 1.41 KB
/
ContiguousMemoryAllocation.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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
void recurse(int files[], int n)
{
int flag = 0, startBlock, len, j, k, ch;
printf("Enter the starting block ");
scanf("%d", &startBlock);
printf("Enter the length of the files: ");
scanf("%d", &len);
for (j = startBlock; j < (startBlock + len); j++)
{
if (files[j] == 1)
flag++;
}
if (len == flag)
{
for (int k = startBlock; k < (startBlock + len); k++)
{
if (files[k] == 1)
{
files[k] = 0;
printf("%d\t%d\n", k, files[k]);
}
}
if (k != (startBlock + len - 1))
printf("The file is allocated to the disk\n");
}
else
printf("The file is not allocated to the disk\n");
printf("Do you want to enter more files?\n");
printf("Press 1 for YES, 2 for NO: ");
scanf("%d", &ch);
if (ch == 1)
recurse(files, n);
else
{
printf("Availible files are \n");
for (int i = 0; i < n; i++)
{
if (files[i] == 1)
{
printf("%d\t%d\n", i, files[i]);
}
}
exit(0);
}
return;
}
int main()
{
printf("Enter the number of files \n");
int n;
scanf("%d", &n);
int files[n];
for (int i = 0; i < n; i++)
files[i] = 1;
recurse(files, n);
getch();
return 0;
}