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
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int recherche_et_modifie_caractere(char *c,char mot[],char mot2[]);
int main ()
{
char lettreentre=0;
int nombre_de_coup=5;
char mot[100]="";
char mot2[100]="";
int i=0;
int j=0;
int h=0;
printf("bienvenue dans le jeu du pendu pourriez vous deviner le mot ??\n\n");
FILE *ptr=NULL;
ptr=fopen("/storage/emulated/0/backups/dico.txt","r");
if(ptr==NULL)
{
printf("impossible d'ouvrir le fichier");
return 0;
}
else
srand(time(NULL));
j=rand()%3+1;
for(h=0; h<j; h++)
{
fgets(mot,100,ptr);
}
strcpy(mot2,mot);
for(i=0; i<strlen(mot)-1; i++)
{
mot[i]='*';
}
while(nombre_de_coup != 0)
{
printf("\nsaisissez votre lettre\n");
printf("%s\n",mot);
scanf("%c",&lettreentre);
while(!(getc(stdin)=='\n'));
recherche_et_modifie_caractere(&lettreentre,mot,mot2);
printf("%s\n",mot);
if(recherche_et_modifie_caractere(&lettreentre,mot,mot2) < 1)
{
nombre_de_coup--;
printf("cette lettre ne se trouve pas dans le mot\n");
printf("il vous reste %d coups\n",nombre_de_coup);
}
else if(strcmp(mot2,mot)==0)
{
printf("\ncongratulation vous avez trouvez le mot mystere\n");
return 0;
}
}
printf("vous avez perdu");
return 0;
}
int recherche_et_modifie_caractere(char *c,char mot[],char mot2[])
{
int j=0;
int i =0;
while(mot2[j] != '\0')
{
if(mot2[j] == *c)
{
mot[j]=*c;
i++;
}
j++;
}
return i;
} |
Partager