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. Also, print the disk blocks allocated to this file

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.

 
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 the file.
 
Output format :
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
The disk blocks allocated to the file F1 are
2 3 4 5 6 7 8 9


Answer:

#include<stdio.h>
int main()
{
    int st,len;
    char str[2];
    printf("Enter the name of the file\n");
    scanf("%s",str);
    printf("Enter the start block of the file\n");
    scanf("%d",&st);
    printf("Enter the length of the file\n");
    scanf("%d",&len);
    printf("File Allocation Table\n");
    printf("%s%40s%40s\n","File Name","Start Block","Length");
    printf("%s%50d%50d\n",str,st,len);
    printf("The disk blocks allocated to the file %s are\n",str);
    for(int i=0;i<len;i++)
    {
        printf("%d",st+i);
    }
}


Post a Comment

0 Comments