Sreekar_0125

Sequential File Allocation

Aug 14th, 2023
1,081
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <conio.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5.  
  6. void recursion(int file[])
  7. {
  8.     int free = 0, block, length, j, k, ch, i;
  9.    
  10.     printf("Enter the starting block and the length: ");
  11.     scanf("%d%d", &block, &length);
  12.     for (i = block; i < block + length; i++)
  13.     {
  14.         if (file[i] == 0)
  15.         {
  16.             free++;
  17.         }
  18.            
  19.     }
  20.     if (length == free)
  21.     {
  22.         for (i = block; i < block + length; i++)
  23.         {
  24.             if (file[i] == 0)
  25.             {
  26.                 file[i] = 1;
  27.                 printf("%d\t%d\n", i, file[i]);
  28.             }
  29.         }
  30.         if (i != (block + length - 1))
  31.         {
  32.             printf("The file is allocated to the disk\n");
  33.         }      
  34.     }
  35.     else
  36.     {
  37.         printf("Another File Exists in the Required Block \n");
  38.     }
  39.        
  40.     printf("Do you want to enter files\n");
  41.     printf("Press 1 for YES, 0 for NO: ");
  42.  
  43.     scanf("%d", &ch);
  44.     if (ch == 1)
  45.         recursion(file);
  46.     else
  47.         exit(0);
  48.     return;
  49. }
  50. int main()
  51. {
  52.     int file[30], i;
  53.  
  54.     for (i = 0; i < 30; i++)
  55.     {
  56.         file[i] = 0;
  57.     }
  58.        
  59.     printf("Files allocated are\n");
  60.     recursion(file);
  61.     getch();
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment