bonjour,
je demande d'aide sur les arbres binaire car je travaille dessus:
j'ai fait un code en Dev C++ dont le but de lire et extraire les données d'un fichier bien défini qui est structurer d'une telle maniere .
mon programme je l'ai fait de telle sorte me demande d'écrire le nom de fichier puis il va le récupérer pour un traitement éventuel mais moi je bloque ici avant la récupération.


ci dessous mon code;


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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
#include <stdlib.h>
 #include <stdio.h>
 
                          /*INCLUDES*/
#include <windows.h>
#include<winsock2.h>
#include <mem.h>
#include <stdio.h>
#include <dos.h>
#include <myconio.h>
#include <malloc.h>
#include <errno.h>
#include <stdlib.h>
//#include <dir.h>
#include <string.h>
 
/*les defenitions*/
 
#define vide printf("\n");
 #define ATT_FONT_G        BLUE
#define ATT_TEXT_G        WHITE        /* definition des couleurs du menu des modules */
#define ATT_FONT_MESS     RED
#define ATT_TEXT_MESS     WHITE
 
#define MAXPATH  2
#define MAXDRIVE 2
#define MAXFILE 10
#define MAXDIR 10
#define MAXEXT 10
 
 
                  /*TOUCHE CLAVIER*/
#define  ESC 27
#define  ret 10                /* définition les touches de clavier utilisées */
#define  espace 32    
#define  arr 46
#define  f1 113
 
 
                         /*PROTOTYPE*/
 void menu_haut1(); 
 void menu_haut2();
 void cadre();
 void info(const char * txt);
 
 void construction_n_fich(char *n_fich,const char *type,int cle);     
char *acq_nfich(const char *ch,const char *mode);      
 void message(char *ch);
 void exit_prg();
 void effacefenetre(int dc,int dl,int fc,int fl,int att_font,int att_text);  /* effacer une fent */
 void fenetre(int dc,int dl,int fc,int fl,int att_rect,int att_font); /* colorer une fent rectangulaire */
void rectangl(int dc, int dl,int longer, int larg);             /* rectangle */
int lec_fich(FILE *p);                                       /* lecture du fichier *.arb */
 
 void error_message(int fc,const char *ch); 
 
 
 
 
                            /*PROGRAMME PRINCIPALE */
 int main ()
 {
 
      char *nfich1;
      cadre();
 
    info("VEUILLEZ APPUYER SUR UNE TOUCHE SVP POUR ACCEDER A L'APLLICATION");
 
 
 
menu_haut2();
 
   menu_haut1();
   nfich1=acq_nfich("NOM DE FILE : ...............(arb)","rt");
  // clrscr();
 
 
      return 0;
      }
 
                                  /*FONCTION*/
void menu_haut1()
{
     int i;
     char *nfich1;
   int tch,cle;
  effacefenetre(1,1,80,25,ATT_FONT_G + RED,ATT_TEXT_G);
 
  //window(1,25,80,25);
textcolor(WHITE); textbackground(BLUE); 
clrscr();
   gotoxy(30,1);
  printf("* LOGIQUE *");
 gotoxy(50+1,2+1);
   textcolor(BLACK); 
   textbackground(WHITE); 
   gotoxy(35+1,20+1);
   cprintf(" ESC-Quit                 F1-Aide\n");
   //window(1,1,80,1);
 
 getch();
 
 nfich1=acq_nfich("NOM DE L'AdD : ..................(arb)","rt");
//getch();
  fenetre(1,2,80,24,ATT_TEXT_G,ATT_FONT_G);
 
  do{
 
      gotoxy(15,1);
      printf("INTRODUCTION DES DONNEES LOGIQUES D'UN AdD\n");
     getch();
      tch=getch();
      switch(tch){
       case ESC:   exit(0);
       case  f1:   ; printf("vous voulez d'aide\n"); break;
       default:   cle=0; break;}
      } while(cle==1);
    getch();
}
 
void menu_haut2()
  {
    int tch,cle;
    effacefenetre(1,2,80,23,ATT_FONT_G,ATT_TEXT_G);
    //window(1,25,80,25);
    textcolor(BLACK); textbackground(WHITE); clrscr();
    gotoxy(2,2);
   cprintf("  ESC-Quit              F1-Aide");
   // window(1,1,80,1);
    textcolor(BLACK); textbackground(WHITE); clrscr();
    gotoxy(35,1);
    cprintf("* KUMAMOTO *");
    fenetre(1,2,80,20+3,ATT_TEXT_G,ATT_FONT_G+RED);
    do{
      gotoxy(10,10);
      printf("  RECHERCHE DES ENSEMBLES MINIMAUX D'UN SYSTEME NON COHERENT ");
      gotoxy(25,12);
      printf("PAR LA METHODE DESCENDANTE .");
      tch=bioskey(0);
      switch(tch){
       case ESC:   exit(0);
       case  f1:   cle=1;printf(" vous voulez d'aide\n"); break;
       default:    cle=0; break;}
     } while(cle==1);
     getch();
     effacefenetre(3,3,78,23,ATT_FONT_G,ATT_TEXT_G);
    gotoxy(7,0);
   }
   // Affiche dans un cadre
