Herzlich Willkommen, lieber Gast!
  Sie befinden sich hier:

  Forum » C / C++ (ANSI-Standard) » dateien lesen und schreiben

Forum | Hilfe | Team | Links | Impressum | > Suche < | Mitglieder | Registrieren | Einloggen
  Quicklinks: MSDN-Online || STL || clib Reference Grundlagen || Literatur || E-Books || Zubehör || > F.A.Q. < || Downloads   

Autor Thread - Seiten: > 1 <
000
25.08.2004, 21:08 Uhr
prn



hi!

Ist es möglich aus einer Datei bis zu einem bestimmten Punkt zu lesen und dann ein Zeichen einzufügen oder zu überschreiben?
Lesen funktioniert bei mir und schreiben auch, aber gleichzeitig nicht.


Danke

prn
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
001
25.08.2004, 21:14 Uhr
typecast
aka loddab
(Operator)


Klar ist das moeglich. C oder C++?
--
All parts should go together without forcing. ... By all means, do not use a hammer. (IBM maintenance manual, 1925)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
002
25.08.2004, 21:22 Uhr
prn



wenn möglich c
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
003
25.08.2004, 21:34 Uhr
typecast
aka loddab
(Operator)


Wenn du in eine Datei lesen und (ueber)schreiben willst, dann oeffnest du einfach die Datei mit


C++:
FILE* fd;
fd = fopen(filename, "w+");
//oder
fd = fopen(filename, "r+");



Dann kannst du sowohl lesen als auch schreiben.
Damit wird allerdings an der Position an der sich der Filedescriptor steht gelesen oder geschrieben. Das heisst, dass nicht eingefuegt wird.

Wenn du ein einfuegen willst, dann musst du erst den Rest der Datei auslesen, irgendwo zwischenspeichern, wieder zu der Stelle springen an der du einfuegen willst und anschliessend alles (mit dem Inhalt den du einfuegen willst) wieder ausschreiben.

Eine andere Moeglichkeit faellt mir nicht ein.
--
All parts should go together without forcing. ... By all means, do not use a hammer. (IBM maintenance manual, 1925)
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
004
25.08.2004, 21:35 Uhr
typecast
aka loddab
(Operator)


Btw: Hier mal die Optionen von fopen (aus der man-page):

Code:
r      Open text file for reading.  The stream is positioned at the beginning of the file.

r+     Open for reading and writing.  The stream is positioned at the beginning of the file.

w      Truncate file to zero length or create text file for writing.  The  stream  is  posi-
        tioned at the beginning of the file.

w+     Open for reading and writing.  The file is created if it does not exist, otherwise it
         is truncated.  The stream is positioned at the beginning of the file.

a      Open for appending (writing at end of file).  The file is  created  if  it  does  not
        exist.  The stream is positioned at the end of the file.

a+     Open  for  reading and appending (writing at end of file).  The file is created if it
         does not exist.  The stream is positioned at the end of the file.


--
All parts should go together without forcing. ... By all means, do not use a hammer. (IBM maintenance manual, 1925)

Dieser Post wurde am 25.08.2004 um 21:36 Uhr von typecast editiert.
 
Profil || Private Message || Suche Download || Zitatantwort || Editieren || Löschen || IP
Seiten: > 1 <     [ C / C++ (ANSI-Standard) ]  


ThWBoard 2.73 FloSoft-Edition
© by Paul Baecher & Felix Gonschorek (www.thwboard.de)

Anpassungen des Forums
© by Flo-Soft (www.flo-soft.de)

Sie sind Besucher: