-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomSearch.c
155 lines (143 loc) · 3.25 KB
/
customSearch.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
#include "customSearch.h"
#include <stdio.h>
#include <string.h>
#include "openFile.h"
void research(char activité[50],char dpt[50]) {
FILE * acces_fichier; // POINTEUR POUR LE CHEMIN DU FICHIER
T_Etudiant etu; // JSPLUS
int i; // I
acces_fichier = fopen(activité, "rt");
if (acces_fichier != NULL)
{ // SI LE FICHIER S'EST OUVERT
i = 0;
while (! feof(acces_fichier)) { // TANT QUON EST PAS A LA FIN DU FICHIER
fscanf(acces_fichier, "%s %s", etu.nom, etu.dpt); // SCAN DE LA LIGNE FORMAT : NOM DPT
if (strcmp(etu.dpt,dpt) == 0)
{
printf("%s / %s\n", etu.nom, etu.dpt); // ECRIRE CHAQUE LIGNE 1 PAR 1
}
i++;
}
}
fclose(acces_fichier);
}
int customSearch() {
T_Ensemble sport;
T_Ensemble musique;
int reponse;
int dep;
int act;
int i;
printf("= Recherche avancée =\n\n");
printf("Voulez vous faire une recherche par :\n-département(1) \n-activité(2) \n-les deux(3)\n");
scanf("%d", &reponse);
if(reponse == 1)
{
printf("Quelle département voulez-vous ?\n (1)GMP (2)STID (3)GEA (4)INFO (5)TC\n");
scanf("%d", &dep);
if (dep == 1)
{
research("data/IUT.txt", "GMP");
}
else if (dep == 2)
{
research("data/IUT.txt", "STID");
}
else if (dep == 3)
{
research("data/IUT.txt", "GEA");
}
else if (dep == 4)
{
research("data/IUT.txt", "INFO");
}
else if (dep == 5)
{
research("data/IUT.txt", "TC");
}
}
else if(reponse == 2)
{
printf("Quelle activité voulez-vous ?\n (1)Sport (2)Musique\n");
scanf("%d", &act);
if (act == 1)
{
sport = openFile("data/SPORT.txt", "rt");
for(i =0; i<sport.nombreTotalEtudiants; i++)
{
printf("%d %s %s\n",i+1 , sport.ensemble[i].nom, sport.ensemble[i].dpt );
}
}
else if (act == 2)
{
musique = openFile("data/MUSIQUE.txt", "rt");
for(i =0; i<musique.nombreTotalEtudiants; i++)
{
printf("%d %s %s\n",i+1 , musique.ensemble[i].nom, musique.ensemble[i].dpt );
}
}
else{
printf("Saisie invalide.");
}
}
else if(reponse == 3)
{
printf("Quelle activité voulez-vous ?\n (1)Sport (2)Musique\n");
scanf("%d", &act);
if (act == 1)
{
printf("Quelle département voulez-vous ?\n (1)GMP (2)STID (3)GEA (4)INFO (5)TC\n");
scanf("%d", &dep);
if (dep == 1)
{
research("data/SPORT.txt", "GMP");
}
else if (dep == 2)
{
research("data/SPORT.txt", "STID");
}
else if (dep == 3)
{
research("data/SPORT.txt", "GEA");
}
else if (dep == 4)
{
research("data/SPORT.txt", "INFO");
}
else if (dep == 5)
{
research("data/SPORT.txt", "TC");
}
}
else if (act == 2)
{
printf("Quelle département voulez-vous ?\n (1)GMP (2)STID (3)GEA (4)INFO (5)TC\n");
scanf("%d", &dep);
if (dep == 1)
{
research("data/MUSIQUE.txt", "GMP");
}
else if (dep == 2)
{
research("data/MUSIQUE.txt", "STID");
}
else if (dep == 3)
{
research("data/MUSIQUE.txt", "GEA");
}
else if (dep == 4)
{
research("data/MUSIQUE.txt", "INFO");
}
else if (dep == 5)
{
research("data/MUSIQUE.txt", "TC");
}
}
}
else
{
printf("Saisie invalide, veuillez réessayer.");
}
return 0;
}