Bonjour à tous
,
je construit en C, dans codeBlock, un petit code pour créer un jeu de pendu.
J'ai beau avoir intégré la bibliothèque <string.h> dans mon code, le message d'erreur suivant apparait toujours à la compilation:
||=== Build: Debug in Pendu (compiler: GNU GCC Compiler) ===|
/Users/theophilemegny-marquet/Desktop/Pendu/main.c|41|warning: implicit declaration of function 'strLen' is invalid in C99 [-Wimplicit-function-declaration]|
/Users/theophilemegny-marquet/Desktop/Pendu/main.c|12|warning: unused variable 'userChances' [-Wunused-variable]|
||=== Build failed: 0 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
Quelqu'un a t'il une idée de ce qu'il se passe?
J'ai déjà essayé d'utiliser strlen dans un autre projet et cela fonctionne.
Merci d'avance.
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
| #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include <string.h>
#include"main.hh"
int main()
{
//DEFINITION DES VARIABLES
FILE *file=NULL; //Dictionnaire
int nbrWordDictio=0, userChances=10, i=0,wordNbrChar=0, randWordChoice=0;
char secretWord[1000]="";
//OUVERTURE DU FICHIER DE DICTIONNAIRE
file=fopen("/Users/theophilemegny-marquet/Desktop/Dico.txt","r");
if(file!=NULL)
{
// ACCUEIL
printf("\n-----------BIENVENU DANS LE JEU DU PENDU----------------");
//TEST NOMBRE DE MOTS DICTIONNAIRE
nbrWordDictio=numberWordDictionnary(file);
printf("\nActuellement votre dictionnaire de mots comporte : %d mots",nbrWordDictio);
printf("\n--------------------------------------------------------\n\n");
//CHOIX DU MOT AU HASARD
//Definir un numero au hasard
srand(time(NULL));
randWordChoice = (rand() % (nbrWordDictio)) + 1;
printf("MOT NUMERO %d",randWordChoice);
//Extraire le mot correspondant a ce numero
for(i=0;i<=(randWordChoice-1);i++)
{
fgets(secretWord,1000,file);
}
printf(" \nMot secret: %s",secretWord);
//Compter le nombre de caracteres du mot secret
wordNbrChar=strLen(secretWord); ////////////////// ICI ///////////
//TOURS DE PARTIES
printf("\n");
printf("Il vous reste %d coups a jouer",userChances);
printf("\n");
printf("Quel est le mot secret? ");
for(i=0;i<=wordNbrChar-1;i++)
{
printf("*");
}
printf("\n");
printf("Proposez une lettre: ");
lireCaractere();
//Si le caractere est dans le mots choisi
//FERMETURE DU FICHIER TEXTE
fclose(file);
}
else
{
printf("\nDictionnaire introuvable");
exit(0);
}
return 0;
}
char lireCaractere()
{
char caractere=0;
caractere=getchar(); //Recupeation d'un caractere utilisateur
caractere=toupper(caractere); //Passage en majuscule
while(getchar()!='\n'); //En appelant getChar n boucle jusqu'a retour charriot on efface les autres
return caractere;
}
int numberWordDictionnary(FILE*file)
{
int nbrChar=0;
char targetChar='\n';
while(targetChar!=EOF)
{
targetChar=fgetc(file);
if (targetChar=='\n')
{
nbrChar++;
}
}
rewind(file);
return(nbrChar);
} |
Partager