Untitled
unknown
plain_text
a month ago
1.3 kB
1
Indexable
Never
#include <stdio.h> struct file { char fname[10]; int index, size, block[10]; //int flag; } f[10]; void main() { int n, allocated[10]; // Initialize allocated array to 0 for (int i = 0; i < 10; i++) { allocated[i] = 0; } // Get the number of files printf("Enter no. of files:"); scanf("%d", &n); // Get the details of each file for (int i = 0; i < n; i++) { //f[i].flag=1; printf("\nEnter file name:"); scanf("%s", f[i].fname); x: printf("Enter index block:"); scanf("%d", &f[i].index); if(allocated[f[i].index]) { printf("Index block is already allocated --try another\n"); goto x; } allocated[f[i].index]=1; //not allowing the index block to use as data block f[i].block[0] = f[i].index; printf("Enter no.of blocks:"); scanf("%d", &f[i].size); printf("Enter block numbers:\n"); for (int j = 1; j <= f[i].size; j++) { y: scanf("%d", &f[i].block[j]); if (allocated[f[i].block[j]] == 1) { printf("Block %d is already allocated-->enter another block\n", f[i].block[j]); //f[i].flag=0; goto y; // break; } // Mark the block as allocated allocated[f[i].block[j]] = 1; } printf("\n"); for(int j=1;j<=f[i].size;j++) { printf("%d ----> %d\n",f[i].block[0],f[i].block[j]); } } // Print the details of each file printf("\nFile\tindex\tsize\n"); for (int i = 0; i < n; i++) { printf("%s\t%d\t\t%d\n", f[i].fname, f[i].index, f[i].size); } }
Leave a Comment