Gros Probleme En C

cs_Infern0 Messages postés 5 Date d'inscription jeudi 13 novembre 2003 Statut Membre Dernière intervention 23 août 2010 - 16 nov. 2003 à 11:33
garslouche Messages postés 583 Date d'inscription mardi 26 novembre 2002 Statut Membre Dernière intervention 29 mai 2015 - 17 nov. 2003 à 10:53
Bon, voila 3 fonction de mon programme. Avec celle d'affichage, quand j'affiche la 1ere, y a aucun probleme, si j'affiche la deuxieme, g des chiffre farfelus. Ci-joint : les sources des 3fonctions et les capture d'ecran de l'affichage.

void ajoutrdv(void){
FILE *FichMED;
FILE *FichRDV;
struct RDV rdv;
int i;

if ((FichRDV = fopen("FichRDV.txt","r+"))!=NULL){
for (i=1;i<4;i++){
rdv.heure = 40-(i*10);
rdv.minute = 40-(i*10);
rdv.numrecord = 0;
fseek(FichRDV,((sizeof(struct RDV))*i),SEEK_SET);
fwrite(&rdv,sizeof(struct RDV),1,FichRDV);
}
}
fclose(FichRDV);
}

void ajoutrdv2(void){
FILE *FichMED;
FILE *FichRDV;
struct RDV rdv;
int i;

if ((FichRDV = fopen("FichRDV.txt","r+"))!=NULL){
for (i=1;i<4;i++){
rdv.heure = i*10;
rdv.minute = i*10;
rdv.numrecord = 0;
fseek(FichRDV,((sizeof(struct RDV))*i),SEEK_SET);
fwrite(&rdv,sizeof(struct RDV),1,FichRDV);
}
}
fclose(FichRDV);
}

void affichagerdv(void){
FILE *FichRDV;
int eof;
struct RDV rdv;

if ((FichRDV = fopen("FichRDV.txt","r+")) != NULL){
fread(&rdv,sizeof(struct RDV),1,FichRDV);
while (!(eof = feof(FichRDV))){
cout<<rdv.heure<<":"<<rdv.minute<<" "<<rdv.numrecord<<endl;
fread(&rdv,sizeof(struct RDV),1,FichRDV);
}
fclose(FichRDV);
}
}

capture d'ecran de ajoutrdv() : ***********************************************
*1 : Cree le fichier medecin *
*2 : Remise a blanc du fichier de rendez-vous *
*3 : Ajouter un medecin *
*4 : Affichage du fichier medecin *
*5 : Ajouter un rendez-vous *
*6 : Afficahge rendez-vous *
*0 : Quitter *
***********************************************
0:0 1
30:30 0
20:20 0
10:10 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 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 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 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 0
0:0 0
0:0 0
0:0 0
0:0 0
0:0 0
Press any key to continue . . .

capture d'ecran de ajoutrdv2() :

***********************************************
*1 : Cree le fichier medecin *
*2 : Remise a blanc du fichier de rendez-vous *
*3 : Ajouter un medecin *
*4 : Affichage du fichier medecin *
*5 : Ajouter un rendez-vous *
*6 : Afficahge rendez-vous *
*0 : Quitter *
***********************************************
0:0 1
10:10 1310720
1310720:0 1966080
1966080: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: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: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: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:0 0
0:0 0
0:0 0
0:0 0
0:0 0
0:0 0
Press any key to continue . . .

Si qq arrive a me resoudre le probleme, je lui paye un verre des que je le voit ;)

1 réponse

garslouche Messages postés 583 Date d'inscription mardi 26 novembre 2002 Statut Membre Dernière intervention 29 mai 2015 1
17 nov. 2003 à 10:53
Ca tombe bien j'avais un peu soif...

Il faut que tu ouvres ton fichier en mode binaire.
Pour cela remplace "r+" par "rb+"

Tu me l'envoies par la poste mon coup à boire ?

On ne force pas une curiosité, on l'éveille.
.................................................Daniel Pennac
0
Rejoignez-nous