Ajout du tp8 et modif de tp7

master
Antoine PEREDERII 2 years ago
parent 6cce9c63e5
commit ac679b44bd

@ -1,4 +1,4 @@
#include "tp7.h" #include "tp7.h"
int remplirTableaux(int tMatieres[],int tCoeff[],int max) 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); fscanf(flot, "%d%d", &nMatieres, &coeff);
i = i + 1; i = i + 1;
} }
return i;
fclose(flot); fclose(flot);
return i;
} }
void affichage(int tMatieres[],int tCoeff[], int nbMatieres) 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]); else printf("\t%d\tpas de note\n", tMatieres[i]);
} }
printf("Moyenne générale\t%d\n", moyenneMatiere); printf("Moyenne générale\t%d\n", moyenneMatiere);
} }

@ -0,0 +1,6 @@
duponal maths 15
duponal algo1 14
duranro maths 13
duranro algo2 12.3
duranro maths 11
martige algo1 16

Binary file not shown.

@ -0,0 +1,7 @@
baie
bail
bailler
baillera
baillerai
bal
balai

@ -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;
}

@ -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, &note);
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, &note);
}
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]);
}
}
}

@ -0,0 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void extraction(void);
void initialiser(char mot[], int n);
void placer(char mot1[], char c, char mot2[]);
void jeuPendu(void);
int compterLettres(char mot[]);
Loading…
Cancel
Save