Advertisement
Eastkap

Untitled

Dec 4th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.01 KB | None | 0 0
  1. #include<stdlib.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. #include "nomenclature.h"
  6.  
  7. #define TMP_STR_SIZE 256
  8. #define TAILLEMAX 1000
  9.  
  10. /*int lit_nomenclature(Nomenclature* *N, char *nom_fic){
  11.     FILE *f = fopen(nom_fic,"r");
  12.     if (!f){
  13.         printf("Erreur lors de l'ouverture du fichier %s\n",nom_fic);
  14.         return (int)NULL;
  15.     }else{
  16.         int i, occ, num, nbpiece;
  17.         float poids;
  18.         char ligne[TMP_STR_SIZE], nom[40];
  19.         fgets(ligne, TMP_STR_SIZE, f);
  20.         sscanf(ligne,"%s",nom);
  21.         fgets(ligne, TMP_STR_SIZE, f);
  22.         sscanf(ligne,"%d",nom, &nbpiece);
  23.         Nomenclature *N = init_nomenclature(nom, TAILLEMAX);
  24.         while(feof(f)){
  25.             //fscanf(f,"%s",ligne);
  26.             //ajouter_Lmot(lm,ligne);
  27.         }
  28.     }
  29.     fclose(f);
  30.     return 1;
  31. }*/
  32.  
  33. int lit_nomenclature(Nomenclature* *N, char* nom_fic)
  34. {
  35.         FILE *f=fopen(nom_fic,"r");
  36.         int i,occ,num,nbpiece;
  37.         float poids;
  38.         char line[TMP_STR_SIZE],nom[40];
  39.         if (!f)
  40.         {
  41.                 fprintf(stderr,"Impossible to read the file\n");
  42.                 return 0;
  43.         }
  44.         for(i=0;i<4;i++)
  45.           fgets(line,TMP_STR_SIZE,f);
  46.         sscanf(line,"%s %d",nom,&nbpiece);
  47.         *N=init_nomenclature(nom,TAILLEMAX);
  48.         for(i=0;i<nbpiece;i++)
  49.         {
  50.                 fgets(line,TMP_STR_SIZE,f);
  51.                 sscanf(line,"%d %s %f",&num,nom,&poids);
  52.                 (*N)->Tab[i]=cree_piece_sans_composant(num,nom,poids);
  53.                 fgets(line,TMP_STR_SIZE,f);
  54.                 sscanf(line,"%d %d",&num,&occ);
  55.                 while(num!=-1 && occ!=-1){
  56.                         fgets(line,TMP_STR_SIZE,f);
  57.                         sscanf(line,"%d %d",&num,&occ);
  58.                 }
  59.         }
  60.         (*N)->nbpiece=nbpiece;
  61.             rewind(f);
  62.         fgets(line,TMP_STR_SIZE,f);
  63.         fgets(line,TMP_STR_SIZE,f);
  64.         for(i=0;i<nbpiece;i++)
  65.         {
  66.                 fgets(line,TMP_STR_SIZE,f);
  67.                 sscanf(line,"%d %d",&num,&occ);
  68.                 while(num!=-1 && occ!=-1){
  69.                         ajout_composant_piece((*N)->Tab[i],(*N)->Tab[recherche_piece_num(*N,num)],occ);
  70.                         fgets(line,TMP_STR_SIZE,f);
  71.                         sscanf(line,"%d %d",&num,&occ);
  72.                 }
  73.                 fgets(line,TMP_STR_SIZE,f);
  74.         }
  75.         return 1;
  76. }
  77.  
  78. int sauvegarde_nomenclature(Nomenclature *N, char *nom_fic){
  79.     FILE *f = fopen(nom_fic,"w");
  80.     if (f == NULL){
  81.         printf("Erreur lors de l'ouverture du fichier %s\n",nom_fic);
  82.         return (int)NULL;
  83.     }else{
  84.         int i;
  85.     Composant* temp;
  86.         fprintf(f,"\n#made by Sanchez and Calle Viera\n\n");
  87.         fprintf(f,"%s %d\n",N->nom,N->nbpiece);
  88.         for(i=0; i<N->nbpiece; i++){
  89.             fprintf(f, "%d  %s  %.2f", N->Tab[i]->num,N->Tab[i]->nom,N->Tab[i]->poids);
  90.             temp=N->Tab[i]->L_composant;
  91.             while(temp->suiv){
  92.                 if(temp->p->num && temp->occ){
  93.                     fprintf(f, "\n\t%d  %d",temp->p->num, temp->occ);
  94.                     temp=temp->suiv;
  95.                 }
  96.             }
  97.             fprintf(f, "\n\t-1  -1\n");
  98.         }
  99.     }
  100.     fclose(f);
  101.     return 1;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement