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.

 
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


Answer:


#include<stdio.h>
int main()
{
    char name[20];
    int start,length;
    printf("Enter the name of the file\n");
    scanf("%s",&name[0]);
    printf("Enter the start block of the file\n");
    scanf("%d",&start);
    printf("Enter the length of the file\n");
    scanf("%d",&length);
    
    printf("File Allocation Table\n");
    printf("%s%40s%40s\n","File Name","Start Block","Length");
    printf("%s%50d%50d",&name[0],start,length);
}

Post a Comment

0 Comments