file allocation
file allocation
void main() {
int start, length, i, flag = 0;
int blocks[50] = {0};
clrscr();
if (flag == 0) {
for (i = start; i < start + length; i++)
blocks[i] = 1;
getch();
}
2. Linked File Allocation (Simplified)
c
Copy
Edit
#include <stdio.h>
#include <conio.h>
void main() {
int blocks[50] = {0};
int start, length, i, count = 0;
clrscr();
if (blocks[start] == 0) {
blocks[start] = 1;
printf("Allocated: %d ", start);
for (i = 0; i < 50 && count < length - 1; i++) {
if (blocks[i] == 0) {
blocks[i] = 1;
printf("-> %d ", i);
count++;
}
}
printf("-> NULL\n");
} else {
printf("Starting block already allocated.\n");
}
getch();
}
3. Indexed File Allocation (Simplified)
c
Copy
Edit
#include <stdio.h>
#include <conio.h>
void main() {
int blocks[50] = {0}, indexBlock, i, n, b;
clrscr();
if (blocks[indexBlock] == 0) {
blocks[indexBlock] = 1;
if (i == n)
printf("File allocated successfully.\n");
} else {
printf("Index block already allocated.\n");
}
getch();
}