Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define tailleP 20
- typedef struct
- {
- char codeMat[6];
- int coef;
- char des[32];
- } Mat;
- Mat lireMat(FILE *flot)
- {
- int l;
- Mat a;
- Mat *b;
- b=&a;
- fscanf(flot,"%s%d",b->codeMat, &b->coef);
- fgets(b->des,32,flot);
- l=strlen(b->des);
- b->des[l-1]='\0';
- return a;
- }
- int chargeFmat(Mat tmat[],int nbmax)
- {
- int i=0;
- Mat a;
- Mat *b;
- b=&a;
- FILE *flot;
- flot=fopen("tabMat.don","r");
- if (flot==NULL)
- {
- printf("Erreur lors de l'ouverture du fichier.\n");
- return -1;
- }
- tmat[i]=lireMat(flot);
- while(!feof(flot))
- {
- if(i==nbmax)
- {
- printf("Dépassement de la capacité du tableau.\n");
- return -2;
- }
- tmat[i]=lireMat(flot);
- i=i+1;
- }
- fclose(flot);
- return i;
- }
- void test(void)
- {
- Mat tmat[20];
- int i, j;
- j=chargeFmat(tmat, tailleP);
- for(i=0;i<j;i++)
- printf("%s\t\t%d\t%s\n",tmat[i].codeMat, tmat[i].coef, tmat[i].des);
- printf("%d\n",i);
- }
- int main(void)
- {
- test();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement