1

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);

yamero
  • 27
  • 6

2 Answers2

1

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
wake-0
  • 3,918
  • 5
  • 28
  • 45
0

You can also use the function

int fflush(FILE *stream)

on stdin. That should do the same operation.