fseek
-
hi,
fseek(f, 0, SEEK_END); retval2 = fseek(f, 1, SEEK_CUR); warum ist retval2 != -1? ich gehe ja uebers file raus...
-
cpp1 schrieb:
warum ist retval2 != -1? ich gehe ja uebers file raus...
http://www.linuxinfor.com/german/man3/fseek.html
Was sagt ftell?
Vielleicht ein Zeilenumbruch drin oder mit welcher Option wurde die Datei geöffnet... Denke daran das auch ein Append möglich ist.Greetz
-
ftell sagt das ich 1 byte ueber der filesize bin!
die datei wurde mit "rb" geoeffnet!
retval2 = fseek(f, 4, SEEK_CUR);
mache bekomme ich auch keinen error! hmmmmmm
-
cpp1 schrieb:
ftell sagt das ich 1 byte ueber der filesize bin!
die datei wurde mit "rb" geoeffnet!
retval2 = fseek(f, 4, SEEK_CUR);
mache bekomme ich auch keinen error! hmmmmmm
Auf welchem OS arbeitest du?
Wenn du auf Windows bist wird 2 auch noch funktionieren und 3 nicht mehr
Wenn du auf Unix (bei Linux - keine Ahnung) bist wird nur nur 1 funktionieren.Liegt am Zeilenede... die Datei hat doch mehere Zeilen oder?
-
bin auf winxp!
das file ist ein .mpg file mit mehr als 20mb! da ist mir das zeilenende mal egal wenn ich es binary lesend oeffne...hmmm
-
cpp1 schrieb:
bin auf winxp!
das file ist ein .mpg file mit mehr als 20mb! da ist mir das zeilenende mal egal wenn ich es binary lesend oeffne...hmmm
Args sorry... das mit dem Binär öffnen habe ich überlesen...
Naja dann ist es eigentlich wie es der ANSI Standard beschreibt:
ISO/IEC 9899:1999
7.19.3
Setting the file position indicator to end-of-file, as with fseek(file, 0, SEEK_END), has undefined behavior for a binary stream (because of possible trailing null characters) or for any stream with state-dependent encoding that does not assuredly end in the initial shift state.ISO/IEC 9899:1999 (E), 7.19.3, #9, Fußnote 225
A binary stream need not meaningfully support fseek calls with a whence value of SEEK_END.
ISO/IEC 9899:1999 (E), 7.19.9.2, #3
Data read in from a binary stream shall compare equal to the data that were earlier written out to that stream, under the same implementation. Such a stream may, however, have an implementation-defined number of null characters appended to the end of the stream.
ISO/IEC 9899:1999 (E), 7.19.2, #3
Du Pöser, pöser du
-
ich habe die datei jetzt als textdatei geoeffnet!
[cpp]
fseek(f, 0, SEEK_END);
retval2 = fseek(f, 30, SEEK_CUR);
[/code]warum ist hier dann retval2 nicht -1?
-
cpp1 schrieb:
warum ist hier dann retval2 nicht -1?
Weil fseek das EOF Flag, das mit dem Stream verbunden ist "löscht".
http://www.cppreference.com/stdio/fseek.html
Auch wenn du nicht hinter "EOF" positionierst wird das EOF des Streams gelöscht.
Ich zitiere auch mal wieder den ANSI Standard:C99 7.19.9.2p5:
After determining the new position, a successful call to the fseek function undoes any effects of the ungetc function on the stream, clears the end-of-file indicator for the stream, and then establishes the new position.Ich glaube so langsam kommen wir dahin, wo du hinwillst
Um trotzdem noch zu EOF zu kommen, kannst du dich am Anfang einmal ans Ende positionieren und dir den Wert in einer Variabel merken (ftell) oder du arbeitest mit fstat().Ich hoffe jetzt ist es klarer
Btw. wenn dich der Standard mal interessiert... hier gibts ihn:
http://www.open-std.org/JTC1/SC22/WG14/Greetz