hi all,
i read a snippet code and found he/she used
to flush the "stdin", it works, but is it portable?Quote:
fseek(stdin, 0, SEEK_END)
thanks d'avance
Printable View
hi all,
i read a snippet code and found he/she used
to flush the "stdin", it works, but is it portable?Quote:
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.Quote:
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]
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.
thanks guys