- include <stdio.h>
- include <stdlib.h>
- include <string.h>
- include <time.h>
- define TAILLE_MAX 100
int lectureMot(char *pcMot) {
FILE *fListeMots = NULL;
int i, iNombreMots=0, iMotVoulu=0;
char cLettreActuel=0;
fListeMots = fopen("list.word", "r");
if( fListeMots != NULL ) {
do {
cLettreActuel = fgetc(fListeMots);
if( cLettreActuel == ´\n´ ) ++iNombreMots;
} while( cLettreActuel != EOF);
printf("%d\n", rand());
do {
iMotVoulu = (rand()*time(NULL))%iNombreMots;
} while( iMotVoulu <= 0 );
printf("%d\n", iMotVoulu);
rewind(fListeMots);
while(iMotVoulu > 1) {
cLettreActuel = fgetc(fListeMots);
if( cLettreActuel == ´\n´ || cLettreActuel == EOF ) --iMotVoulu;
}
fgets(pcMot, TAILLE_MAX, fListeMots);
pcMot[strlen(pcMot)-1] = ´\0´;
}
return 0;
}
int main() {
char mot[TAILLE_MAX];
char *trouve=NULL;
char proposition=´\n´;
int i = 0;
srand( time(NULL) );
lectureMot(mot);
/*printf("Mot : ");
scanf("%s", &mot);*/
int iTailleMot = (strlen(mot)+1)*sizeof(char);
trouve = malloc(iTailleMot);
for(i=0; i<iTailleMot; ++i) trouve[i] = 0;
if(iTailleMot > 4) trouve[0]=mot[0];
trouve[iTailleMot] = ´\0´;
do {
printf("\nMot mystere : ");
for(i=0; mot[i] != ´\0´ && i<=TAILLE_MAX; ++i) {
if( mot[i] == proposition ) trouve[i] = mot[i];
if( trouve[i] != 0 ) printf("%c", trouve[i]);
else printf("_");
}
while(proposition != ´\n´) scanf("%c", &proposition);
printf("\nProposez une lettre : ");
scanf(" %c", &proposition);
printf("\n");
} while( strcmp(mot, trouve) != 0);
free(trouve);
return 0;
}
je me suis éclaté à faire un pendu tout à l´heure en cours 