Je rencontre nue erreur lors de l'appel de la fonction piocherMot, qui se trouve dans le main.c
à la ligne , le programme bloque quand j'appel cette fonction, hors elle correctement écrite.
Franchement, je n'arrive pas moi même, à ,trouver d'erreur dans ce code.
le main.c:
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include"dico.h"intrechercherLettre(char carcactereARchercher,char motMystere[],int lettreTrouvee[]);intgagne(int lettreTrouvee[],int tailleMot);charlireCaractere();intmain(){int i=0;char reponse[100]="";int nombreDeVie;int tailleMot=0;char caractereARechercher=0;char motMystere[100]={0};int* lettreTrouvee=NULL;do{
nombreDeVie =10;printf("bienvenue");piocherMot(motMystere);
tailleMot=strlen(motMystere);
lettreTrouvee=malloc(tailleMot *sizeof(int));if(lettreTrouvee == NULL){exit(0);}for(i =0; i < tailleMot ; i++){
lettreTrouvee[i]=0;}do{printf("Il vous reste %d vies", nombreDeVie);printf("Proposez une lettre");for(i =0; i < tailleMot ; i++){if(lettreTrouvee[i])printf("%c", motMystere[i]);elseprintf("*");}
caractereARechercher=lireCaractere();if(!rechercherLettre(caractereARechercher, motMystere, lettreTrouvee)){
nombreDeVie--;}}while(nombreDeVie !=0&&!gagne(lettreTrouvee, tailleMot));if(gagne(lettreTrouvee, tailleMot)){printf("\n\nGagne ! Le mot secret etait bien : %s, souhaitez vous rejouez?", motMystere);scanf("%s", reponse);}else{printf("\n\nPerdu ! Le mot secret etait : %s, souhaitez vous rejouez?", motMystere);scanf("%s", reponse);}free(lettreTrouvee);}while(strcmp(reponse,"oui")==0);return0;}charlireCaractere(){char caractere =0;
caractere =getchar();
caractere =toupper(caractere);while(getchar()!='\n');return caractere;}intrechercherLettre(char carcactereARchercher,char motMystere[],int lettreTrouvee[]){int bonneLettre=0;int i=0;for(i=0; motMystere[i]!='\0';i++){if(carcactereARchercher==motMystere[i]){
lettreTrouvee[i]=1;
bonneLettre=1;}}return bonneLettre;}intgagne(int lettreTrouvee[],int tailleMot){int i =0;int joueurGagne =1;for(i =0; i <6; i++){if(lettreTrouvee[i]==0)
joueurGagne =0;}return joueurGagne;}
dico.c:
#include<stdio.h>#include<stdlib.h>#include<string.h>#include<ctype.h>#include"dico.h"intpiocherMot(char*motPioche){
FILE* dico = NULL;int nombreMots =0, numMotChoisi =0, i =0;int caractereLu =0;
dico =fopen("C:\\Users\\Mehdi\\Documents\\monprojet2\\dico.txt","r");if(dico==NULL){printf("Le dictionnaire de mot n'a pas pu etre ouvert");}do{
caractereLu=fgetc(dico);if(caractereLu='\n'){
nombreMots++;}}while(dico != EOF);
numMotChoisi=nombreAleatoire(nombreMots);rewind(dico);while(numMotChoisi>0){
caractereLu=fgetc(dico);if(caractereLu='\n'){
numMotChoisi--;}}fgets(motPioche,100, dico);
motPioche[strlen(motPioche)-1]='\0';fclose(dico);return1;}intnombreAleatoire(int nombreMax){srand(time(NULL));return(rand()% nombreMax);}