in datei schreiben

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • in datei schreiben

    moin,


    ich möchte in eine datei schreiben, ohne das der inhalt überschrieben wird meine aktuelle version:

    for(int i=1;i<=a;i++){
    FILE *datei;
    datei = fopen ("teilnehmer.txt", "w");
    if (datei != NULL)
    {
    fprintf (datei, "%s;%s;%f\n", name ,boot[i],yards[i]);
    fclose (datei);
    }
    }

    dabei wird aber leider der inhalt immer wieder überschrieben...

    ich hoffe ihr könnt mir helfen

    gruß

    Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von casio ()

  • darthdespotism schrieb:

    Ansonsten würde ich bei dem fopen mal "w" durch "aw" ersetzen ;)



    "aw" gibts nicht
    wenn du nur anhängen willst, währe "a" sicher passend. Wenn's file nicht existiert wirds erzeugt.

    manual page von fopen sagt dazu:


    DESCRIPTION
    The fopen() function opens the file whose name is the string pointed to
    by filename and associates a stream with it.

    The argument mode points to a string beginning with one of the following
    sequences (Additional characters may follow these sequences.):

    ``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 positioned 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 writing. The file is created if it does not exist. The
    stream is positioned at the end of the file. Subsequent writes
    to the file will always end up at the then current end of file,
    irrespective of any intervening fseek(3) or similar.

    ``a+'' Open for reading and writing. The file is created if it does not
    exist. The stream is positioned at the end of the file. Subse-
    quent writes to the file will always end up at the then current
    end of file, irrespective of any intervening fseek(3) or similar.