How do i make fprintf print something in the end of a file?

How do i make fprintf (or any other function that can print text to textfiles) in C print something at the end of a textfile? Cant seem to make it do that. Thanks

Comments

  • Hola,

    Try using fseek
    Moves the file pointer to a specified location.
    int fseek( FILE *stream, long offset, int origin );

    example:
    FILE *fp = fopen(fname,"wb");
    fseek( fp, SEEK_END, 0);
    if(fp != NULL) {
    fwrite((void *)hdrBuf,1,hdrLen,fp);
    fflush(fp);
    fclose(fp);
    }

    More info:
    Return Value

    If successful, fseek returns 0. Otherwise, it returns a nonzero value. On devices incapable of seeking, the return value is undefined.

    Parameters

    stream

    Pointer to FILE structure

    offset

    Number of bytes from origin

    origin

    Initial position

    Remarks

    The fseek function moves the file pointer (if any) associated with stream to a new location that is offset bytes from origin. The next operation on the stream takes place at the new location. On a stream open for update, the next operation can be either a read or a write. The argument origin must be one of the following constants, defined in STDIO.H:

    SEEK_CUR

    Current position of file pointer

    SEEK_END

    End of file

    SEEK_SET

    Beginning of file



    : How do i make fprintf (or any other function that can print text to textfiles) in C print something at the end of a textfile? Cant seem to make it do that. Thanks
    :


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion