Bonjour,
je suis débutant dans ce language...
Je suis entrain d'essayer de modifier des fichier binaire mais je bloque

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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
 
#include <stdio.h>  
#include <stdlib.h>
#include <ctype.h> 
#include <conio.h>
#include <string.h>
 
char nomFile[50] = "c:/testC/CLAS(0).dat";
 
struct etudiant { char efface;
                  int num;
                  char classe[5];
                  char mat[9];
                  char nom[31];
                  char prenom[21];
                 };
 
    char afficherMenu();
    void ajouter();
    char gererChoix(char);                
 
    FILE *bin ;
 
 
 
char afficherMenu() {
     char choix;
     clrscr();
     printf("\n1. ajouter un etudiant");
     printf("\n2. rechercher un etudiant");
     printf("\n3. effacer un etudiant");
     printf("\n4. liste d' etudiant effacé");
     printf("\n5. recuperer un etudiant effacé");
     printf("\n6. copie defragmentee");          
     printf("\n\n0 Quitter sans confirmation");
     printf("\n--------------------------------");
     printf("\nVotre choix :   ");
     scanf("%c", &choix);
     return choix;          
}
 
 
 
 
 
char verifierMat(etudiant newEtu) {
 
     etudiant etuLu;
     char choix;
     bin = fopen(nomFile,"r+b");
     if (bin == NULL) {
            printf("ERROR D'OUVERTURE");
            getch();
            exit(0);      
    }
 
 
     fread(&etuLu, sizeof(etuLu),1, bin);
     while (!feof(bin)) {
           if (strcmp(etuLu.mat, newEtu.mat)==0) {
              printf("\nLe matricule exste deja... ");
              if (etuLu.efface == 'o') {
                 printf("\nVoulez vous le recuperer (le rendre non supprime) ? [o]");
                 scanf(" %c",&choix);
                 if (toupper(choix) == 'O') {
                         etuLu.efface='n';
                         fwrite(&etuLu,sizeof(struct etudiant),1,bin);                          
                         return 'y';
                 }
               return 'n';
              }
              else{
                     printf("\nVoulez vous le recuperer l'emplacement (le supprimer a vie)? [o]");
                     scanf("%*c");
                     scanf("%c",&choix);
                     if (toupper(choix) == '0') {
                         etuLu.efface='e';
                         fwrite(&etuLu,sizeof(struct etudiant),1,bin);
                         return 'y';
                     }
                     else return 'n';
              }
 
 
           }
           else fread(&etuLu, sizeof(etuLu),1, bin);
 
     }
     fclose(bin);
     return 'n';
 
}
 
void ajouter() {
    char verif; 
 
    struct etudiant temp;
    temp.efface = 'n';
    printf("Entrer num ?");
    scanf("%d",&temp.num);
    printf("Entrer la classe (?T??)");
    scanf("%s",temp.classe);
    printf("Entrer matricule (8 lettre chiffre) ?");
    scanf("%8s",temp.mat);
    verif = verifierMat(temp);
    printf("\n\n VERIFMAT FINI");
    getch();
    if (verif == 'n') {
             printf("Entrer nom ?");
             scanf("%s",temp.nom);   
             printf("Entrer prenom ?");
             scanf("%s",temp.prenom);
 
      bin = fopen(nomFile,"ab");
      if (bin == NULL) {
             printf("ERROR D'OUVERTURE");
             getch();
             exit(0);      
      }            
      fwrite(&temp,sizeof(struct etudiant),1,bin); 
    }
    fclose(bin);
}
 
 
char gererChoix(char choix) {
     switch(choix) {
                   case '0' : return '0'; break;
                   case '1' : ajouter(); break;
                   //case '2' rechercher();
     }
}
 
int main() {
 
 
    char choix;
    do {
    choix = afficherMenu();
    choix = gererChoix(choix);
    }while (choix != '0');
    getch();
}
Mon fichier binaire de base est : http://yrejk2.ifrance.com/c/CLAS(0).dat qui en faite contient ceci

Mais je ne comprend pas pourquoi tout d'abord quand il passe dans la méthode verifierMat il ne modifie pas mon fichier binaire alors que je lui demande de changer le temp.efface.

Un tout grand merci a toute personne qui pourrait m'aider...

Jeremy

ps :
config : dev-C++ sur winXP
emplacement de base : c:/testC/...