-
Notifications
You must be signed in to change notification settings - Fork 0
/
TwoLevelDir.c
126 lines (106 loc) · 3.35 KB
/
TwoLevelDir.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// * Simulate file organization techniques.
struct
{
char dname[10], fname[10][10];
int fileCount;
} dir[10];
void main()
{
int dirCount = 0, choice;
int i;
char d[10], f[10];
while (1)
{
printf("\n1. Create Directory\n2. Create File\n3. Delete File");
printf("\n4. Search File\n5. Display\n6. Exit\nEnter your choice: ");
scanf("%d", &choice);
switch (choice)
{
case 1:
printf("\nEnter Directory Name: ");
scanf("%s", dir[dirCount].dname);
dir[dirCount].fileCount = 0;
dirCount++;
break;
case 2:
printf("\nEnter Directory Name: ");
scanf("%s", d);
for (i = 0; i < dirCount; i++)
if (strcmp(d, dir[i].dname) == 0)
{
printf("\nEnter File Name: ");
scanf("%s", dir[i].fname[dir[i].fileCount]);
dir[i].fileCount++;
break;
}
if (i == dirCount)
printf("\nDirectory %s not found", d);
break;
case 3:
printf("\nEnter name of the Directoy: ");
scanf("%s", d);
for (i = 0; i < dirCount; i++)
{
if (strcmp(d, dir[i].dname) == 0)
{
printf("\nEnter File Name: ");
scanf("%s", f);
for (int k = 0; k < dir[i].fileCount; k++)
if (strcmp(f, dir[i].fname[k]) == 0)
{
printf("File %s Deleted", f);
dir[i].fileCount--;
strcpy(dir[i].fname[k], dir[i].fname[dir[i].fileCount]);
goto jmp;
}
printf("File %s not found", f);
goto jmp;
}
}
printf("Directory %s not found", d);
jmp:
break;
case 4:
printf("\nEnter name of the Directoy: ");
scanf("%s", d);
for (i = 0; i < dirCount; i++)
{
if (strcmp(d, dir[i].dname) == 0)
{
printf("\nEnter File Name: ");
scanf("%s", f);
for (int k = 0; k < dir[i].fileCount; k++)
if (strcmp(f, dir[i].fname[k]) == 0)
{
printf("File %s is found ", f);
goto jmp1;
}
printf("File %s not found", f);
goto jmp1;
}
}
printf("Directory %s not found", d);
jmp1:
break;
case 5:
if (dirCount == 0)
printf("\nNo Directories");
else
{
printf("\nDirectories\tFiles\n");
for (int i = 0; i < dirCount; i++)
{
printf("\n%s\t\t", dir[i].dname);
for (int k = 0; k < dir[i].fileCount; k++)
printf("%s\n\t\t", dir[i].fname[k]);
}
}
break;
default:
exit(0);
}
}
}