Advertisement
Vincent38190

dico.c

Jan 20th, 2016
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.82 KB | None | 0 0
  1. #ifndef DEF_FONCTION
  2. #define DEF_FONCTION
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <time.h>
  7. #include <ctype.h>
  8. #include "fonction.h"
  9. #include "dico.h"
  10. #endif // DEF_FONCTION
  11. #define TAILLE_MAX 10000
  12.  
  13. void Dictionnaire(char sortit[])
  14. {
  15.     FILE* dico = NULL;
  16.     dico = fopen("dico.txt","r");
  17.     int nombreDeMot = NombreDeMot(dico);
  18.     //printf("\nNombre de mot %d", nombreDeMot);
  19.     int motMystere = (rand() % (nombreDeMot - 1)) + 1;
  20.     //printf("\n Mot mystere : %d", motMystere);
  21.     rewind(dico);
  22.     int pos = 0, i = -2;
  23.     char caractereActuel = 0;
  24.     do
  25.         {
  26.  
  27.             caractereActuel = fgetc(dico); // On lit le caractère
  28.             if(caractereActuel == '\n')
  29.                pos ++;
  30.               // printf("\n pos n=%d & caractere actuel = %c",pos,caractereActuel);
  31.             if(pos == motMystere)
  32.             {
  33.                         // printf("\n i=%d & caractere actuel = %c",i,caractereActuel);
  34.                         if(caractereActuel != ' ')
  35.                         {
  36.                         i++;
  37.                         sortit[i] = caractereActuel;
  38.                         }
  39.  
  40.             }
  41.         } while (caractereActuel != EOF); // On continue tant que fgetc n'a pas retourné EOF (fin de fichier)
  42.     fclose(dico);
  43.  
  44. }
  45.  
  46.  
  47. int NombreDeMot(FILE* fichier)
  48. {
  49.  
  50.     int nombreDeMot = 0, caractereActuel = 0;
  51.     rewind(fichier);
  52.     if (fichier != NULL)
  53.     {
  54.         do
  55.         {
  56.             caractereActuel = fgetc(fichier); // On lit le caractère
  57.             if(caractereActuel == '\n')
  58.                 nombreDeMot ++;
  59.         } while (caractereActuel != EOF); // On continue tant que fgetc n'a pas retourné EOF (fin de fichier)
  60.     }
  61.     else
  62.     {
  63.         printf("Erreur ouverture du dictionnaire");
  64.     }
  65.  
  66.     return nombreDeMot;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement