1. Weiterleitung zu NetzLiving.de
  2. Forum
    1. Unerledigte Themen
  3. zum neuen Forum
  • Anmelden
  • Suche
Dieses Thema
  • Alles
  • Dieses Thema
  • Dieses Forum
  • Seiten
  • Forum
  • Erweiterte Suche
  1. Informatik Forum
  2. Webmaster & Internet
  3. Entwicklung

Unterschied fopen(file,"rt"); fopen(file,"rb")

    • Frage
  • Kongo
  • 19. April 2004 um 11:49
  • Unerledigt
Hallo zusammen,

das Informatik-Forum geht in den Archivmodus, genaue Informationen kann man der entsprechenden Ankündigung entnehmen. Als Dankeschön für die Treue bekommt man von uns einen Gutscheincode (informatikforum30) womit man bei netzliving.de 30% auf das erste Jahr sparen kann. (Genaue Infos sind ebenfalls in der Ankündigung)

Vielen Dank für die Treue und das Verständnis!
  • Kongo
    Punkte
    295
    Beiträge
    44
    • 19. April 2004 um 11:49
    • #1

    Was sind eigentlich die Unterschiede zwischen dem translation und dem binary mode? Ein Unterschied ist, dass im translation mode die carriage return rausgeschnitten werden. Was ist da aber sonst noch anders?

  • Primenumber
    Punkte
    1.122
    Beiträge
    218
    • 19. April 2004 um 15:37
    • #2
    Zitat von Kongo

    Was sind eigentlich die Unterschiede zwischen dem translation und dem binary mode? Ein Unterschied ist, dass im translation mode die carriage return rausgeschnitten werden. Was ist da aber sonst noch anders?


    Auszug aus dem MSDN:

    t Open in text (translated) mode. In this mode, CTRL+Z is interpreted as an end-of-file character on input. In files opened for reading/writing with "a+", fopen checks for a CTRL+Z at the end of the file and removes it, if possible. This is done because using fseek and ftell to move within a file that ends with a CTRL+Z, may cause fseek to behave improperly near the end of the file. Also, in text mode, carriage return–linefeed combinations are translated into single linefeeds on input, and linefeed characters are translated to carriage return–linefeed combinations on output. When a Unicode stream-I/O function operates in text mode (the default), the source or destination stream is assumed to be a sequence of multibyte characters. Therefore, the Unicode stream-input functions convert multibyte characters to wide characters. For the same reason, the Unicode stream-output functions convert wide characters to multibyte characters.

    b Open in binary (untranslated) mode; translations involving carriage-return and linefeed characters are suppressed. If t or b is not given in mode, the default translation mode is defined by the global variable _fmode. If t or b is prefixed to the argument, the function fails and returns NULL.

    For more information about using text and binary modes in Unicode and multibyte stream-I/O, see Text and Binary Mode File I/O and Unicode Stream I/O in Text and Binary Modes.

  • Plantschkuh!
    Punkte
    6.173
    Beiträge
    1.181
    • 19. April 2004 um 15:42
    • #3
    Zitat von Kongo

    Was sind eigentlich die Unterschiede zwischen dem translation und dem binary mode?


    Es gibt keinen translation mode, es gibt einen text mode. Ein 't' im mode-string ist ein Fehler und erzeugt undefined behavior.

    Es gibt folgende mode strings (siehe hier, das ist der letze öffentliche Draft des C99-Standards):

    Zitat von n869


    r open text file for reading
    w truncate to zero length or create text file for writing
    a append; open or create text file for writing at end-of-file
    rb open binary file for reading
    wb truncate to zero length or create binary file for writing
    ab append; open or create binary file for writing at end-of-file
    r+ open text file for update (reading and writing)
    w+ truncate to zero length or create text file for update
    a+ append; open or create text file for update, writing at end-of-file
    r+b or rb+ open binary file for update (reading and writing)
    w+b or wb+ truncate to zero length or create binary file for update
    a+b or ab+ append; open or create binary file for update, writing at end-of-file

    Alles anzeigen


    Alles, was nicht in dieser Liste aufscheint, ist ein Fehler.

    Zitat von Kongo

    Ein Unterschied ist, dass im translation mode die carriage return rausgeschnitten werden. Was ist da aber sonst noch anders?


    Das kommt auf die Plattform an. Bei text-streams wird eben die Textdarstellung im File an die Konventionen von C angepaßt. Unter Unix zum Beispiel findet die Transformation, die du angesprochen hast, auch nicht statt, da gibt es keinen Unterschied zwischen Text- und Binärdateien.
    Da die gelesenen Zeichen eben nicht genau den gespeicherten entsprechen, sind fseek/ftell auf Textfiles auch eingeschränkt.

  • Primenumber
    Punkte
    1.122
    Beiträge
    218
    • 19. April 2004 um 15:44
    • #4
    Zitat von Plantschkuh!

    Es gibt keinen translation mode, es gibt einen text mode. Ein 't' im mode-string ist ein Fehler und erzeugt undefined behavior.

    Es gibt folgende mode strings (siehe hier, das ist der letze öffentliche Draft des C99-Standards)


    ich erhebe meine hand und schwöre demütig: ich zitiere nie wieder aus dem MSDN

  • Ringding
    Punkte
    1.237
    Beiträge
    244
    • 22. April 2004 um 23:31
    • #5

    Diese DOS-Perversion "rb" & co hat ihren Weg in den Standard gefunden? Immer wieder faszinierend, wie weit das Lobbying reicht...

  • Maximilian Rupp 27. Dezember 2024 um 12:06

    Hat das Thema aus dem Forum Programmieren nach Entwicklung verschoben.

  1. Datenschutzerklärung
  2. Impressum