1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <co
1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <conio.h> 5 #include <windows.h> 6 #include <dos.h> 7 8 ///fonction changer position gotoxy 9 void gotoxy(int x,int y) 10 { 11 COORD gogo= {0,0}; 12 gogo.X=x; 13 gogo.Y=y; 14 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE),gogo); 15 } 16 17 ///fonction changer la color 18 void Color(int couleurDuTexte, int couleurDeFond) 19 { 20 SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE),couleurDeFond*16+couleurDuTexte); 21 } 22 typedef struct tra 23 { 24 char traduction[70]; 25 26 } tra; 27 28 typedef struct e_arb 29 { 30 char car; 31 struct e_arb * fils, * frere, * pere; 32 tra * trad; 33 } earb; 34 35 typedef earb * arbre; 36 37 void initialisation(arbre racine) 38 { 39 racine->pere = NULL; 40 racine->frere = NULL; 41 racine->fils = NULL; 42 racine->car = '#'; 43 } 44 arbre racine; 45 46 typedef struct dictionnaire 47 { 48 char nom[50]; 49 int num; 50 arbre dic; 51 struct dictionnaire * suivant; 52 } dictionnaire; 53 54 typedef dictionnaire * diction; 55 56 void ajouter_lettre(arbre r,char * c,char * ttt) 57 { 58 arbre e,p,prec; 59 int pos; 60 61 while(*c != '\0') 62 { 63 64 if(r->fils == NULL) 65 { 66 e = malloc(sizeof(earb)); 67 e->trad = NULL; 68 e->car = *c; 69 e->fils = NULL; 70 e->frere = NULL; 71 e->pere = r; 72 r->fils = e; 73 r = r->fils; 74 75 } 76 else 77 { 78 79 p = r->fils; 80 prec = p; 81 82 pos = 0; 83 while(p != NULL && *c > p->car) 84 { 85 prec = p; 86 p = p->frere; 87 pos++; 88 } 89 90 91 if(p == NULL) ///pas trouver la lettre dans les freres 92 { 93 94 e = malloc(sizeof(earb)); 95 e->trad = NULL; 96 e->car = *c; 97 e->fils = NULL; 98 e->frere = NULL; 99 e->pere = prec->pere; 100 prec->frere = e; 101 r = e; 102 103 } 104 else if(*c < p->car) 105 { 106 107 if(pos == 0) 108 { 109 e = malloc(sizeof(earb)); 110 e->trad = NULL; 111 e->car = *c; 112 e->fils = NULL; 113 e->frere = p; 114 e->pere = r; 115 r->fils = e; 116 r = e; 117 } 118 else 119 { 120 e = malloc(sizeof(earb)); 121 e->trad = NULL; 122 e->car = *c; 123 e->fils = NULL; 124 e->frere = p; 125 e->pere = r; 126 prec->frere = e; 127 r = e; 128 129 } 130 131 } 132 else if(*c == p->car) 133 { 134 135 r = p; 136 if(*(c+1) == '\0') 137 { 138 p->trad = malloc(sizeof(tra)); 139 strcpy(p->trad->traduction,ttt); 140 } 141 142 } 143 144 } 145 146 c++; 147 } 148 149 e->trad = malloc(sizeof(tra)); 150 strcpy(e->trad->traduction,ttt); 151 152 } 153 154 char * concatenation(char carcterre,char * m) 155 { 156 int i; 157 i = strlen(m)+1; 158 while(i>=1) 159 { 160 m[i] = m[i-1]; 161 i--; 162 } 163 if(strlen(m) == 0) 164 { 165 m[1] = '\0'; 166 } 167 168 169 170 171 m[0] = carcterre; 172 return m; 173 } 174 175 176 void afficher_mot_exp(arbre r) 177 { 178 arbre p,d; 179 arbre pile[100]; 180 int sommet; 181 char mot1[50]; 182 183 p = r; 184 sommet = 0; 185 while(p != NULL) 186 { 187 188 if(p->trad != NULL) 189 { 190 191 192 d = p; 193 strcpy(mot1,""); 194 while(d->pere != NULL) 195 { 196 197 strcpy(mot1,concatenation(d->car,mot1)); 198 d = d->pere; 199 } 200 201 printf("\t%s : %s\n",mot1,p->trad->traduction); 202 203 } 204 205 206 if(p->frere != NULL) 207 { 208 209 pile[sommet] = p->frere; 210 sommet++; 211 } 212 213 p = p->fils; 214 215 if(p == NULL && sommet > 0) 216 { 217 sommet--; 218 p = pile[sommet]; 219 220 } 221 222 } 223 224 225 226 } 227 228 void afficher_mot(arbre r) 229 { 230 arbre p,d; 231 arbre pile[100]; 232 int sommet; 233 char mot1[50]; 234 int i; 235 236 p = r; 237 sommet = 0; 238 while(p != NULL) 239 { 240 241 if(p->trad != NULL) 242 { 243 244 245 d = p; 246 strcpy(mot1,""); 247 while(d->pere != NULL) 248 { 249 250 strcpy(mot1,concatenation(d->car,mot1)); 251 d = d->pere; 252 } 253 254 255 printf("\t%s\n",mot1); 256 257 } 258 259 260 if(p->frere != NULL) 261 { 262 263 pile[sommet] = p->frere; 264 sommet++; 265 } 266 267 p = p->fils; 268 269 if(p == NULL && sommet > 0) 270 { 271 sommet--; 272 p = pile[sommet]; 273 274 } 275 276 } 277 278 279 280 } 281 282 283 void recherche(arbre r,char * mot) 284 { 285 arbre p; 286 char chaine[50]; 287 int valide; 288 289 strcpy(chaine,mot); 290 if(r == NULL) 291 { 292 gotoxy(5,5); 293 printf("dictionnaire est vide"); 294 } 295 else 296 { 297 valide = 1; 298 while(*mot != '\0' && valide == 1) 299 { 300 301 302 p = r->fils; 303 304 while(p != NULL && *mot > p->car) 305 { 306 p = p->frere; 307 } 308 309 if(p == NULL) 310 { 311 312 valide = 0; 313 314 } 315 else if(*mot < p->car) 316 { 317 318 valide = 0; 319 320 } 321 else if(*mot == p->car) 322 { 323 324 r = p; 325 326 } 327 328 mot++; 329 330 } 331 332 333 if(valide == 1 && *mot == '\0' && p->trad != NULL) 334 { 335 336 gotoxy(5,7); 337 printf("%s : %s",chaine,p->trad->traduction); 338 } 339 else 340 { 341 gotoxy(5,7); 342 printf("mot exist pas"); 343 344 } 345 346 347 } 348 349 350 } 351 352 353 void sauvgarder(arbre r,char * nomf) 354 { 355 FILE * f; 356 arbre p,d; 357 arbre pile[100]; 358 int sommet; 359 char mot1[50]; 360 char nomfichier[50]; 361 362 strcpy(nomfichier,nomf); 363 364 365 strcat(nomfichier,".txt"); 366 367 f = fopen(nomfichier,"wt"); 368 if(f == NULL) 369 { 370 printf("ERREUR!!"); 371 getch(); 372 } 373 else 374 { 375 376 p = r; 377 sommet = 0; 378 while(p != NULL) 379 { 380 381 if(p->trad != NULL) 382 { 383 384 d = p; 385 strcpy(mot1,""); 386 while(d->pere != NULL) 387 { 388 389 strcpy(mot1,concatenation(d->car,mot1)); 390 d = d->pere; 391 } 392 393 fputs(mot1,f); 394 fputs("\n",f); 395 fputs(p->trad->traduction,f); 396 fputs("\n",f); 397 398 } 399 400 401 if(p->frere != NULL) 402 { 403 404 pile[sommet] = p->frere; 405 sommet++; 406 } 407 408 p = p->fils; 409 410 if(p == NULL && sommet > 0) 411 { 412 sommet--; 413 p = pile[sommet]; 414 415 } 416 417 } 418 printf("sauvgarder avec succes"); 419 getch(); 420 fclose(f); 421 422 } 423 424 } 425 426 427 428 void charger(arbre r,char * nomf) 429 { 430 FILE * f; 431 char nomfichier[50]; 432 char chaine[100]; 433 char expli[100]; 434 435 strcpy(nomfichier,nomf); 436 437 strcat(nomfichier,".txt"); 438 439 f = fopen(nomfichier,"rt"); 440 if(f == NULL) 441 { 442 printf("Erreur: pas de dictionnaire sauvgarder!!"); 443 getch(); 444 } 445 else 446 { 447 while(fscanf(f, "%s", &chaine) != EOF) 448 { 449 fscanf(f, "%s", &expli); 450 ajouter_lettre(r,chaine,expli); 451 } 452 453 printf("sauvgarder avec succes"); 454 getch(); 455 } 456 } 457 458 459 void modifier(arbre r,char * mot) 460 { 461 arbre p; 462 char chaine[50]; 463 int valide; 464 465 strcpy(chaine,mot); 466 if(r == NULL) 467 { 468 469 gotoxy(5,5); 470 printf("dictionnaire est vide"); 471 } 472 else 473 { 474 valide = 1; 475 while(*mot != '\0' && valide == 1) 476 { 477 478 479 p = r->fils; 480 481 while(p != NULL && *mot > p->car) 482 { 483 p = p->frere; 484 } 485 486 if(p == NULL) 487 { 488 489 valide = 0; 490 491 } 492 else if(*mot < p->car) 493 { 494 495 valide = 0; 496 497 } 498 else if(*mot == p->car) 499 { 500 501 r = p; 502 503 } 504 505 mot++; 506 507 } 508 509 510 if(valide == 1 && *mot == '\0' && p->trad != NULL) 511 { 512 513 514 gotoxy(5,7); 515 printf("Entrer la nouvelle traduction:"); 516 scanf("%s",p->trad->traduction); 517 } 518 else 519 { 520 gotoxy(5,7); 521 printf("cette mot exist pas"); 522 523 } 524 } 525 } 526 527 528 void supprimer(arbre r,char * mot,dictionnaire * dik) 529 { 530 arbre p,d,prec=NULL; 531 char chaine[50]; 532 int valide; 533 534 strcpy(chaine,mot); 535 536 if(r == NULL) 537 { 538 gotoxy(5,7); 539 printf("dictionnaire est vide"); 540 } 541 else 542 { 543 valide = 1; 544 while(*mot != '\0' && valide == 1) 545 { 546 p = r->fils; 547 548 while(p != NULL && *mot > p->car) 549 { 550 prec = p; 551 p = p->frere; 552 } 553 554 if(p == NULL) 555 { 556 557 valide = 0; 558 559 } 560 else if(*mot < p->car) 561 { 562 563 valide = 0; 564 565 } 566 else if(*mot == p->car) 567 { 568 r = p; 569 } 570 571 mot++; 572 573 } 574 575 576 if(valide == 1 uploads/s3/ main-2.pdf
-
21
-
0
-
0
Licence et utilisation
Gratuit pour un usage personnel Attribution requise- Détails
- Publié le Dec 24, 2022
- Catégorie Creative Arts / Ar...
- Langue French
- Taille du fichier 0.5182MB