Salut tt le monde !
Notre prof d'algorithme nous a donné un projet a faire ( mini moteur de recherche )
donc l'utilisateur va entrer un fichier texte et va designer le nombre de ligne par page
je dois faire l'index de tt les mots dans ce fichier :
Voila mon projet a faire :
http://djaguera.jimdo.com/tpl2/
et voila mon main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct page page;
struct page
{
     page *svt;
     page *prec;
     int pg;
     int occ;
};
 
typedef struct word word;
struct word
{
  word* suivant;
  page* first;
  page* last ;
  char wrd[256];
};
 
typedef struct index index ;
struct index {
    char indice;
    word* contenu;
};
 
void initINDEX (index IDX[] )
{
    int i ;
    char c ;
 
    c = 'a';
    for(i=0;i<26;i++)
    {
        IDX[i].indice = c ;
        IDX[i].contenu = NULL ;
        c++ ;
 
    }
}
 
void ajouTETE (index IDX[], char mot[], int i)
{
    word* id ;
    id = malloc(sizeof(word));
    strcpy(id->wrd , mot);
    id->first = NULL ;
    id->last = NULL ;
    id->suivant = NULL ;
    IDX[i].contenu = id ;
 
}
 
void ajoutCROISSANT (index IDX[] , char mot[],int i , word** W )
{
    word* prec ;
    word* p ;
    word* nv ;
 
    p = IDX[i].contenu ;
 
    while ((p != NULL) && (stricmp(p->wrd , mot)  < 0))
    {
        prec = p ;
        p = p->suivant ;
    }
    printf("je viens de sortir du while  \n");
    if (stricmp(p->wrd , mot) == 0)
    {
        printf("je suis dans le cas d egalite \n");
        *W = p ;
 
    }
    else
    {
    nv = (word*)malloc(sizeof(word));
    strcpy(nv->wrd , mot );
    nv->suivant = p ;
    prec->suivant = nv ;
    *W = nv ;
        printf("je suis dans le cas de inserer apres \n");
    }
 
 
 
}
int returnINDICETAB (char c )
{
    int i ;
    if (c < 91)
    i = c - 60 ;
    else
    {
    i = c - 97 ;
    }
    return i ;
}
void ajouteMOT (index IDX[],char mot[] ,word** W)
{
    int i ;
 
    i = returnINDICETAB ( mot[0] );
    if (IDX[i].contenu == NULL)
    {
    ajouTETE(IDX ,mot,i);
    *W = IDX[i].contenu ;
    }  
    else
    {
    ajoutCROISSANT(IDX,mot,i,&(*W));
    }
 
}
 
page* initPAGE(int num_p)
{
    page* p ;
    p = (page*)malloc(sizeof(page)) ;
    p->occ = 1 ;
    p->pg = num_p ;
    p->svt = NULL ;
    p->prec = NULL ;
 
        return p ;
}
 
void insertPAGE (word** W , int num_p)
{
    page* p ;
    p = initPAGE(num_p);
    if ((*W)->first == NULL )
    {
 
    (*W)->first = p ;
    (*W)->last = p ;
    }
    else
    {
        (*W)->last->svt = p ;
        p->prec = (*W)->last ;
        (*W)->last = p ;
    }
 
 
}
void remplissageINDEX (index IDX[],char nomf[], int nbr_l)
{
    char chaine[256];
    char ligne[256];
    char* motf ;
    int i ,id, page ;
    word* W ;
    FILE* fichier ;
    fichier = fopen(nomf, "r");
 
    if (fichier != NULL)
               {
    page = 1 ;
    i = 1 ;
    while (fgets(ligne ,256,fichier)!= NULL)
    {
    motf = strtok(ligne , " ");
    while ( motf != NULL )
       {
       strcpy(chaine,motf);
 
       ajouteMOT(IDX,chaine,&W);
       printf("%s\n",chaine);
       if (W->first == NULL )
       {
        insertPAGE(&W,page);
       }
       else if (W->last->pg == page )
       {
        W->last->occ ++ ;
          printf("%d\n",W->last->occ) ;
       }
       else
       {
        insertPAGE(&W,page);
       }
       motf = strtok ( NULL , " " );   
       }
              i++ ;
    if (i == nbr_l)
        {
        i = 1 ;
        page ++ ;
        }  
    }
 
 
              }
    else
    {
        printf("Impossible d'ouvrir le fichier %s !",nomf);
    }
}
 
