Bonjour, je programme sur codeblocks et je suis sur un problème qui n'est pas dans la compilation mais dans l’exécution (le programme a cessé de fonctionner). Je précise qu'il s'agit d'un pendu et que j'ai créer un Dico.txt avec un * après chaque mots pour pouvoir les compter. ça bug à "lettre = fgetc(fichier);"
Voici mon code :
- include <stdio.h>
- include <stdlib.h>
- include <time.h>
- include <windows.h>
- include <unistd.h>
int main()
{
int jouer = 1;
while (jouer == 1)
{
int nmot = 0, MIN = 0,MAX = 0, nombremots = 0, place = 0, essai = 0, fin = 0, type = 0, perdu = 0;
char mot[30];
char proposition[30];
char cache[30];
int lettre = 0;
FILE* fichier = NULL;
srand(time(NULL));
system("cls");
printf("Bonjour et bienvenue dans le jeu de pendu !\n");
printf("Rapppel : Le jeu ne gere pas les accents\n");
system("pause");
system("cls");
fichier = fopen("Dico.txt", "r");
rewind(fichier);
fseek(fichier,1,SEEK_SET);
if (fichier = NULL)
{
system("cls");
printf("Erreur de fichier");
system("pause");
}
while (lettre != EOF)
{
lettre = fgetc(fichier);
printf("%c", lettre);
if (lettre == '*')
{
nombremots++;
}
fseek(fichier,1,SEEK_CUR);
}
lettre = NULL;
MAX = nombremots;
nombremots = 0;
rewind (fichier);
nmot = rand() % (MAX - MIN + 1) + MIN;
while (nombremots != nmot-1)
{
lettre = fgetc(fichier);
if (lettre == '*')
{
nombremots++;
}
fseek(fichier,1,SEEK_CUR);
}
fseek(fichier,1,SEEK_CUR);
while (lettre != '*')
{
lettre = fgetc(fichier);
mot[place] = lettre;
place++;
}
lettre = NULL;
type = 0;
while (lettre != '\n')
{
lettre = mot[type];
cache[type] = mot[type];
type++;
}
lettre = NULL;
while (fin != 1)
{
system("cls");
printf("\n Mot : %s\n\n Proposttion : ", &cache);
scanf("%s", &proposition);
while (lettre != '\0')
{
lettre = proposition[type];
type++;
}
lettre = NULL;
if (type == 1)
{
type = 0;
while (lettre != '\0')
{
lettre = mot[type];
type++;
if (lettre == proposition[0])
{
cache[type] = lettre;
}
}
}
else if (type > 1)
{
if (proposition == mot)
{
type = 0;
lettre = NULL;
while (lettre != '\0')
{
cache[type] = mot[type];
type++;
}
}
}
if (cache == mot)
{
system("cls");
printf("Vous avez trouver le mot : %s", &cache);
fin = 1;
}
}
}
}