|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
#include "tp8f.h"
|
|
|
|
|
#include "tp8.h"
|
|
|
|
|
|
|
|
|
|
int moyenne(void)
|
|
|
|
|
{
|
|
|
|
@ -99,7 +99,7 @@ void jeuPendu(void)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void charger(char *tab[2])
|
|
|
|
|
int charger(char tab[][27])
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
char mot[27];
|
|
|
|
@ -109,21 +109,24 @@ void charger(char *tab[2])
|
|
|
|
|
if (flot == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Problème lors de l'ouverture du fichier.\n");
|
|
|
|
|
return;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fscanf(flot, "%s", mot);
|
|
|
|
|
fscanf(flot, "%s%*c", mot);
|
|
|
|
|
while(!feof(flot))
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < strlen(mot); ++j)
|
|
|
|
|
tab[j][i] = mot[j];
|
|
|
|
|
strcpy(tab[i], mot);
|
|
|
|
|
i = i+1;
|
|
|
|
|
fscanf(flot, "%s%*c", mot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(flot);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void afficher(char *tab[2])
|
|
|
|
|
/*void afficher(char tab[][27], int nb)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < 15; ++i)
|
|
|
|
|
for (int i = 0; i < nb; ++i)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < 27; ++j)
|
|
|
|
|
{
|
|
|
|
@ -131,4 +134,133 @@ void afficher(char *tab[2])
|
|
|
|
|
}
|
|
|
|
|
printf("\n");
|
|
|
|
|
}
|
|
|
|
|
}*/
|
|
|
|
|
void afficher(char tab[][27], int nb)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < nb; ++i)
|
|
|
|
|
printf("%s\n", tab[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void insert(char tab[][27], int *nb, char mot[])
|
|
|
|
|
{
|
|
|
|
|
int x = *nb;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < *nb; ++i)
|
|
|
|
|
{
|
|
|
|
|
if(strcmp(mot, tab[i]) == 0)
|
|
|
|
|
{
|
|
|
|
|
printf("mot déjà dans existant\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(strcmp(tab[i], mot) > 0)
|
|
|
|
|
{
|
|
|
|
|
x = i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = *nb; i >= x; i=i-1)
|
|
|
|
|
strcpy(tab[i+1], tab[i]);
|
|
|
|
|
|
|
|
|
|
strcpy(tab[x], mot);
|
|
|
|
|
*nb = *nb +1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sauvegarder(char tab[][27], int nb)
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
|
|
FILE *flot;
|
|
|
|
|
flot = fopen("fichierMots.txt", "w");
|
|
|
|
|
if (flot == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Problème lors de l'ouverture du fichier.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nb; ++i)
|
|
|
|
|
fprintf(flot, "%s\n", tab[i]);
|
|
|
|
|
|
|
|
|
|
fclose(flot);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int chargerLong(char tab[][27])
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
char mot[27];
|
|
|
|
|
|
|
|
|
|
FILE *flot;
|
|
|
|
|
flot = fopen("fichierMotsLong.txt", "r");
|
|
|
|
|
if (flot == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Problème lors de l'ouverture du fichier.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fgets(mot, 27, flot);
|
|
|
|
|
mot[strlen(mot) - 1] = '\0';
|
|
|
|
|
while(!feof(flot))
|
|
|
|
|
{
|
|
|
|
|
strcpy(tab[i], mot);
|
|
|
|
|
i = i+1;
|
|
|
|
|
fgets(mot, 27, flot);
|
|
|
|
|
mot[strlen(mot) - 1] = '\0';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fclose(flot);
|
|
|
|
|
return i;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int sauvegarderLong(char tab[][27], int nb)
|
|
|
|
|
{
|
|
|
|
|
int i=0;
|
|
|
|
|
|
|
|
|
|
FILE *flot;
|
|
|
|
|
flot = fopen("fichierMotsLong.txt", "w");
|
|
|
|
|
if (flot == NULL)
|
|
|
|
|
{
|
|
|
|
|
printf("Problème lors de l'ouverture du fichier.\n");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nb; ++i)
|
|
|
|
|
fprintf(flot, "%s\n", tab[i]);
|
|
|
|
|
|
|
|
|
|
fclose(flot);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void chercher(char tab[][27], int nb, char mot[])
|
|
|
|
|
{
|
|
|
|
|
int pass;
|
|
|
|
|
char res[27];
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < nb; ++i)
|
|
|
|
|
{
|
|
|
|
|
int num[27] = {0};
|
|
|
|
|
|
|
|
|
|
for (int j = 0; j < strlen(tab[i]); ++j)
|
|
|
|
|
{
|
|
|
|
|
pass = 0;
|
|
|
|
|
|
|
|
|
|
for (int k = 0; k < strlen(mot); ++i)
|
|
|
|
|
{
|
|
|
|
|
if (tab[i][j] == mot[k] && num[k] == 0)
|
|
|
|
|
{
|
|
|
|
|
num[k] = 1;
|
|
|
|
|
pass=1;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(pass == 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if(pass == 1 && strlen(tab[i]) > strlen(res))
|
|
|
|
|
strcpy(res, tab[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf("%s\n", res);
|
|
|
|
|
}
|