void afficherQuatre (index IDX[] )
{
    char reponse[3] ;
    int i ;
    int j ;
    int BS ;
    int BI ;
    word* DX ;
 
    i = 0 ;
    BI = 0 ;
    BS = 4 ;
    while (i <= 7 ) { /* il affiche 6 fois un groupe de 4 et la derniere un groupe de 2 */
        for (j=BI;j<BS;j++)
        {
        DX = IDX[j].contenu ;
        while (DX != NULL )
            {
        printf("\t%s",DX->wrd) ;
        DX = DX->suivant ;
            }
        }
        BI = BI + 4 ;
        BS = BS + 4 ;
        do            {
        printf("Voulez-vous continuer l affichage de l index pour les 4 prochaines caractère ?\n");
        printf("Tapez OUI pour continuer ou NON pour revenir a l acceuil : ");
        scanf("%s",&reponse);
        if (strcmp(reponse ,"OUI") == 0 )
        {
         i++ ;
        }
        else if (strcmp(reponse , "NON") == 0)
        {
            break ;
        }
 
                       } while ((strcmp(reponse , "OUI") == 0)||(strcmp(reponse , "NON") == 0));       
                }
}
 
void indexMOT ( index IDX[] )
{
    int i ;
    char mot[256];
    word* W ;
    page* affiche ;
    printf("Entrer le mot que vous cherchez :");
    scanf("%s",&mot);
    i = returnINDICETAB(mot[0]);
    W = IDX[i].contenu ;
    while ((strcmp(W->wrd,mot) != 0) && (W != NULL))
    {
        W = W->suivant ;
    }
    if (W != NULL)
    {
        affiche = W->last ;
        printf("INDEX du mot %s est :\n",W->wrd);
        while (affiche != NULL)
        printf("page : %d ====> occurance :%d\n",affiche->pg,affiche->occ);
        affiche = affiche->prec ;
    }
    else
    printf ("%s n existe pas dans l index des mots !\n",mot);
}
/* void ajouteMOT existe deja donc il suffit de l'appeler pour ajouter un mot dans l'index */
 
void supprimerMOT (index IDX[])
{
    int i ;
    char mot[256];
    word* p ;
    word* prec ;
 
    printf("Entrer le mot que vous voulez supprimer de l index :");
    scanf("%s",&mot);
    i = returnINDICETAB(mot[0]);
    p = IDX[i].contenu ;
    while ((strcmp(p->wrd,mot)!=0)&&(p != NULL))
    {
        prec = p ;
        p = p->suivant ;
    }
    if ( p != NULL )
    {
        prec->suivant = p->suivant ;
        free ( p );
    }
    else
    printf ("%s n existe pas dans l index des mots !\n",mot);
}
 
 
int main(int argc, char *argv[]) {
    system("COLOR 02");
    index id[26] ;
    char motf[256];
    int nbr_l;
 
    initINDEX(id) ;
    printf("Entrez le mot de votre fichier :");
    scanf("%s",&motf);
    printf("\nDesignez le nombre de ligne par page :  ");
    scanf("%d",&nbr_l);
    remplissageINDEX(id,motf,nbr_l);
        afficheQuatre(id)
    system("pause");
    return 0;
}
a la ligne 70 il sort d'une boucle while et il n'entre pas dans les 2 if !!
j'ai pas pu trouver l'erreur !!
vous devez créer un fichier texte et le remplir avec des mots pour compiler ce programmme
SVP aidez moi a trouver l'erreur