J'ai un problème ici lorsque j'effectue ma boucle "while (*ChariotClient[i] != '\0') " mon fichier ne veut pas s'ouvrir, alors que lorsque je test ma fonction InfosArticle je n'ai aucun problème.
Code:# include <stdio.h> # include <string.h> void LectureCodeBarres(unsigned char[], char[], char[]); struct Article { char CodeFabricant[6]; char CodeArticle[6]; char Nom[30]; int Rayon; double prix; int stock; }; struct Article InfosArticle(char[], char[], int*); double lecture_sequentielle(unsigned char[][12]); int main() { struct Article A; int position; unsigned char CodeBarres[12] = { 13, 49, 17, 5, 29, 13, 102, 66, 80, 78, 68, 66 }; char code_fab[6]; char code_art[6]; double prix = 0; // LectureCodeBarres(CodeBarres, code_fab, code_art); // puts(code_fab); // puts(code_art); // A=InfosArticle(code_fab, code_art, &position); // puts(A.Nom); // printf("%d", position); unsigned char ChariotClient[][12] = { {13, 11, 13, 51, 57, 39, 102, 68, 72, 114, 114, 114}, {19, 11, 55, 57, 39, 39, 114, 68, 116, 78, 66, 66}, {13, 61, 33, 29, 23, 13, 108, 102, 40, 116, 102, 68}, {33, 51, 23, 9, 29, 33, 114, 78, 114, 122, 100, 76}, {13, 19, 5, 23, 9, 13, 92, 78, 66, 66, 116, 72}, {13, 57, 59, 47, 29, 39, 102, 66, 80, 78, 68, 66}, 0 }; prix=lecture_sequentielle(ChariotClient); printf("%lf", prix); return 0; } double lecture_sequentielle(unsigned char ChariotClient[][12]) { int position; struct Article A; char code_fab[6]; char code_art[6]; double somme = 0; int i = 0; while (*ChariotClient[i] != '\0') { LectureCodeBarres(ChariotClient[i], code_fab, code_art); A = InfosArticle(code_fab, code_art, &position); puts(A.Nom); somme = somme + A.prix; i++; } return somme; } struct Article InfosArticle(char code_fabricant[], char article[], int*position) { struct Article inconnu = { "", "", "inconnu", 0, 0.0, 0 }, A; FILE* pf=NULL; errno_t code_erreur; code_erreur = fopen_s(&pf, "C:/Users/anton/Downloads/Articles2020.bin", "r+b"); if (code_erreur != 0) { printf("erreur lors de l'ouverture"); return inconnu; } *position = 0; while ((fread(&A, sizeof(struct Article), 1, pf)) != 0) { // puts(A.CodeArticle); *position = *position + 1; if ( strcmp(A.CodeFabricant, code_fabricant) == 0 && strcmp(A.CodeArticle, article) == 0) return A; } *position = -1; return inconnu; fclose(pf); } void LectureCodeBarres(unsigned char code_barre[], char code_fabricant[], char article[]) { char Jeux[117] = { 0 , 0 , 0 , 0 , 0 , '6' , 0 , 0 , 0 , '8' , 0 , '9', 0 , '0' , 0 , 0 , 0 , '7' , 0 , '2' , 0 , 0 , 0 , '9' , 0 , '1' , 0 , '2' , 0 , '4' , 0 , 0 , 0 , '3' , 0 , '4' , 0 , 0 , 0 , '0' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , '6' , 0 , '5' , 0 , '1', 0 , 0 , 0 , '8' , 0 , '5' , 0 , '7' , 0 , '3', 0 , 0 , 0 , 0 , '3' , 0 , '7' , 0 , 0 , 0 , '8' , 0 , 0 , 0 , 0 , 0 , '5' , 0 , '6', 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , '4' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , '1' , 0 , 0 , 0 , 0 , 0 , '2' , 0 , 0 , 0 , 0 , 0 , '0' , 0 , '9' }; int i, j; for (i = 0; i < 5; i++) code_fabricant[i] = Jeux[code_barre[i + 1]]; for (j = 6; j < 11; j++) article[j - 6] = Jeux[code_barre[j]]; code_fabricant[5] = '\0'; article[5] = '\0'; //int f; //for (f = 0; f < 5; f++) // printf("%c",article[f]); }
-----