Erreur de compilation

Fermé
faab - 20 avril 2011 à 19:44
Dynamix Messages postés 202 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 30 avril 2011 - 20 avril 2011 à 19:48
Bonjour,
J'ai créer le programme suivant et il m'affiche "root_chr error", mais je ne comprends pas pourquoi ! En effet, n'affichant pas "fopen error", j'en conclus que mon pregramme a ouvert le fichier dico. Apparemment, la variable word ne veut pas s'initialiser à 0 ! Je vous remercie d'avance pour vos réponses. PS: Je précise que j'ai segmenté mon programme en deux fichiers .h et un .c
/*main.c*/
#include "progr.h"
int main(int argc, char *argv[]){
progr_pendu();
return 0;
}
/*progr.h*/
#include "root.h"
int progr_win(int find[], long size){
int win=1;
long i;
for(i=0; i<size; i++){
if(find[i]==0){
win=0;
}}
return win;
}
int progr_chf(char lettr, char word[], int find[]){
int object=0;
long i;
for(i=0; word[i]!='\0'; i++){
if(lettr==word[i]){
object=1;
find[i]=1;
}}
return object;
}
void progr_pendu(){
char lettr=0, word[30]={0};
int *find=NULL;
long size=0, life=10;
if(!root_chr(word)){
printf("root_chr error ");
exit(0);
}
size=strlen(word);
find=(int*)malloc(size * sizeof(int));
if(find=NULL){
printf("malloc error ");
exit(0);
}
printf("BIENVENUE AU JEU DU PENDU\n ");
/*for(i=0; i<size; i++){
find[i]=0;
}*/
while(life>0 && !progr_win(find, size)){
long i=0;
printf("\n\nIl vous reste %ld coup restant\n",life);
for(i=0; i<size; i++){
if(find[i]){
printf("%c",word[i]);
}else{
printf("*");
}}
printf("\nProposez une lettre ");
lettr=root_rdc();
if(!progr_chf(lettr, word, find)){
life--;
}}
if(progr_win(find, size)){
printf("\n\nGagne ! Le mot secret etait bien : %s", word);
}else{
printf("\n\nPerdu ! Le mot secret etait : %s", word);
}
free(find);
return 0;
}
/*root.h*/
#ifndef ROOT
#define ROOT
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <stdio.h>
char root_rdc(){
char car=0;
car=getchar();
while(getchar()!='\n');
return car;
}
int root_nbr(int min, int max){
int num;
srand(time(NULL));
num=(rand()%(max-min+1))+min;
return num;
}
char root_chr(char *mot){
FILE *dico=NULL;
int word=0, num=0;
char read=NULL;
dico=fopen("/home/home/Projects/azote/azote/dico","r");
if(dico==NULL){
printf("fopen error ");
return 0;
}
do{
read=fgetc(dico);
if(read=='\n'){
word++;
}
}while(read!=EOF);
num=root_nbr(1, word++);
rewind(dico);
while(num>0){
read=fgetc(dico);
if(read=='\n'){
num--;
}}
fgets(mot, 30, dico);
mot[strlen(mot)-1]='\0';
fclose(dico);
return 0;
}
#endif

1 réponse

Dynamix Messages postés 202 Date d'inscription dimanche 22 mars 2009 Statut Membre Dernière intervention 30 avril 2011 76
20 avril 2011 à 19:48
Tu as des balises <code> à ta disposition pour que le code soit plus lisible.
1