void info(const char * txt)
{
     int i;
     textcolor(WHITE);
     textbackground(GREEN); 
 
	  gotoxy(2,9); printf("%c",201); for( i=0; i<75; i++) printf("%c",205); printf("%c",187);
	  gotoxy(2,10); printf("%c %s",186,txt); gotoxy(3+75,10);      printf("%c",186);
	  gotoxy(2,11); printf("%c",200); for( i=0; i<75; i++) printf("%c",205); printf("%c",188);
 
	}
 
// Créer le cadre 
void cadre()
{
     int i;
    textcolor(WHITE);
	textbackground(BLUE);
	  printf("\n");
	  for( i=0; i < 70; i++) printf("%c",223);
	  printf("\n");
	  for( i=0; i < 20; i++) printf("%c \t\t\t\t\t\t\t\t     %c\n",223,223);
	  for( i=0; i < 70; i++) printf("%c",223);
}
 
 
void construction_n_fich(char *n_fich,const char *type,int cle) 
{
     char FILENAME;
    int flag;
    char drive[2],file[MAXFILE],ext[MAXEXT],dir[MAXDIR];
    char s[MAXPATH];
 
  flag=fnsplit(n_fich,drive,dir,file,ext);
 
    if(flag&FILENAME)
    strcpy(ext,type);
    if(cle==1)         
    fnmerge(n_fich,NULL,NULL,file,ext);
    else
 
fnmerge(n_fich,drive,dir,file,ext);
}
 
void message(char *ch)
{
   int tch;
 
   textcolor(ATT_FONT_MESS);
   textbackground(WHITE);
   gotoxy(7,0);
   clrscr();
   cprintf("%s",ch);
   tch=bioskey(0);
   switch(tch){
     case f1:    printf("VOUS VOULEZ D'AIDE? CONTACTER SMAIL\n");break;
     case ESC:   exit_prg();
     default:    clrscr(); break;}
}
 
 
void exit_prg()
{
  effacefenetre(1,1,80,25,BLACK,BLACK);
  gotoxy(7,0);
  exit(0);
  }
 
void effacefenetre(int dc,int dl,int fc,int fl,int att_font,int att_text)
{
 
   textbackground(att_font);
   textcolor(att_text);
   clrscr();
 
}
 
void fenetre(int dc,int dl,int fc,int fl,int att_rect,int att_font)
{
 
  textcolor(BLUE);
  textbackground(YELLOW);
  clrscr();
  rectangl(1,1,fc,fl);
 gotoxy(7,0);
 
 
  }
 
void rectangl(int dc, int dl,int longer, int larg)
{
  int i ;
   char c1='Í' ,c2='É',c3='¼',c4='»',c5='È',c6='º';
 
  for(i=0;i<longer-1;i++)
 { gotoxy(dc+i+1,dl);
    cprintf("Í");   }
 
  for(i=0;i<longer-1;i++)
   { gotoxy(dc+i+1,larg+1);
     cprintf("Í");}
 
  for(i=1;i<=larg-1;i++)
  { gotoxy(dc,dl+i);
    cprintf("º");}
 
  for(i=1;i<=larg-1;i++)
  { 
 
  gotoxy(longer,dl+i);
    cprintf("º");}
 
  gotoxy(dc,dl);         cprintf("É");
  gotoxy(longer,dl);     cprintf("»");
  gotoxy(dc,larg+1);     cprintf("È");
  gotoxy(longer,larg+1); cprintf("¼");
   }
 
 
 
 
