Search code examples
cinputiobufferflush

What does the following line mean?


I was writing a program and had to handle buffers. But when I employed some loops I realized that the buffer was not being flushed after each iteration and withheld its last input value. I searched on the internet and found this code line. It works but I don't know what this means. fseek(stdin,0,SEEK_END);


Solution

  • It moves the read/write pointer to the end of the file/stream and so it needs to be flushed.

    see Tutorialspoint

    int fseek(FILE *stream, long int offset, int whence)
    

    Parameters

    stream − This is the pointer to a FILE object that identifies the stream.

    offset − This is the number of bytes to offset from whence.

    whence − This is the position from where offset is added. It is specified by one of the following constants −

    • SEEK_SET: Beginning of file
    • SEEK_CUR: Current position of the file pointer
    • SEEK_END: End of file