-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBruteForceFiling.c
145 lines (112 loc) · 3.75 KB
/
BruteForceFiling.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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<sys/stat.h>
int main()
{
// file name is data.txt
char input='x';
int ignore = 0;
printf("Press 'a' to add new student.\nPress 'b' to read students record.\nPress 'c' delete student record from file.\nOr any other key to exit.\n");
ignore = scanf("%c", &input); // input
if (input == 'a') // if a is pressed
{
char name[50];
char rollNo[15]; // name email and roll number
char email[50];
printf("Enter name: ");
ignore = scanf("%s", name);
printf("Enter roll number: ");
ignore = scanf("%s", rollNo);
printf("Enter email: ");
ignore = scanf("%s", email);
printf("%s\n%s\n%s\nrecord has been added.\n", name, rollNo,email);
FILE* file;
file = fopen("data.txt", "a"); // add new student
ignore = fprintf(file, "\n%s", name);
ignore = fprintf(file, "\n%s", rollNo);
ignore = fprintf(file, "\n%s", email);
fclose(file);
}
else if (input == 'b') // if b is pressed
{
int secInput=-1;
printf("Press 0 to view your record.\nPress 1 to view 1st record.\nPress 2 to view 2nd record.\n");
ignore=scanf("%d", &secInput);
char name[50];
char rollNo[15];
char email[50];
char Waste[50];
FILE* file;
file = fopen("data.txt", "r");
for (int i = 0; i < secInput; i++) // geting desired student
{
ignore = fscanf(file, "%[^\n]\n", Waste);
ignore = fscanf(file, "%[^\n]\n", Waste);
ignore = fscanf(file, "%[^\n]\n", Waste);
}
ignore = fscanf(file, "%[^\n]\n", name);
ignore = fscanf(file, "%[^\n]\n", rollNo);
ignore = fscanf(file, "%[^\n]\n", email);
fclose(file);
printf("Name: %s\n", name);
printf("Roll nunber: %s\n", rollNo); // printing information of that student.
printf("email: %s\n", email);
}
else if (input == 'c') // if c is pressed
{
int secInput = -1;
printf("Press 0 to delete your record.\nPress 1 to delete 1st record.\nPress 2 to delete 2nd record.\n");
ignore = scanf("%d", &secInput);
char name1[50];
char rollNo1[15];
char email1[50];
char name2[50];
char rollNo2[15];
char email2[50];
char name3[50]; // name roll number and email of all three studentss...
char rollNo3[15];
char email3[50];
FILE* file;
file = fopen("data.txt", "r");
ignore = fscanf(file, "%[^\n]\n", name1);
ignore = fscanf(file, "%[^\n]\n", rollNo1);
ignore = fscanf(file, "%[^\n]\n", email1);
ignore = fscanf(file, "%[^\n]\n", name2);
ignore = fscanf(file, "%[^\n]\n", rollNo2); // reading data of all three students
ignore = fscanf(file, "%[^\n]\n", email2);
ignore = fscanf(file, "%[^\n]\n", name3);
ignore = fscanf(file, "%[^\n]\n", rollNo3);
ignore = fscanf(file, "%[^\n]\n", email3);
fclose(file);
file = fopen("data.txt", "w");
if (secInput != 0)
{
ignore = fprintf(file, "%s", name1);
ignore = fprintf(file, "\n%s", rollNo1);
ignore = fprintf(file, "\n%s\n", email1);
}
if (secInput != 1)
{
ignore = fprintf(file, "%s", name2); // writing back the data expect the one who is deleted...
ignore = fprintf(file, "\n%s", rollNo2);
ignore = fprintf(file, "\n%s\n", email2);
}
if (secInput != 2)
{
ignore = fprintf(file, "%s", name3);
ignore = fprintf(file, "\n%s", rollNo3);
ignore = fprintf(file, "\n%s", email3);
}
if(secInput<=2 && secInput>-1)
{
printf("deleted succesffully.\n");
}
else
{
printf("delete Unsuccessful.\n");
}
fclose(file);
}
return 0;
}