/*Jeu du Pendu réalisé par EdurionVersion numéro: 1.0Gestion du dictionnaire incluseCopyright 2008Toutes modification sans l'accord du dévellopeur est à proscrire*/#include <stdlib.h>#include <stdio.h>#include <time.h>#include <string.h>#include <ctype.h>#include <errno.h>int PiocherMot(char *motPioche,FILE* dico);int nombreAleatoire(int nombreMot);char LireCaractere();int RechercheLettre(char lettreEntree, char motSecret[], int lettreTrouvee[]);void perror (const char *s);int main(int argc, char argv[]){ int choix, choix2, boucle, coupsRestant=11, i, arrete=0, gagne=0; char lettreEntree, motPioche; FILE* dico = NULL; dico = fopen("dico.txt", "r"); char motSecret[100]={0}; char* s=NULL; int lettreTrouvee[100]={0}; int nombreLettre=0; do { printf("\n -=-=-=-=-=-Bienvenue sur le Pendu!-=-=-=-=-=-\n"); printf("\n\n -=} 1 - Demarrer le jeu (1J){=-"); printf("\n -=} 2 - Demarrer le jeu (2J & +) {=-"); printf("\n -=} 3 - Rajouter un mot dans le dictionnaire {=-"); printf("\n -=} 4 - Quitter {=-\n"); scanf("%ld", &choix); switch (choix) { case 1: perror(s); if(PiocherMot(motSecret, dico)==0) { boucle=0; perror(s); } else { printf(" --=Vous avez choisi le mode 1 joueur=--!\n\n"); nombreLettre = strlen(motSecret); printf("Le mot a trouver est un mot de %ld lettres!\n", nombreLettre); coupsRestant=11; arrete=0; int lettreTrouvee[100]={0}; gagne=0; do { if(gagne==1) { printf("Bravo! Vous avez gagne!\n"); printf("Le mot a trouver etait bien %s !\n\n", motSecret); fclose(dico); arrete=1; } else if(coupsRestant==0) { //Code de la défaite printf("Desole, vous avez perdu!\n"); fclose(dico); arrete=1; } else { for(i=0; motSecret[i] != '\0'; i++) { if(lettreTrouvee[i]) { printf("%c", motSecret[i]); } else { printf("*"); } } printf("\nIl vous reste %ld coups a jouer!\nProposez une lettre...", coupsRestant); lettreEntree = LireCaractere(); if(!RechercheLettre(lettreEntree, motSecret, lettreTrouvee)) { coupsRestant--; } printf("\n\n\n\n"); for(i=0; motSecret[i] != '\0'; i++) { gagne=0; if(lettreTrouvee[i] == 1) { gagne++; } else { gagne--; } } if(gagne==nombreLettre) { gagne=1; } else { gagne=0; } } }while(arrete==0); fclose(dico); printf("Voulez-vous refaire une partie?\n"); printf("1 - Oui\n2 - Non\n"); scanf("%ld", &boucle); } break; case 2: //Code 2 joueur printf("pas encore"); boucle=1; break; case 3: //Mode d'ajout printf("pâtience"); boucle=1; break; case 4: printf("\n\n\n\t\a Voulez-vous vraiment quitter?\n\n"); printf("1 - Oui\n2 - Non\n"); scanf("%ld", &choix2); if(choix2==1) { boucle=0; } else { boucle = 1; } break; } }while(boucle==1);return 0;}int RechercheLettre(char lettreEntree, char motSecret[], int lettreTrouvee[]){ int i=0; int bonneLettre = 0; for(i=0; motSecret[i] != '\0'; i++) { if(lettreEntree == motSecret[i]) { bonneLettre = 1; lettreTrouvee[i]=1; } } return bonneLettre;}char LireCaractere(){ char caractere = 0; caractere = getchar(); // On lit le premier caractère caractere = toupper(caractere); // On met la lettre en majuscule si elle ne l'est pas déjà // On lit les autres caractères mémorisés un à un jusqu'à l'\n (pour les effacer) while (getchar() != '\n') ; return caractere; // On retourne le premier caractère qu'on a lu}int nombreAleatoire(int nombreMot){ srand(time(NULL)); return (rand() % nombreMot);}int PiocherMot(char motSecret[],FILE* dico){ int caractereLu=0, nombreMot=0, numeroMotChoisi=0; if(dico==NULL) { printf("Le fichier du dictionnaire n'a pas pu etre charge..."); return 0; } do { caractereLu=fgetc(dico); if(caractereLu == '\n') { nombreMot++; } }while(caractereLu != EOF); numeroMotChoisi = nombreAleatoire(nombreMot); rewind(dico); while(numeroMotChoisi > 0) { caractereLu = fgetc(dico); if(caractereLu == '\n') { numeroMotChoisi--; } } fgets(motSecret, 100, dico); motSecret[strlen(motSecret) - 1] = '\0'; return 1;}
test.c:23: warning: second argument of 'main' should be 'char **'test.c: In function 'main':test.c:41: warning: format '%ld' expects type 'long int *', but argument 2 has type 'int *'test.c:58: warning: format '%ld' expects type 'long int', but argument 2 has type 'int'test.c:94: warning: format '%ld' expects type 'long int', but argument 2 has type 'int'test.c:127: warning: format '%ld' expects type 'long int *', but argument 2 has type 'int *'test.c:143: warning: format '%ld' expects type 'long int *', but argument 2 has type 'int *'test.c:30: warning: unused variable 'lettreTrouvee'test.c:25: warning: unused variable 'motPioche'
// Nom de la fonction//Quels sont les paramètres//Quel est le retour//Quel est le traitement//