Bonjour!!!
Je suis débutante en C, je suis un cours sur internet... J'ai fait un code qui ne sert pour l'instant qu'a générer un mot aléatoire à partir d'un mini-dictionnaire... Le problème est que le code n'affiche absolument rien, même pas le "Appuyez sur une touche pour continuer..." ... RIEN!!! Et je ne comprend pas pourquoi
main.c
dico.c
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include <stdio.h> #include <stdlib.h> #include <ctype.h> #include <string.h> #include "dico.h" int main(int argc, char *argv[]) { char mot_secret[100] = {0}; if(!choisir_mot(mot_secret)) { printf("ERREUR"); } printf("%s", mot_secret); system("PAUSE"); return 0; }
dico.h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> #include "dico.h" int choisir_mot(char *mot_choisi) { FILE* dico = NULL; long nb_mots = 0, num_mot = 0; int caractere = 0; dico = fopen("dico.txt", "r"); if(dico == NULL) { exit(0); } do { caractere = fgetc(dico); if (caractere == '\n') { nb_mots++; } } while(caractere != EOF); num_mot = nombre_aleatoire(nb_mots); while(num_mot > 0) { rewind(dico); caractere = fgetc(dico); if(caractere == '\n') { num_mot--; } } fgets(mot_choisi, 100, dico); mot_choisi[strlen(mot_choisi) - 1] = '\0'; fclose(dico); return 1; } long nombre_aleatoire(long max) { srand(time(NULL)); return(rand() % max); }
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 #ifndef DEF_DICO #define DEF_DICO int choisir_mot(char *mot_choisi); long nombre_aleatoire(long max); #endif
Partager