diff --git a/Algo/tp/tp7/tp7.c b/Algo/tp/tp7/tp7.c index 950da9e..752e8f5 100644 --- a/Algo/tp/tp7/tp7.c +++ b/Algo/tp/tp7/tp7.c @@ -1,4 +1,4 @@ -#include "tp7.h" + #include "tp7.h" int remplirTableaux(int tMatieres[],int tCoeff[],int max) { @@ -23,8 +23,8 @@ int remplirTableaux(int tMatieres[],int tCoeff[],int max) fscanf(flot, "%d%d", &nMatieres, &coeff); i = i + 1; } - return i; fclose(flot); + return i; } void affichage(int tMatieres[],int tCoeff[], int nbMatieres) @@ -267,4 +267,4 @@ void MoyenneEtudiant(int tCoeff[], int tMatieres[], int tNotes[], int tNbNotes[] else printf("\t%d\tpas de note\n", tMatieres[i]); } printf("Moyenne générale\t%d\n", moyenneMatiere); -} \ No newline at end of file +} diff --git a/Algo/tp/tp8/Notes.don b/Algo/tp/tp8/Notes.don new file mode 100644 index 0000000..50ef4a4 --- /dev/null +++ b/Algo/tp/tp8/Notes.don @@ -0,0 +1,6 @@ +duponal maths 15 +duponal algo1 14 +duranro maths 13 +duranro algo2 12.3 +duranro maths 11 +martige algo1 16 \ No newline at end of file diff --git a/Algo/tp/tp8/exe b/Algo/tp/tp8/exe new file mode 100755 index 0000000..455e92c Binary files /dev/null and b/Algo/tp/tp8/exe differ diff --git a/Algo/tp/tp8/mots.don b/Algo/tp/tp8/mots.don new file mode 100644 index 0000000..e9f83bf --- /dev/null +++ b/Algo/tp/tp8/mots.don @@ -0,0 +1,7 @@ +baie +bail +bailler +baillera +baillerai +bal +balai diff --git a/Algo/tp/tp8/testtp8.c b/Algo/tp/tp8/testtp8.c new file mode 100644 index 0000000..3260ca2 --- /dev/null +++ b/Algo/tp/tp8/testtp8.c @@ -0,0 +1,26 @@ +#include "tp8.h" + +void testinitialiser(void) +{ + char mot[10]; + initialiser(mot, 10); + printf("%s\n", mot); +} + +void testplacer(void) +{ + char mot1[10] = "bonjour"; + char mot2[10]; + initialiser(mot2, 7); + placer(mot1, 'n', mot2); + printf("%s\n", mot2); +} + +int main(void) +{ + //extraction(); + //testinitialiser(); + //testplacer(); + jeuPendu(); + return 0; +} diff --git a/Algo/tp/tp8/tp8.c b/Algo/tp/tp8/tp8.c new file mode 100644 index 0000000..4825ce8 --- /dev/null +++ b/Algo/tp/tp8/tp8.c @@ -0,0 +1,134 @@ +#include "tp8.h" + +void extraction(void) +{ + int nb =0; + char login[8], code[6], codeMat[6]; + float note, som = 0, moyenne; + FILE *flot; + flot = fopen("Notes.don", "r"); + if (flot == NULL) + { + printf("Erreur d'ouverture du fichier"); + return; + } + printf("Entrez le code de la matiere : "); + scanf("%s", codeMat); + printf("\n\nNotes données en %s\n", codeMat); + printf("\nETUDIANTS\tNOTES\n"); + fscanf(flot, "%s%s%f", login, code, ¬e); + while(!feof(flot)) + { + if(strcmp(code, codeMat) == 0) + { + printf("%s\t\t%.2f\n", login, note); + som = som + note; + nb = nb + 1; + } + fscanf(flot, "%s%s%f", login, code, ¬e); + } + fclose(flot); + if(nb == 0) + printf("\nAucune note pour cette matiere\n\n"); + else + { + moyenne = som / nb; + printf("\nMoyenne :\t%.2f\n\n", moyenne); + } +} + +void initialiser(char mot[], int n) +{ + int i; + for(i = 0; i < n; i++) + mot[i] = '_'; + mot[n] = '\0'; +} + +void placer(char mot1[], char c, char mot2[]) +{ + int i; + for(i = 0; mot1[i] != '\0'; i++) + { + if(mot1[i] == c) + mot2[i] = c; + } + mot2[i] = '\0'; +} + +void jeuPendu(void) +{ + char mot[10], mot2[10], mot3[10], c; + int i, nb = 0, nb2; + printf("Joueur1, proposez un mot : \n"); + system("stty -echo"); + scanf("%s", mot); + system("stty echo"); + nb = compterLettres(mot); + initialiser(mot2, nb); + printf("Joueur1, donnez le nombre de coups : \n"); + scanf("%d", &nb2); + printf("Mot de %d lettres à trouver en %d étapes\n", nb, nb2); + printf("%s", mot2); + printf("\n"); + for(i = 0; i < nb2; i++) + { + printf("Joueur2, proposez une lettre :"); + scanf("%*c%c", &c); + placer(mot, c, mot2); + printf("%s", mot2); + printf("\nJoueur2, avez-vous trouvé le mot ? (o/n) : "); + scanf("%*c%c", &c); + if(c == 'o') + { + printf("Joueur2, quel est le mot ? : "); + scanf("%s", mot3); + if(strcmp(mot, mot3) == 0) + { + printf("\nBravo ! Vous avez trouvé le mot en %d étapes\n", i + 1); + return; + } + else + { + printf("Ce n'est pas le mot\n"); + } + } + } + printf("Joueur2, vous avez perdu ! Le mot était %s\n", mot); +} + +int compterLettres(char mot[]) +{ + int i, nb = 0; + for(i = 0; mot[i] != '\0'; i++) + nb = nb + 1; + return nb; +} + +/* Exercice 3 */ + +void chargement(int tMot[][nbMots]) +{ + int i = 0, j; + + FILE *flot; + flot = fopen("mots.don", "r"); + if (flot == NULL) + { + printf("Erreur d'ouverture du fichier"); + return; + } + fscanf(flot, "%s", tMot[0]); + while(feof(flot)) + { + if(i == nbMots) + { + printf("Erreur : trop de mots dans le fichier"); + return; + } + for(j = 0; j < nbLettres; j++) + { + fscanf(flot, "%d", &tMot[i][j]); + } + } +} \ No newline at end of file diff --git a/Algo/tp/tp8/tp8.h b/Algo/tp/tp8/tp8.h new file mode 100644 index 0000000..fa313ef --- /dev/null +++ b/Algo/tp/tp8/tp8.h @@ -0,0 +1,9 @@ +#include +#include +#include + +void extraction(void); +void initialiser(char mot[], int n); +void placer(char mot1[], char c, char mot2[]); +void jeuPendu(void); +int compterLettres(char mot[]); \ No newline at end of file