bonjour,
j'ai un problème avec un buffer de 10 caractères.
les caractères d'indice 4 et 9 sont des sentinelles (EOF)
j'utilise le mode ios::binary pour lire le fichier par blocs de caractères
la fonction carSuiv() répond à mes attente.
par contre, dans la fonction reculer(), l'appel de la méthode "f.read(tampon+SENTINELLE1+1,TAILLEDEMITAMPON) fait comme si elle n'était pas appelée
quelqu'un a une idé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 #define SENTINELLE1 4 #define SENTINELLE2 9 #define TAILLEDEMITAMPON 4 #define TAILLETAMPON 10 char tampon[TAILLETAMPON]; int block(0),enAvant(0); char c; ifstream f; void carSuiv(); void reculer(); int main(void){ int taille,i; for(i=0;i<TAILLETAMPON;i++) tampon[i]=EOF; f.open("exemple.ors",ios::in | ios::binary); if(f.is_open()){ f.read(tampon,TAILLEDEMITAMPON); for(i=0;c!=EOF;i++){ carSuiv(); if(c!=EOF) cout<<c; } reculer(); while(i>1){ reculer(); carSuiv(); if(c!=EOF) cout<<c; reculer(); i--; } cout<<endl; f.close(); } } void carSuiv(){ if(tampon[enAvant]==EOF) if(enAvant==SENTINELLE1){ for(int i(SENTINELLE1+1);i<TAILLETAMPON;i++) tampon[i]=EOF; f.read(tampon+SENTINELLE1+1,TAILLEDEMITAMPON); block++; enAvant++; } else if(enAvant==SENTINELLE2){ for(int i(0);i<SENTINELLE1;i++) tampon[i]=EOF; f.read(tampon,TAILLEDEMITAMPON); block++; enAvant=0; } c=tampon[enAvant++]; } void reculer(){ enAvant--; if(enAvant==-1) if(block!=0){ block--; f.seekg(block*TAILLEDEMITAMPON,ios::beg); f.read(tampon+SENTINELLE1+1,TAILLEDEMITAMPON); enAvant=SENTINELLE2-1; } else enAvant=0; else if(enAvant==SENTINELLE1){ block--; f.seekg(block*TAILLEDEMITAMPON,ios::beg); f.read(tampon,TAILLEDEMITAMPON); enAvant--; } }
Partager