-
Notifications
You must be signed in to change notification settings - Fork 0
/
searchRecord.c
90 lines (86 loc) · 2.47 KB
/
searchRecord.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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "dataFormat.h"
int findRecord (EVENT_T *allData,int count,char *input,int menu);
int searchRecord (EVENT_T *allData,int count)
{
char input[32];
int year = -1;
int i;
int menu = 0;
int correct = 1;
menu = integerInput("PLEASE INSERT TYPE OF DATA : ",1,3);
printf("---------------------------------------------------------------------\n");
switch (menu)
{
case 1:
printf("\t\t Search by TYPE OF EVENT \t\t\n");
printf("---------------------------------------------------------------------\n");
checkEventType (input);
break;
case 2:
printf("\t\t Search by YEAR OF EVENT \t\t\n");
printf("---------------------------------------------------------------------\n");
do
{
memset(input,0,sizeof(input));
printf("PLEASE INSERT YEAR OF EVENT : ");
fgets(input,sizeof(input),stdin);
sscanf(input,"%d",&year);
}while (year < 0 || year > 3000);
sscanf(input,"%s",input);
break;
case 3:
memset(input,0,sizeof(input));
printf("\t\t Search by DISTRICT \t\t\n");
printf("---------------------------------------------------------------------\n");
checkDistrict(input);
break;
}
printf("---------------------------------------------------------------------\n");
printf("SEARCH QUERY : %s\n",input);
printf("---------------------------------------------------------------------\n");
findRecord (allData,count,input,menu);
}
int findRecord (EVENT_T *allData,int count,char *input,int menu)
{
int i = 0;
int index = 0;
char *typeOfGhost;
char *eventYear;
for (i = 0; i < count; i++)
{
if (menu == 1)
{
typeOfGhost = strstr(allData[i].typeOfEvent,input);
if (typeOfGhost != NULL)
{
printf("* %02d: Found '%s' in record NO. %02d\n", index+1 ,input,i+1);
showEvent (allData[i]);
index++;
}
}
else if (menu == 2)
{
eventYear = strstr(allData[i].date,input);
if (eventYear != NULL)
{
printf("* %02d: Found '%s' in record NO. %02d\n", index+1 ,input,i+1);
showEvent (allData[i]);
index++;
}
}
else
{
if (strcmp(allData[i].district,input) == 0)
{
printf("* %02d: Found '%s' in record NO. %02d\n", index+1 ,input,i+1);
showEvent (allData[i]);
index++;
}
}
}
printf("* Number of result : %2d\n",index);
printf("---------------------------------------------------------------------\n");
}