6/recent/ticker-posts

Write a C program to get the name of the file, the start block of the file and the length of the file from the user and display it in the given format.

Write a C program to get the name of the file, the start block of the file and the length of the file from the user and display it in the given format. Also, print the disk blocks allocated to this file. Get the details of another file and check whether this file can be allocated the disk space using contiguous or sequential allocation.


Note: 
Assume that the disk space from 1 to 1000 is available for file allocation.

 
Input format:
Input consists of Filename (string ), the start of the block ( int ) and length ( int ) of two files.
 
Output format:
The output consists of given input in the file allocation table and says whether the second file is placed in the drive or not.
Use printf ("%s%40s%40s","File Name","Start Block","Length\n"); to print the table header in the specified format.
Use "%s%50d%50d\n" to display the details in the specified format.
[ Refer Sample Input and Output for further specifications ]
 
Sample Input and Output :
[All text in bold corresponds to the input and the rest corresponds to output]
 
 
Enter the name of the file
F1
Enter the start block of the file
2
Enter the length of the file
8
File Allocation Table
File Name                             Start Block                                 Length
F1                                                 2                                                 8
Enter the name of the file
F2
Enter the start block of the file
6
Enter the length of the file
8
F2 cannot be allocated disk space
 
Sample Input and output 2:
Enter the name of the file
F1
Enter the start block of the file
2
Enter the length of the file
8
File Allocation Table
File Name                             Start Block                                 Length
F1                                                 2                                                 8
Enter the name of the file
F2
Enter the start block of the file
11
Enter the length of the file
8
F2 can be allocated disk space


Answer:


#include<stdio.h>
int main()
{
    char name[10];
    int start[2],length[2];
    printf("Enter the name of the file\n");
    scanf("%s",&name[0]);
    printf("Enter the start block of the file\n");
    scanf("%d",&start[0]);
    printf("Enter the length of the file\n");
    scanf("%d",&length[0]);
    
    printf("File Allocation Table\n");
    printf("%s%40s%40s","File Name","Start Block","Length\n");
    printf("%s%50d%50d\n",&name[0],start[0],length[0]);
    
    printf("Enter the name of the file\n");
    scanf("%s",&name[1]);
    printf("Enter the start block of the file\n");
    scanf("%d",&start[1]);
    printf("Enter the length of the file\n");
    scanf("%d",&length[1]);
    
    int total=start[0]+length[0];
    if(start[1]>=total){
        printf("%s can be allocated disk space",&name[1]);
    }
    else
    {
        printf("%s cannot be allocated disk space",&name[1]);
    }
}

Post a Comment

0 Comments