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
| #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "header.h"
int main()
{
long coup = NBRE_COUP;
char solution[TAILLE] = "marron";
char* pendu = NULL;
int etoile = strlen(solution)-1;
char lettre = ' ';
pendu = malloc(etoile * sizeof(long));
initPendu(pendu, &etoile);
printf("Bienvenue dand le pendu !\n");
do{
afficheCoupRestant(&coup);
getNewLetter(&lettre, pendu);
//setGoodLetter(solution, pendu , &lettre, &etoile);
}while(coup > 0 || etoile == 0);
if (coup == 0) printf("You're dead !\n\n");
else if (etoile == 0) printf("Bravo vous avez trouve : %s", pendu);
return 0;
}
void initPendu(char* pendu, const int* etoile){
int i = 0;
do {
pendu[i] = '*';
i++;
}while(i <= *etoile);
pendu[i] = '\0';
}
void afficheCoupRestant(long* coup){
long test = *coup;
printf("\n\nIl vous reste %ld coups a jouer.\n", *coup);
(*coup)--;
}
void setGoodLetter(const char* solution, char* pendu, const char* lettre, int* etoile){
int i = 0;
char c = ' ';
do {
c = solution[i];
if (c == *lettre){
pendu[i] = c;
(*etoile)--;
}
i++;
}while(c != '\0');
}
void getNewLetter(char* lettre, const char* pendu){
printf("Quel est le mot secret ? : ");
printf("%s\n", pendu);
printf("Proposez une lettre : ");
scanf("%c", lettre);
} |
Partager