-
Notifications
You must be signed in to change notification settings - Fork 1
/
6a.c
55 lines (45 loc) · 1.05 KB
/
6a.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/** C program
* File Allocation
* Sequential
* Copyright (c) 2021 Jayesh Mann
**/
#include <stdio.h>
#include <string.h>
struct fileTable
{
char name[20];
int sb, nob;
} ft[30];
int main(int argc, char const *argv[])
{
int i, j, n;
char s[20];
printf("Enter no. of files: ");
scanf("%d", &n);
for (i = 0; i < n; i++)
{
printf("\nEnter file name %d: ", i + 1);
scanf("%s", ft[i].name);
printf("\nEnter starting block of file %d: ", i + 1);
scanf("%d", &ft[i].sb);
printf("\nEnter no. of blocks in file %d: ", i + 1);
scanf("%d", &ft[i].nob);
}
printf("\nEnter the file name to be searched: ");
scanf("%s", s);
for (i = 0; i < n; i++)
if (strcmp(s, ft[i].name) == 0)
break;
if (i == n)
printf("\nFile not found.");
else
{
printf("\nFile Name\tStart Block\tNo. of Blocks\tBlocks Occupied");
printf("\n%s\t\t%d\t\t%d\t\t", ft[i].name, ft[i].sb, ft[i].nob);
for (j = 0; j < ft[i].nob; j++)
printf("%d, ", ft[i].sb + j);
printf("\n");
}
printf("\n");
return 0;
}