-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearchStudent.c
More file actions
145 lines (119 loc) · 2.9 KB
/
searchStudent.c
File metadata and controls
145 lines (119 loc) · 2.9 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
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
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include "school_system.h"
extern FILE* fp;
void searchStudent(void)
{
int search_id = 0;
char search_name[MAXSIZE] = { 0 };
char search_phone[MAXSIZE] = { 0 };
char search_email[MAXSIZE] = { 0 };
char mode = 0;
bool name_exist = false;
bool phone_exist = false;
bool email_exist = false;
STUDENT rec = { 0 };
printf("\n-----You can search student by ID(i), Name(n), Phone number(p), e-mail(e)-----\n");
printf("select mode(i/n/p/e): ");
scanf(" %c", &mode);
switch(mode)
{
case 'i':
printf("\n-----Enter Student_ID to search-----\n");
printf("Enter here: ");
scanf("%d", &search_id);
fseek(fp, (search_id - STARTID)*(long)sizeof(rec), SEEK_SET);
if((fread(&rec, sizeof(rec), 1, fp) > 0) && (rec.id != 0))
{
printf("%d %s %s %s %s %s %d %s %s\n", rec.id, rec.name, rec.phone, rec.email,
rec.addr, rec.major, rec.scholar, rec.multimajor, rec.state);
}
else
{
printf("Not Exist\n");
}
break;
case 'n':
printf("\n-----Enter Name to search-----\n");
printf("Enter here: ");
scanf("%s", search_name);
rewind(fp);
while(fread(&rec, sizeof(rec), 1, fp) > 0)
{
if(rec.id == 0)
{
continue;
}
if(strncmp(rec.name, search_name, strlen(rec.name)) == 0)
{
printf("%d %s %s %s %s %s %d %s %s\n", rec.id, rec.name, rec.phone, rec.email,
rec.addr, rec.major, rec.scholar, rec.multimajor, rec.state);
name_exist = true;
}
else
{
continue;
}
}
if (!name_exist)
{
printf("Not Exist\n");
}
break;
case 'p':
printf("\n-----Enter Phone number to search-----\n");
printf("Enter here: ");
scanf("%s", search_phone);
rewind(fp);
while(fread(&rec, sizeof(rec), 1, fp) > 0)
{
if(rec.id == 0)
{
continue;
}
if(strncmp(rec.phone, search_phone, strlen(rec.phone)) == 0)
{
printf("%d %s %s %s %s %s %d %s %s\n", rec.id, rec.name, rec.phone, rec.email,
rec.addr, rec.major, rec.scholar, rec.multimajor, rec.state);
phone_exist = true;
}
else
{
continue;
}
}
if (!phone_exist)
{
printf("Not Exist\n");
}
break;
case 'e':
printf("\n-----Enter e-mail to search-----\n");
printf("Enter here: ");
scanf("%s", search_email);
rewind(fp);
while(fread(&rec, sizeof(rec), 1, fp) > 0)
{
if(rec.id == 0)
{
continue;
}
if(strncmp(rec.email, search_email, strlen(rec.email)) == 0)
{
printf("%d %s %s %s %s %s %d %s %s\n", rec.id, rec.name, rec.phone, rec.email,
rec.addr, rec.major, rec.scholar, rec.multimajor, rec.state);
email_exist = true;
}
else
{
continue;
}
}
if (!email_exist)
{
printf("Not Exist\n");
}
break;
}
}