#include #include #include typedef struct { char nom[30]; char nbVitr[3]; char v0,v4,v6,v7,v8,v8p; }TVitrauxDeco ; void quit(void); void ecrLigne2(char car,int offset, char*ligne2 ,char* substitut, FILE *fic); char *ligne, *ligne2; TVitrauxDeco *tableau; int main(/*int nbArg, char **pArg*/) { int var=0; FILE *input=0, *output=0, *tableauImprime=0; int tllLigne, nbLigTab=0, i,j,y=-2, x; char code[6][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}}; char nom[30], *ptrNom=0; char nom2[30], *ptrNom2=0; ligne=0;ligne2=0;tableau=0; atexit(quit); input=fopen("data2.txt"/*pArg[1]*/,"r"); tableauImprime=fopen("tableau.txt"/*pArg[2]*/,"r"); if(!input) printf("Erreur: le fichier d'entree %d n'a pas ete ouvert\n","data.txt"/*pArg[1]*/); if(!tableauImprime) printf("Erreur: le fichier tableau %d n'a pas ete ouvert\n","tableau.txt"/*pArg[2]*/); if(!input || !tableauImprime) { printf("Usage:\targ1: fichier contenant les données à dupliquer\n\targ2: fichier contenant le tableau de correspondances\n\targ3: fichier de sortie qui est cree si non existant et ecrase sinon\n"); exit(1); } //compte les lignes et alloue tableau do { nbLigTab++; if(!lireLigne(0,tableauImprime)) nbLigTab--; }while(!feof(tableauImprime)); if(tableau) free(tableau); tableau=calloc(nbLigTab,sizeof (TVitrauxDeco)); //lit la 1ere ligne du tableau et la parse dans code if(ligne) free(ligne); ligne=malloc(100); if(ligne2) free(ligne2); ligne2=malloc(100); fseek(tableauImprime, 0, SEEK_SET); lireLigne(ligne, tableauImprime); for(i=0; i1) while(ligne[i]!='\t' && ligne[i]!=0) i++; } } output=fopen("test.txt"/*pArg[3]*/,"w"); fgetc(input); while(!feof(input)) { fseek(input,-1,SEEK_CUR); //lecture d'une ligne du fichier d'entree tllLigne=lireLigne(0,input); if(ligne) free(ligne); ligne=calloc(tllLigne+1,1); if(ligne2) free(ligne2); ligne2=calloc(tllLigne+1,1); fseek(input, -tllLigne-2, SEEK_CUR); lireLigne(ligne, input); strcpy(ligne2, ligne); //lecture du champ de nom et recherche dans le tableau x=chCaseN(ligne,7); i=chCaseN(ligne,8); ptrNom2=strcpy(nom2, &(ligne[x])); if(code[0][0]==0) { // ERREUR!!! ERREUR!!! ERREUR!!! printf("La, y'a une ...!!\n"); } ptrNom=strcpy(nom, &(ligne[x])); if(code[0][0]==0) { // ERREUR!!! ERREUR!!! ERREUR!!! printf("La, y'a une ...!!\n"); } nom[i-x-1]=0; x=chCaseN(ligne,14); x=ligne[x]-'0'; if(x) { for(i=0;i n'a pu etre ouvert.\n",nomFic); } else { cpt+=lireLigne(&(chaine[cpt]),input1); i=0; do { cpt+=i; chaine[cpt]='|'; cpt++; }while((i=lireLigne(&(chaine[cpt]),input2))>0); fputs(chaine, output); fputs("\n",output); fclose(input2); } } fclose(input1); fclose(output); fclose(erreur); } */ //Cette fonction renvoie 1 si toutes les cases ont été lues, 0 sinon. //Cette fonction ne controle pas la taille des cases avant d'écrire //attention donc aux dépassements!!! int scanLigne(char *iLigne, int *nbCases, void **pCase) { int i=0, j=0, k=0; while(iLigne[i] && iLigne[i]!='\r' && iLigne[i]!='\n') { while(iLigne[i]=='\t') { ((char**)pCase)[j][k]=0; k=0; i++; j++; if(j>*nbCases) { *nbCases=j; return 0; } } ((char**)pCase)[j][k]=iLigne[i]; i++; k++; } return 1; } //lit une ligne et retourne le nombre de car. lus (comme strlen). //Le \n n'est pas intégré dans la chaine. //si chaine vaut 0, les caracteres ne sont simplement pas stockes int lireLigne(char *oLigne, FILE *iFic) { int cpt=0; int c=0; while(c!='\n' && !feof(iFic)) { c=fgetc(iFic); if(oLigne) oLigne[cpt]=c; cpt++; } cpt--; if(oLigne) oLigne[cpt]=0; return cpt; } int chCaseN(char *ligne, int numCase) { int x=0, i; for(i=0;i