- #include<stdlib.h>
- #include<string.h>
- #include<conio.h>
-
- int verification(char pendu[],char test[],char lettre);
- int gagne(char test[],int longueur);
-
- main()
- {
- char mots[5][10]={"papa","velo","maison","ecole","voiture"};
- int mot,verif,i,length;
- int n=0;
- char lettre,bad[26];
- char test[10];
- char pendu[10];
- bad[0]='\0';
-
- printf("Entrez un nb de 0 a 4 \n");
- scanf("%d",&mot);
- fflush(stdin);
- strcpy(pendu,mots[mot]);
- length=strlen(pendu);
-
-
- for(i=0;i<length;i++)
- {
- test[i]='-';
- }
- test[length]='\0';
-
- while(gagne(test,length) == 0)
- {
- printf("%s \n",test);
- printf("Entrez une lettre \n");
- scanf("%c",&lettre);
- fflush(stdin);
- verif = verification(pendu,test,lettre);
-
- if(verif == 0)
- {
- bad[n] = lettre;
- n=n+1;
- bad[n] = '\0';
- }
- printf("Mauvaises lettres entrees : %s \n",bad);
- }
-
- printf("Jeu termine le mot etait %s \n",pendu);
- getch();
- }
-
- int verification(char pendu[],char test[],char lettre)
- {
- int j,check=0;
-
- for(j=0;j<strlen(pendu);j++)
- {
- if(pendu[j] == lettre)
- {
- test[j] = lettre;
- check=1;
- }
- }
- return check;
- }
-
- int gagne(char test[],int longueur)
- {
- int j=0,check=1;
-
- while((check == 1) && (j<longueur))
- {
- if(test[j] == '-') check=0;
- j=j+1;
- }
- return check;
- }
-
-
#include<stdlib.h>
#include<string.h>
#include<conio.h>
int verification(char pendu[],char test[],char lettre);
int gagne(char test[],int longueur);
main()
{
char mots[5][10]={"papa","velo","maison","ecole","voiture"};
int mot,verif,i,length;
int n=0;
char lettre,bad[26];
char test[10];
char pendu[10];
bad[0]='\0';
printf("Entrez un nb de 0 a 4 \n");
scanf("%d",&mot);
fflush(stdin);
strcpy(pendu,mots[mot]);
length=strlen(pendu);
for(i=0;i<length;i++)
{
test[i]='-';
}
test[length]='\0';
while(gagne(test,length) == 0)
{
printf("%s \n",test);
printf("Entrez une lettre \n");
scanf("%c",&lettre);
fflush(stdin);
verif = verification(pendu,test,lettre);
if(verif == 0)
{
bad[n] = lettre;
n=n+1;
bad[n] = '\0';
}
printf("Mauvaises lettres entrees : %s \n",bad);
}
printf("Jeu termine le mot etait %s \n",pendu);
getch();
}
int verification(char pendu[],char test[],char lettre)
{
int j,check=0;
for(j=0;j<strlen(pendu);j++)
{
if(pendu[j] == lettre)
{
test[j] = lettre;
check=1;
}
}
return check;
}
int gagne(char test[],int longueur)
{
int j=0,check=1;
while((check == 1) && (j<longueur))
{
if(test[j] == '-') check=0;
j=j+1;
}
return check;
}