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
   |  
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
int compare (void const *a, void const *b)
{
 
   char *const *pa = a;
   char *const *pb = b;
 
   return strcmp (*pa, *pb);
}
 
int Nb_mot()
{
    char c[15];
    FILE *file;
    int compteur=0;
 
    file=fopen("dictionnaire","r");
    while (!feof(file))
    {
          fgets(c, 17, file);
          compteur++;
    }
    fclose(file);
    printf("%d",compteur);
    return compteur;
}
 
int main (void)
{
 
   int nbmot,i;
   nbmot=Nb_mot();
   FILE *file;
   printf("il y a %d mots dans le dictionnaire ",nbmot);
   char **c=malloc(nbmot*sizeof(char));
   for (i=0;i<nbmot;i++)
   {
       c[i]=malloc (15*sizeof(char));
   }
   char const *tab[] = { "world", "hellos", "hello" };
   char chaine[15];
   file=fopen("dictionnaire","r");
 
   for (i=0;i<nbmot;i++)
   {
                    fgets(chaine, 17, file);
                    strcpy(c[i],chaine);
                    printf("%s",c[i]);
 
   }
   //qsort (c, sizeof c / sizeof *c, sizeof *c, compare);
   printf("%s",c[1]);
   getchar();
 
 
} | 
Partager