You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
2.4 KiB

#include "tp8f.h"
int moyenne(void)
{
float note, moy=0, nb=0;
char in[27], nom[27], mat[27];
FILE *flot;
flot = fopen("fichierNotes.txt", "r");
if (flot == NULL)
{
printf("Problème lors de l'ouverture du fichier.\n");
return -1;
}
printf("Tapez le code de la matière à traiter : ");
scanf("%s", in);
/*in[strlen(in)-1] = '\0';*/
printf("Notes données en %s :\nETUDIANTS\tNOTES\n", in);
fscanf(flot, "%s%s%f", nom, mat, &note);
while(!feof(flot))
{
if (strcmp(in, mat) == 0)
{
nb = nb+1;
moy = moy+note;
printf("%s\t\t%.2f\n", nom, note);
}
fscanf(flot, "%s%s%f", nom, mat, &note);
}
if (nb == 0)
printf("aucune note pour cette matière\n");
else
printf("\nMOYENNE :\t%.2f\n", moy/nb);
fclose(flot);
return moy;
}
void initialiser(char mot[], int n)
{
for (int i = 0; i < n; ++i)
*(mot +i) = '-';
}
void placer(char mot1[], char c, char mot2[])
{
for (int i = 0; i < strlen(mot1); ++i)
if (*(mot1+i) == c)
*(mot2+i) = c;
}
void jeuPendu(void)
{
int etapes = 4;
char mot1[27], mot2[27], mot3[27], c;
printf("Joueur 1, proposez un mot à deviner : ");
system("stty -echo");
scanf("%s%*c", mot1);
system("stty echo");
initialiser(mot2, strlen(mot1));
printf("\nMot de %d lettres à trouver en %d étapes\n%s\n\n", strlen(mot1), etapes, mot2);
for (int i = 0; i < etapes; ++i)
{
printf("proposez une lettre : ");
scanf("%c%*c", &c);
placer(mot1, c, mot2);
printf("%s\navez vous reconnu le mot (o/n) ?", mot2);
scanf("%c%*c", &c);
if (c == 'o')
{
printf("\nmot ? ");
scanf("%s%*c", mot3);
if (strcmp(mot1, mot3) == 0)
{
printf("Bravo vous avez gagné !!!\nmot trouvé en %d étapes\n", i);
return;
}
else
printf("Désolé ...\n");
}
printf("\n");
}
printf("\nmot ? ");
scanf("%s%*c", mot3);
if (strcmp(mot1, mot3) == 0)
{
printf("Bravo vous avez gagné !!!\nmot trouvé en %d étapes\n", etapes+1);
return;
}
else
printf("Désolé ... Vous avez perdu.\n");
}
void charger(char *tab[2])
{
int i=0;
char mot[27];
FILE *flot;
flot = fopen("fichierMots.txt", "r");
if (flot == NULL)
{
printf("Problème lors de l'ouverture du fichier.\n");
return;
}
fscanf(flot, "%s", mot);
while(!feof(flot))
{
for (int j = 0; j < strlen(mot); ++j)
tab[j][i] = mot[j];
i = i+1;
}
}
void afficher(char *tab[2])
{
for (int i = 0; i < 15; ++i)
{
for (int j = 0; j < 27; ++j)
{
printf("%c", tab[i][j]);
}
printf("\n");
}
}