-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSMS.c
330 lines (326 loc) · 8.64 KB
/
SMS.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
/* Name: Student Management System (SMS)
Copyright: root@kunu247
Author: Mr. Kunal Mendarkar
Date: 05-03-22 15.39
Description: Student Management System (SMS) is a system to
record, update, manage students basic details in C programming */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<windows.h>
#include<string.h>
// function declaration
void gotoxy(int ,int );
void menu();
void add();
void view();
void search();
void modify();
void deleterec();
// creating structure for student variable
struct student {
char name[20];
char mobile[10];
int roll;
char course[20];
char branch[20];
};
// -------------------------------------------------
// main function
int main() {
gotoxy(15,3);
printf("<--:Student Record Management System:-->");
gotoxy(15, 5);
system("type logo.txt");
gotoxy(19,15);
printf("Press any key to continue.");
getch();
menu();
return 0;
}
// -------------------------------------------------
// menu function
void menu() {
int choice;
system("cls && color CF");
gotoxy(10,3);
printf("<--:MENU:-->");
gotoxy(10,5);
printf("Enter appropriate number to perform following task.");
gotoxy(10,7);
printf("[ 1 ] : Add Record");
gotoxy(10,8);
printf("[ 2 ] : View Record");
gotoxy(10,9);
printf("[ 3 ] : Search Record");
gotoxy(10,10);
printf("[ 4 ] : Modify Record");
gotoxy(10,11);
printf("[ 5 ] : Delete");
gotoxy(10,12);
printf("[ 6 ] : Exit");
gotoxy(10,13);
printf("[ 7 ] : About");
gotoxy(10,16);
printf(" | Enter your choice = ");
scanf("%d", &choice);
// -------------------------------------------------
switch(choice) {
// when 1 pressed
case 1:
add();
break;
// when 2 pressed
case 2:
view();
break;
// when 3 pressed
case 3:
search();
break;
// when 4 pressed
case 4:
modify();
break;
// when 5 pressed
case 5:
deleterec();
break;
// when 6 pressed
case 6:
exit(1);
break;
// when 7 pressed
case 7:
system("cls && color 0E && type about.txt");
break;
// when invalid value entered
default:
gotoxy(10,17);
printf("Error !!! Invalid Choice.");
}
// -------------------------------------------------
}
// add function
void add() {
FILE *fp;
struct student std;
char another ='y';
system("cls && color 09");
fp = fopen("record.txt","ab+");
if(fp == NULL){
gotoxy(10,5);
printf("Error opening file");
exit(1);
}
fflush(stdin);
while(another == 'y')
{
gotoxy(10,3);
printf("<--:ADD RECORD:-->");
gotoxy(10,5);
printf("Enter details of student.");
gotoxy(10,7);
printf("[+] Enter Name : ");
// gets(std.name);///???
gets(std.name);
gotoxy(10,8);
printf("[+] Enter Mobile Number : ");
gets(std.mobile);
gotoxy(10,9);
printf("[+] Enter Roll No : ");
scanf("%d",&std.roll);
fflush(stdin);
gotoxy(10,10);
printf("[+] Enter Course : ");
// gets(std.course);///???
gets(std.course);
gotoxy(10,11);
printf("[+] Enter Branch : ");
gets(std.branch);
// gotoxy(10,12);
// printf("Enter Father's Name : ");
// gets(std.fathername);
fwrite(&std,sizeof(std),1,fp);
gotoxy(10,15);
printf("[ # ] Want to add of another record? Then press 'y' else 'n'.");
fflush(stdin);
// another = getch();///???
another = getch();
system("cls ");
fflush(stdin);
}
fclose(fp);
gotoxy(10,18);
printf("Press any key to continue.");
getch();
menu();
}
// ----------------------------------------------------------------------------------------------------------
// View Function
void view() {
FILE *fp;
int i=1,j;
struct student std;
system("cls && color 1E");
gotoxy(10,2);
printf("<--:VIEW RECORD:-->");
gotoxy(10,4);
printf("| ----- | ---------------------- | ------------ | --------- | ------------ | ------------ |");
// printf("| 1 | kunal | 894254254 | 21 | BCA | kamothe |");
gotoxy(10,5);
printf("| Sr.No | Name of Student | Mobile No | Roll No | Course | Branch |");
gotoxy(10,6);
printf("| ----- | ---------------------- | ------------ | --------- | ------------ | ------------ |");
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,8);
printf("Error opening file.");
exit(1);
}
j=7;
while(fread(&std,sizeof(std),1,fp) == 1){
gotoxy(10,j);
printf("| %-5d | %-22s | %-12s | %-9d | %-12s | %-12s |",i,std.name,std.mobile,std.roll,std.course,std.branch);
i++;
j++;
}
fclose(fp);
gotoxy(10,j+3);
printf("Press any key to continue.");
getch();
menu();
}
// -------------------------------------------------
// search function
void search() {
FILE *fp;
struct student std;
char stname[20];
system("cls && color 0E");
gotoxy(10,3);
printf("<--:SEARCH RECORD:-->");
gotoxy(10,5);
printf("| Enter name of student : ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
while(fread(&std,sizeof(std),1,fp ) == 1){
if(strcmp(stname,std.name) == 0){
gotoxy(10,8);
printf("| Name : %s",std.name);
gotoxy(10,9);
printf("| Mobile Number : %s",std.mobile);
gotoxy(10,10);
printf("| Roll No : %d",std.roll);
gotoxy(10,11);
printf("| Course : %s",std.course);
gotoxy(10,12);
printf("| Branch : %s",std.branch);
}
}
fclose(fp);
gotoxy(10,16);
printf("Press any key to continue.");
getch();
menu();
}
void modify() {
char stname[20];
FILE *fp;
struct student std;
system("cls && color 0A");
gotoxy(10,3);
printf("<--:MODIFY RECORD:-->");
gotoxy(10,5);
printf("Enter name of student to modify: ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
rewind(fp);
fflush(stdin);
while(fread(&std,sizeof(std),1,fp) == 1)
{
if(strcmp(stname,std.name) == 0){
gotoxy(10,7);
printf("[~] Enter name: ");
gets(std.name);
gotoxy(10,8);
printf("[~] Enter mobile number : ");
gets(std.mobile);
gotoxy(10,9);
printf("[~] Enter roll no : ");
scanf("%d",&std.roll);
gotoxy(10,10);
printf("[~] Enter Course : ");
fflush(stdin);
gets(std.course);
gotoxy(10,11);
printf("[~] Enter Branch : ");
fflush(stdin);
gets(std.branch);
fseek(fp , sizeof(std),SEEK_CUR);
fwrite(&std,sizeof(std),1,fp);
break;
}
}
fclose(fp);
gotoxy(10,16);
printf("Press any key to continue.");
getch();
menu();
}
// delete record function
void deleterec() {
char stname[20];
FILE *fp,*ft;
struct student std;
system("cls && color 0c");
gotoxy(10,3);
printf("<--:DELETE RECORD:-->");
gotoxy(10,5);
printf(" | Enter name of student to delete record : ");
fflush(stdin);
gets(stname);
fp = fopen("record.txt","rb+");
if(fp == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
ft = fopen("temp.txt","wb+");
if(ft == NULL){
gotoxy(10,6);
printf("Error opening file");
exit(1);
}
while(fread(&std,sizeof(std),1,fp) == 1){
if(strcmp(stname,std.name)!=0)
fwrite(&std,sizeof(std),1,ft);
}
fclose(fp);
fclose(ft);
remove("record.txt");
rename("temp.txt","record.txt");
gotoxy(10,10);
printf("Press any key to continue.");
getch();
menu();
}
void gotoxy(int x,int y)
{
COORD c;
c.X=x;
c.Y=y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),c);
}