Bonsoir à tous,
Dans le code qui suit, pourriez vous m'expliquer pourquoi si je fais un test de lecture a la fin de ma fonction modif_stock, le stock réel est bien modifier, mais une fois que je veux lire le fichier article après la fin de mon programme, aucune modification n'y à été enregistrée.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include <assert.h>
#include <myconio.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 
typedef struct article
{
    char code[10];
	char desc[30];
	int stock_min;
	int stock_reel;
};
 
struct vente
{
    int code;
    int vendu;
};
 
void lect_vente(struct vente* une_vente, FILE*);
void rech_article(struct article* un_article, struct vente une_vente, FILE*);
void modif_stock(struct article* un_article, struct vente une_vente, FILE*);
 
int main ()
{
   FILE* fic_vente;
   FILE* fic_article;
   struct article un_article;
   struct vente une_vente;
   int stock_min, stock_reel ;
 
   fic_vente = fopen("vente.txt", "r");
   assert(fic_vente != NULL);
   fic_article = fopen("article.dat", "r+b");
   assert(fic_article != NULL);
 
   while(!feof(fic_vente))
   {
       lect_vente(&une_vente, fic_vente);
       rech_article(&un_article, une_vente, fic_article);
       modif_stock(&un_article, une_vente, fic_article);
   }
   fclose(fic_vente);
   fclose(fic_article);
}
 
void lect_vente(struct vente* une_vente, FILE* fic_vente)
{
    char chaine[10];
 
    fgets(chaine, sizeof(une_vente->code), fic_vente);
    une_vente->code = atoi(chaine);
    fgets(chaine, sizeof(une_vente->vendu), fic_vente);
    une_vente->vendu = atoi(chaine);
}
 
void rech_article(struct article* un_article, struct vente une_vente, FILE* fic_article)
{
    int nbr_enreg, nbr_octets;
 
    fseek(fic_article, 0, SEEK_END);
    nbr_octets = ftell(fic_article);
    nbr_enreg = (nbr_octets/sizeof(struct article))/2;
    fseek(fic_article, (nbr_octets) - sizeof(struct article)*((nbr_enreg)+1), SEEK_SET);
 
    fread(un_article, sizeof(struct article), 1, fic_article);
 
    while(atoi(un_article->code) != une_vente.code)
    {
        if(une_vente.code < atoi(un_article->code))
        {
            nbr_enreg = nbr_enreg/2;
            if (nbr_enreg < 1)
                  nbr_enreg = 1;
 
            fseek(fic_article, -sizeof(struct article), SEEK_CUR);
            fseek(fic_article, -sizeof(struct article) * nbr_enreg , SEEK_CUR);
            fread(un_article, sizeof(struct article), 1, fic_article);
        }
        else
        {
            nbr_enreg = nbr_enreg/ 2;
            if(nbr_enreg<1)
                nbr_enreg = 1;
 
            fseek(fic_article, -sizeof(struct article), SEEK_CUR);
            fseek(fic_article, sizeof(struct article) * nbr_enreg , SEEK_CUR);
            fread(un_article, sizeof(struct article), 1, fic_article);
        }
    }
}
 
void modif_stock(struct article* un_article, struct vente une_vente, FILE* fic_article)
{
    un_article->stock_reel -= une_vente.vendu;
    fwrite(&un_article, sizeof(struct article), 1, fic_article);
}
Je vous remercie d'avance pour vos réponse