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);
Asked
Active
Viewed 1,815 times
1

yamero
- 27
- 6
-
Similar to http://stackoverflow.com/q/4917801/2410359 – chux - Reinstate Monica Jan 15 '17 at 21:21
-
2If you did not find the documentation of `fseek` you definitively should enhance your search skills. It is the very first entry on a simple google search. If you don't understand the syntax, learning C will help. – too honest for this site Jan 15 '17 at 21:35
2 Answers
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.

Romain Artru
- 65
- 9
-
1have you read this: http://stackoverflow.com/a/18170435/6081445 - it should not be used for stdin – wake-0 Jan 15 '17 at 21:02
-
3
-
1See [Using `fflush(stdin)`](http://stackoverflow.com/questions/2979209/using-fflushstdin) for the full details — there are some contexts where it is OK, but not many. – Jonathan Leffler Jan 16 '17 at 00:00