hi all,
i read a snippet code and found he/she used
to flush the "stdin", it works, but is it portable?fseek(stdin, 0, SEEK_END)
thanks d'avance
hi all,
i read a snippet code and found he/she used
to flush the "stdin", it works, but is it portable?fseek(stdin, 0, SEEK_END)
thanks d'avance
i guess so. it's used for seeking the streams so i guess it's ok
it's gonna seek to the bigging of stdin
The first google hit for "fseek stdin" indicates that it's not portable. http://lists.debian.org/debian-user/.../msg00389.html
I may be wrong, but I remember reading something about using freopen() to open stdin for seeking. But that's probably just because freopen()ing stdin is just like fopen()ing a file.I tried to do a fseek(stdin , 0 , SEEK_END ) under linux.
On windows and solaris this commands cleans the input stream. Under linux
I get an error message il[l]egal seek.
So, fseek()ing in stdin is probably not portable.
[edit] If all you want to do is flush stdin, read this FAQ. http://faq.cprogramming.com/cgi-bin/...&id=1043284392 [/edit]
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
The call is portable.
The effect you desire however might not be.
fseek() has too many caveats (in the ISO standard), which when you add in various operating systems, and maybe redirecting stdin from say a file or a pipe, I doubt you'll get what you want in all cases.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
thanks guys