CFA
CFA
h>
#include <stdlib.h>
#include <string.h>
struct File_Details
{
char File_Name[10];
int File_size;
int File_start;
} directory[MAX_FILES];
int *Bit_vector;
int memory_size;
int count = 0;
void Initialize_bit_vector()
{
printf("Enter the size of memory (number of blocks): ");
scanf("%d", &memory_size);
void Show_memory_blocks()
{
printf("Memory Blocks: ");
for (int i = 0; i < memory_size; i++)
{
printf("%d ", Bit_vector[i]);
}
printf("\n");
}
void Create_File()
{
char filename[10];
int file_size, start_pos;
if (start_pos == -1)
{
printf("Error: No free memory available\n");
return;
}
void Delete_File()
{
char filename[10];
printf("Enter name to delete: ");
scanf("%s", filename);
// Remove the file from the directory by shifting the remaining entries
for (int j = i; j < count - 1; j++)
{
directory[j] = directory[j + 1];
}
count--;
printf("File deleted.\n");
return;
}
}
printf("File not found.\n");
}
void Display_directory()
{
printf("Directory:\n");
for (int i = 0; i < count; i++)
{
printf("Name: %s, Start: %d, Length: %d\n", directory[i].File_Name,
directory[i].File_start, directory[i].File_size);
}
}
int main()
{
int choice;
Initialize_bit_vector();
while (1)
{
printf("\n1. Show Memory Blocks\n");
printf("2. Create New File\n");
printf("3. Show Directory\n");
printf("4. Delete File\n");
printf("5. Exit\n");
printf("Enter choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1: Show_memory_blocks(); break;
case 2: Create_File(); break;
case 3: Display_directory(); break;
case 4: Delete_File(); break;
case 5:
free(Bit_vector); // Free the allocated memory
exit(0);
break;
default: printf("Invalid Choice\n");
}
}
return 0;
}