-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrm.c
More file actions
73 lines (72 loc) 路 1.71 KB
/
Copy pathrm.c
File metadata and controls
73 lines (72 loc) 路 1.71 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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(int argc, char* argv[])
{
if (argc <= 2)
{
printf("Enter some file arguments");
}
else if (argc == 3 && strcmp(argv[2], "-i") != 0 &&strcmp(argv[2], "-f") != 0)
{
FILE *f = NULL;
f = fopen(argv[2], "w");
if (f == NULL)
{
printf("File is write protected or File is not available");
exit(1);
}
int y = remove(argv[2]);
if (y != 0)
{
printf("Error occured");
exit(1);
}
}
else if (argc == 4 && strcmp(argv[2], "-i") == 0)
{
char c;
printf("You want to remove filename:%s (y/n)?", argv[3]);
scanf("%c", &c);
if (c == 'y')
{
FILE *f = NULL;
f = fopen(argv[3], "w");
if (f == NULL)
{
printf("File is write protected or File not availbale \n");
exit(1);
}
int y=remove(argv[3]);
if (y != 0)
{
printf("Error occured");
exit(1);
}
}
else if (c == 'n')
{
exit(0);
}
else{
printf("Inavlid input");
}
}
else if (argc == 4 && strcmp(argv[2], "-v") == 0)
{
FILE *f = NULL;
f = fopen(argv[3], "w");
if (f == NULL)
{
printf("File is write protected or File is not available");
exit(1);
}
int y=remove(argv[3]);
if (y != 0)
{
printf("Error occured");
exit(1);
}
printf("File : %s removed..", argv[3]);
}
}