int lec_fich(FILE *p)  // la fonction de lecture des données de mon file
  {
 
 
       unsigned  int i,j,i1;
       int a;
       int NP,NE,NBE;
       char *chaine,*ch;
       int *E;
 
 
     fscanf(p,"%d",&NP);
     fscanf(p,"%d",&NE);
     fscanf(p,"%d",&NBE);
 
if((p=malloc(NP*(NE+1)*sizeof(chaine)))==NULL)
	{ error_message(62,"Mémoire insuffisante pour cet AdD. ESC"); exit(0);
    }
     if((E=malloc(NP*sizeof(int)))==NULL)
	{ error_message(62,"M‚moire insuffisante pour cet AdD. ESC"); exit(0);}
     for(i=0;i<NP;i++)
	{
 fscanf(p,"%s",(p+0+i*(NE+1))->ch);
 
       a=strlen((p+0+i*(NE+1))->ch);
 
       if(strncmp((p+0+i*(NE+1))->ch,"g+",2)!=0
	    && strncmp((p+0+i*(NE+1))->ch,"g*",2)!=0
	    && strncmp((p+0+i*(NE+1))->ch,"n+",2)!=0
	    && strncmp((p+0+i*(NE+1))->ch,"n*",2)!=0
	    && strncmp((p+0+i*(NE+1))->ch,"gx",2)!=0
	    ) return(0);
	else if(a<3)  return(0);
	      else  {  for(i1=2;i1<a;i1++)
		       if((isdigit((p+0+i*(NE+1))->ch[i1]))==0) return(0);}
 
       a=extrait((p+0+i*(NE+1))->ch); if(a<0||a>NP-1)    return(0);
 
      fscanf(p,"%u",(E+i));
	if(*(E+i)<0 ||*(E+i)> NE) return(0);
      for(j=1;j<=*(E+i);j++)
	{  fscanf(p,"%s",(p+j+i*(NE+1))->ch);
	   a=strlen((p+j+i*(NE+1))->ch);
	  if(strncmp((p+j+i*(NE+1))->ch,"g+",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"g*",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"n+",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"n*",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"gx",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"e+",2)!=0
	      && strncmp((p+j+i*(NE+1))->ch,"e-",2)!=0
	      ) return(0);
	  else if(a<3)  return(0);
		else {  for(i1=2;i1<a;i1++)
			if((isdigit((p+j+i*(NE+1))->ch[i1]))==0) return(0);}
 
	  a=extrait((p+j+i*(NE+1))->ch);
 
	  if(strncmp((p+j+i*(NE+1))->ch,"g+",2)==0
		|| strncmp((p+j+i*(NE+1))->ch,"g*",2)==0
		|| strncmp((p+j+i*(NE+1))->ch,"n*",2)==0
		|| strncmp((p+j+i*(NE+1))->ch,"n+",2)==0
		|| strncmp((p+j+i*(NE+1))->ch,"gx",2)==0)
		       { if(a<0||a>NP-1)    return(0); }
	    else if(strncmp((p+j+i*(NE+1))->ch,"e+",2)==0
		      || strncmp((p+j+i*(NE+1))->ch,"e-",2)==0 )
		    { if(a<0||a>NBE)    return(0); }}
	 }
    fclose(p);
    return(1);
   }
void error_message(int fc,const char *ch)
{
    int dc=20,dl=10,fl=12;
    int cle=0,tch;
    fenetre(dc,dl,fc,fl,ATT_TEXT_MESS,ATT_FONT_MESS);
 
    gotoxy(2,1);
    cprintf("%s",ch);
     do{
       tch=bioskey(0);
       switch(tch){
       case ESC
       :    clrscr(); cle=1; break;
       defaulte:    cle=0;break;
       }} while(cle==0);
     effacefenetre(dc,dl,fc,fl,ATT_FONT_G,ATT_TEXT_G);
}
 
 
 
 
int extrait(char *ptr)
  {
    int n1;
    n1=atoi(ptr+2);
    return(n1);
   }
 void gprintf(int *p,int lig ,int col)
   {
     int i,j;
     printf("\n");//vide;
     for(i=0;i<lig;i++)
       { for(j=0;j<col;j++)
	 printf("% d",*(p+j+i*col));
	    printf("\n");}
    }
 
 
 
 
 char *acq_nfich(const char *ch,const char *mode)
   {
      char *nfich;
       FILE *fp;
       int NBE,NE,NP,dc1=15,dl1=10,fc1=65,fl1=12;
 
    do{
       fenetre(dc1,dl1,fc1,fl1,BLUE,WHITE);
       gotoxy(dc1+2,dl1+1);
       cprintf("%s",ch);
      // nfich=ascanf(MAXPATH,dc1+strlen(ch)-12,dl1+1,fc1-2,fl1-1);
     //  construction_n_fich(nfich,".arb",0);
       if((fp=fopen(nfich,mode))==NULL)
        { 
        free(nfich);
         message("Erreur d'ouverture !");}
       }while(fp==NULL);
       effacefenetre(dc1,dl1,fc1,fl1,BLUE,WHITE);
   if(!(lec_fich(fp))||NP==0||NBE==0||NE==0)
      { 
      error_message(50,"Erreur de format. ESC"); exit(0);}
     return(nfich);
    }

la fonction de lecture de mon file ça marche pas

* tout les variable sont connue , elles nous donnent des information sur notre file or notre arbre car mon fichier contient un arbre dont a un structure bien defini
NP nmbre de porte logique
NE nmbre événement
NBE nmbre maximal des entree d'une porte
nfich==nom de mon arbre ou fichier dont je traite
les g signifient gate or porte qui sont dans mon file
les e sont les entrees des portes qui sont dans file

or mon file structuré sous forme des ligne chaque ligne presente une porte suivi des ces entrées ..

*j'arrive pas à fonctionner la ta traduction de la touche appuyer pour que mon prog exécute exemple quand je clic sur ESC mon programme doit sortir ou F1 pour demander d'aide ...etc