diff --git a/Algo/tp/tp8/Final/exe b/Algo/tp/tp8/Final/exe index e143272..9fb57e1 100755 Binary files a/Algo/tp/tp8/Final/exe and b/Algo/tp/tp8/Final/exe differ diff --git a/Algo/tp/tp8/Final/fichierMots.txt b/Algo/tp/tp8/Final/fichierMots.txt index e69de29..e9f83bf 100644 --- a/Algo/tp/tp8/Final/fichierMots.txt +++ b/Algo/tp/tp8/Final/fichierMots.txt @@ -0,0 +1,7 @@ +baie +bail +bailler +baillera +baillerai +bal +balai diff --git a/Algo/tp/tp8/Final/fichierMotsLong.txt b/Algo/tp/tp8/Final/fichierMotsLong.txt new file mode 100644 index 0000000..08dbcf9 --- /dev/null +++ b/Algo/tp/tp8/Final/fichierMotsLong.txt @@ -0,0 +1 @@ +barbe à papa diff --git a/Algo/tp/tp8/Final/fichierNotes.txt b/Algo/tp/tp8/Final/fichierNotes.txt index e69de29..f42e1f3 100644 --- a/Algo/tp/tp8/Final/fichierNotes.txt +++ b/Algo/tp/tp8/Final/fichierNotes.txt @@ -0,0 +1,6 @@ +duponal maths 15 +duponal algo1 14 +duranro maths 13 +duranro algo2 12.3 +duranro maths 11 +martige algo1 16 diff --git a/Algo/tp/tp8/Final/testtp8.c b/Algo/tp/tp8/Final/testtp8.c new file mode 100644 index 0000000..530d047 --- /dev/null +++ b/Algo/tp/tp8/Final/testtp8.c @@ -0,0 +1,57 @@ +#include "tp8.h" + +int main(void) +{ + char tab[15][27], mot[27]; + int nb = charger(tab), in=1; + + if(nb < 0) + return -1; + + while(in != 0) + { + afficher(tab, nb); + printf("\nAjouter un mot ou chercher le plus long ? (0/1/2)\n"); + scanf("%d", &in); + + if (in == 1) + { + printf("\nMot à insert : "); + scanf("%s%*c", mot); + insert(tab, &nb, mot); + } + else if (in == 2) + { + printf("\nLettres à trouver : "); + scanf("%s%*c", mot); + chercher(tab, nb, mot); + } + } + + return sauvegarder(tab, nb); +} + +/*int main(void) +{ + char tab[15][27], mot[27]; + int nb = chargerLong(tab), in=1; + + if(nb < 0) + return -1; + + while(in != 0) + { + afficher(tab, nb); + printf("\nAjouter un mot ? (0/1)\n"); + scanf("%d", &in); + + if (in == 1) + { + printf("\nMot à insert : "); + fgets(mot, 27, stdin); + insert(tab, &nb, mot); + } + } + + return sauvegarderLong(tab, nb); +}*/ \ No newline at end of file diff --git a/Algo/tp/tp8/Final/testtp8f.c b/Algo/tp/tp8/Final/testtp8f.c deleted file mode 100644 index beed681..0000000 --- a/Algo/tp/tp8/Final/testtp8f.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "tp8f.h" - -int main(void) -{ - char tab[27][15]; - - charger(tab[15]); - afficher(tab[15]); - return 0; -} \ No newline at end of file diff --git a/Algo/tp/tp8/Final/tp8f.c b/Algo/tp/tp8/Final/tp8.c similarity index 50% rename from Algo/tp/tp8/Final/tp8f.c rename to Algo/tp/tp8/Final/tp8.c index 01d3ed0..77ce0d7 100644 --- a/Algo/tp/tp8/Final/tp8f.c +++ b/Algo/tp/tp8/Final/tp8.c @@ -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); } \ No newline at end of file diff --git a/Algo/tp/tp8/Final/tp8.h b/Algo/tp/tp8/Final/tp8.h new file mode 100644 index 0000000..b67e9db --- /dev/null +++ b/Algo/tp/tp8/Final/tp8.h @@ -0,0 +1,19 @@ +#include +#include +#include + +int moyenne(void); + +void initialiser(char mot[], int n); +void placer(char mot1[], char c, char mot2[]); +void jeuPendu(void); + +int charger(char tab[][27]); +void afficher(char tab[][27], int nb); +void insert(char tab[][27], int *nb, char mot[]); +int sauvegarder(char tab[][27], int nb); + +int chargerLong(char tab[][27]); +int sauvegarderLong(char tab[][27], int nb); + +void chercher(char tab[][27], int nb, char mot[]); \ No newline at end of file diff --git a/Algo/tp/tp8/Final/tp8f.h b/Algo/tp/tp8/Final/tp8f.h deleted file mode 100644 index 7e1643a..0000000 --- a/Algo/tp/tp8/Final/tp8f.h +++ /dev/null @@ -1,11 +0,0 @@ -#include -#include - -int moyenne(void); - -void initialiser(char mot[], int n); -void placer(char mot1[], char c, char mot2[]); -void jeuPendu(void); - -void charger(char *tab[2]); -void afficher(char *tab[2]); \ No newline at end of file