forked from AugustineAykara/CPU-Scheduling-Algorithm-In-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSingle_Level_Dir_File.c
More file actions
103 lines (92 loc) · 2.14 KB
/
Single_Level_Dir_File.c
File metadata and controls
103 lines (92 loc) · 2.14 KB
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
// CPU-Scheduling-Algorithm-In-C
// Single Level Directory File Organization
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct {
char fileName[50][50];
int fileCount;
}dir;
void main()
{
char file[50];
int choice, i;
dir.fileCount = 0;
do {
printf("\n 1. CREATE FILE \n 2. DELETE FILE \n 3. SEARCH FILE \n 4. DISPLAY FILES \n 5. EXIT \n");
printf("\n Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
case 1: printf("\n Enter the name of file : ");
scanf("%s", file);
for(i=0; i<dir.fileCount; i++)
{
if(strcmp(file, dir.fileName[i]) == 0)
{
printf("\n File %s NOT CREATED (file already EXIST)\n", file);
break;
}
}
if (i == dir.fileCount)
{
strcpy(dir.fileName[dir.fileCount], file);
printf("\n File %s is CREATED\n", dir.fileName[dir.fileCount]);
dir.fileCount++;
}
break;
case 2: if(dir.fileCount == 0)
{
printf("\n Directory is EMPTY (no files to DELETE)\n");
break;
}
printf("\n Enter the name of file : ");
scanf("%s", file);
for(i=0; i<dir.fileCount; i++)
{
if(strcmp(file, dir.fileName[i]) == 0)
{
printf("\n File %s is DELETED\n", file);
strcpy(dir.fileName[i], dir.fileName[dir.fileCount-1]);
break;
}
}
if (i == dir.fileCount)
{
printf("\n File %s NOT FOUND\n", file);
}
else
{
dir.fileCount--;
}
break;
case 3: printf("\n Enter the name of file : ");
scanf("%s", file);
for(i=0; i<dir.fileCount; i++)
{
if(strcmp(file, dir.fileName[i]) == 0)
{
printf("\n File %s is FOUND :)\n", file);
break;
}
}
if(i == dir.fileCount)
{
printf("\n File %s NOT FOUND :(\n", file);
}
break;
case 4: if(dir.fileCount == 0)
{
printf("\n Directory is EMPTY");
}
for(i=0; i<dir.fileCount; i++)
{
printf("\n %d. %s", i+1, dir.fileName[i]);
}
printf("\n");
break;
case 5: exit(0);
}
printf("\n---------------------------------------------------------------------\n");
}while(1);
}