parent
4c0bdedf18
commit
abe3449c16
Binary file not shown.
@ -0,0 +1,5 @@
|
|||||||
|
algo 4 algorithme périodique 1
|
||||||
|
maths 2 mathématiques
|
||||||
|
maths 4
|
||||||
|
maths 5
|
||||||
|
math 5 sdjlkgf sdkjgf 55dsf
|
@ -0,0 +1,26 @@
|
|||||||
|
#include "tp9.h"
|
||||||
|
|
||||||
|
void test(void)
|
||||||
|
{
|
||||||
|
Mat tmat[50];
|
||||||
|
int nbmat, res;
|
||||||
|
char code[6];
|
||||||
|
nbmat = chargeFmat(tmat, 50);
|
||||||
|
if(nbmat < 0)
|
||||||
|
return;
|
||||||
|
afficheTmat(tmat, nbmat);
|
||||||
|
printf("Code de la matiere a rechercher : ");
|
||||||
|
scanf("%s", code);
|
||||||
|
res = rechMat(code, tmat, nbmat);
|
||||||
|
if(res == -1)
|
||||||
|
printf("Matiere non trouvee, code incorrect !!!\n");
|
||||||
|
else
|
||||||
|
afficheMat(tmat[res]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
//test();
|
||||||
|
ajoutMat();
|
||||||
|
return;
|
||||||
|
}
|
@ -0,0 +1,130 @@
|
|||||||
|
#include "tp9.h"
|
||||||
|
|
||||||
|
Mat lireMat(FILE *fe)
|
||||||
|
{
|
||||||
|
Mat c;
|
||||||
|
fscanf(fe, "%s%d%*c", c.code, &c.coef);
|
||||||
|
fgets(c.desig, 32, fe);
|
||||||
|
c.desig[strlen(c.desig)-1] = '\0';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficheMat(Mat c)
|
||||||
|
{
|
||||||
|
printf("%s\t%d\t%s\n", c.code, c.coef, c.desig);
|
||||||
|
}
|
||||||
|
|
||||||
|
int chargeFmat(Mat tmat[], int nbmax)
|
||||||
|
{
|
||||||
|
Mat c;
|
||||||
|
int i = 0;
|
||||||
|
FILE *fe;
|
||||||
|
fe = fopen("matieres.txt", "r");
|
||||||
|
if (fe == NULL)
|
||||||
|
{
|
||||||
|
printf("Erreur d'ouverture du fichier");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
c = lireMat(fe);
|
||||||
|
while(!feof(fe))
|
||||||
|
{
|
||||||
|
if(i == nbmax)
|
||||||
|
{
|
||||||
|
printf("Probleme, tableau plein !!!");
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
tmat[i] = c;
|
||||||
|
i++;
|
||||||
|
c = lireMat(fe);
|
||||||
|
}
|
||||||
|
fclose(fe);
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
void afficheTmat(Mat tmat[], int nbmat)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
printf("CodeM\tCoef\tDesignation\n");
|
||||||
|
for(i = 0; i < nbmat; i++)
|
||||||
|
{
|
||||||
|
afficheMat(tmat[i]);
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
int rechMat(char code[], Mat tmat[], int nbmat)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < nbmat; i++)
|
||||||
|
{
|
||||||
|
if(strcmp(code, tmat[i].code) == 0)
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Mat saisieMat(Mat tmat[], int nbmat)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
Mat c;
|
||||||
|
printf("Saisie d'une matiere\n");
|
||||||
|
printf("Code:\t ");
|
||||||
|
scanf("%s", c.code);
|
||||||
|
res = rechMat(c.code, tmat, nbmat);
|
||||||
|
while(res != -1)
|
||||||
|
{
|
||||||
|
printf("\nErreur : Code déjà enregistré pour %s\n", tmat[res].desig);
|
||||||
|
printf("Retapez : \t");
|
||||||
|
scanf("%s", c.code);
|
||||||
|
printf("%s", c.code);
|
||||||
|
res = rechMat(c.code, tmat, nbmat);
|
||||||
|
}
|
||||||
|
printf("\nCoefficient : \t");
|
||||||
|
scanf("%d%*c", &c.coef);
|
||||||
|
printf("\nDesignation : \t");
|
||||||
|
fgets(c.desig, 32, stdin);
|
||||||
|
c.desig[strlen(c.desig)-1] = '\0';
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ajoutMat(void)
|
||||||
|
{
|
||||||
|
Mat tmat[50], c;
|
||||||
|
int nbmat, res;
|
||||||
|
char code[6], rep ='o';
|
||||||
|
nbmat = chargeFmat(tmat, 50);
|
||||||
|
if(nbmat < 0)
|
||||||
|
return;
|
||||||
|
afficheTmat(tmat, nbmat);
|
||||||
|
while(rep == 'o')
|
||||||
|
{
|
||||||
|
if(nbmat == 50)
|
||||||
|
{
|
||||||
|
printf("Probleme, tableau plein !!!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
c = saisieMat(tmat, nbmat);
|
||||||
|
tmat[nbmat] = c;
|
||||||
|
nbmat++;
|
||||||
|
printf("\nAjouter une autre matiere ? (o/n)\t");
|
||||||
|
scanf("%*c%c", &rep);
|
||||||
|
}
|
||||||
|
sauvFmat(tmat, nbmat);
|
||||||
|
}
|
||||||
|
|
||||||
|
void sauvFmat(Mat tmat[], int nbmat)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
FILE *fe;
|
||||||
|
fe = fopen("matieres.txt", "w");
|
||||||
|
if(fe == NULL)
|
||||||
|
{
|
||||||
|
printf("Erreur d'ouverture du fichier");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for(i = 0; i < nbmat; i++)
|
||||||
|
fprintf(fe, "%s\t%d\t%s\n", tmat[i].code, tmat[i].coef, tmat[i].desig);
|
||||||
|
fclose(fe);
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char code[6];
|
||||||
|
int coef;
|
||||||
|
char desig[32];
|
||||||
|
} Mat;
|
||||||
|
|
||||||
|
Mat lireMat(FILE *fe);
|
||||||
|
void afficheMat(Mat c);
|
||||||
|
int chargeFmat(Mat tmat[], int nbmax);
|
||||||
|
void afficheTmat(Mat tmat[], int nbmat);
|
||||||
|
int rechMat(char code[], Mat tmat[], int nbmat);
|
||||||
|
Mat saisieMat(Mat tmat[], int nbmat);
|
||||||
|
void ajoutMat(void);
|
||||||
|
void sauvFmat(Mat tmat[], int nbmat);
|
Loading…
Reference in new issue