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
|
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>
#define NB_D_ELEMENTS 5
#define NB_DE_POSSIBILITE pow(26,NB_D_ELEMENTS)*2
#define NB_DE_MOTS_PAR_LIGNE 15
#define NB_DE_MOTS_PAR_FICHIER 1000000
#define NB_D_ELEMENTS_ALPHABET 26
int main(int argc, char* argv[])
{
int i;
int j=NB_DE_POSSIBILITE;
int compteur=0;
FILE* dico=NULL;
char nomFichier[11]="dico.txt";
srand (time(NULL));
char mot[NB_D_ELEMENTS]="\0";
char alphabet[27]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
int numeroFichier=0;
do{
for (i=0;i<NB_D_ELEMENTS;i++)
{
int nbAleatoire = (rand() % NB_D_ELEMENTS_ALPHABET);
mot [i]= alphabet[nbAleatoire];
}
compteur++;
mot[NB_D_ELEMENTS]='\0';
if(!(compteur%NB_DE_MOTS_PAR_FICHIER)||compteur==1)
{
numeroFichier++;
sprintf(nomFichier, "dico%d.txt", numeroFichier);
dico=fopen(nomFichier,"a+");
}
fputs(mot, dico);
fputs(" ", dico);
if (!(compteur%NB_DE_MOTS_PAR_LIGNE))
fputc('\n',dico);
}while (j--);
fclose(dico);
} |
Partager