Untitled
unknown
plain_text
a month ago
1.4 kB
0
Indexable
Never
#include <stdio.h> struct file{ int number; int starting; int size; int allocated; }; struct disk{ int allocated; }; void main(){ int n,m; printf("enter number of blocks in disk "); scanf("%d",&n); struct disk d[n]; for(int i = 0;i<n;i++){ d[i].allocated = 0; } printf("enter number of files to be allocated"); scanf("%d",&m); struct file f[m]; for(int i = 0;i<m;i++){ printf("enter file number "); scanf("%d",&f[i].number); printf("enter starting block of file %d ",i); scanf("%d",&f[i].starting); printf("enter size of file %d ",i); scanf("%d",&f[i].size); int x = 0; for(int j = f[i].starting;j<f[i].starting+f[i].size;j++){ if(d[j].allocated == 1){ x=1; } } if(x==1){ printf("not allocated\n"); f[i].allocated = 0; } else{ for(int j = f[i].starting;j<f[i].starting+f[i].size;j++){ d[j].allocated = 1; } f[i].allocated = 1; } } printf("enter file number to be searched "); scanf("%d",&n); if(f[n].allocated == 1){ printf("starting address = %d\n",f[n].starting); printf("sizes = %d\n",f[n].size); } else{ printf("file not allocated"); } }
Leave a Comment