473,246 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

In fflush(stdin), what happens to flushed data?

hugo 27, Oct 9, 2004

Ref Docs: c.l.c FAQ article 12.26 .
www.digitalmars.com sitemap.stdio.fflush

Reading these Docs I understand that fflush does not
summarily destroy or discard the flushed data.
But it is not clear, in the case of fflush(stdin),
where stdin is default C keyboard buffer, what
actually becomes of the data.
Is there a way to capture it?

fflush( ) returns an int as status report, so one
cannot assign fflush's return to char str[20], for
insatance. Does this function take a second argument?
like fflush(stdin, str);
?
hugo
Nov 14 '05 #1
5 8975

"hugo27" <ob****@yahoo.com> wrote

But it is not clear, in the case of fflush(stdin),
where stdin is default C keyboard buffer, what
actually becomes of the data.
Is there a way to capture it?

You flush a toilet (out) not a tap (in).

fflush(stdin) is an error in ANSI C. The implementation can treat it anyhow,
including irreversibly losing the contents of the input buffer.
Nov 14 '05 #2
On 9 Oct 2004 13:47:46 -0700, in comp.lang.c , ob****@yahoo.com (hugo27)
wrote:
But it is not clear, in the case of fflush(stdin),
where stdin is default C keyboard buffer, what
actually becomes of the data.
You can't fflush(stdin) so the question is meaningless. See 12.26 of the
FAQ.
Is there a way to capture it?
Yes. Don't try to flush the stream, but instead read the stream, storing
the data, till you have emptied it.
fflush( ) returns an int as status report, so one
cannot assign fflush's return to char str[20],
Well, no, for fflush forces anything in the stream to be written. How would
it be meaningful to return the data?
Does this function take a second argument?
like fflush(stdin, str);


The question makes no sense as you can't flush input streams and anyway
fflush() forces the data to be written to the stream. Since you put the
data in teh stream, you have no need for a copy....

--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>
----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 14 '05 #3
[snips]

On Sat, 09 Oct 2004 13:47:46 -0700, hugo27 wrote:
But it is not clear, in the case of fflush(stdin),
where stdin is default C keyboard buffer, what
actually becomes of the data.


Since fflush is defined only for output streams, and stdin is an input
stream, fflush(stdin) is undefined behaviour. Thus, to answer your
question, "what actually becomes of the data?" the answer is: anything
whatsoever can happen to it.
Nov 14 '05 #4
In some situations, stdin refers to the same file as stdout or stderr,
so you could end up flushing these (no real harm done).

Eg. On linux console, by default: stdin, stdout and stderr all refer
to the current console.

Although I don't know much about the standards, I'm guessing undefined
behaviour here. If stdin refers to a file that can be written to, you
would flush whatever has been to this file. If stdin is input-only
(you have to assume this to be portable), then its undefined
behaviour.

Hope this clarifys things,
Paul Barker
Nov 14 '05 #5
In article <news:2b*************************@posting.google.c om>
Paul Barker <pa***********@hotmail.com> wrote:
Eg. On linux console, by default: stdin, stdout and stderr all refer
to the current console.
But it will not matter there, because:
Although I don't know much about the standards, I'm guessing undefined
behaviour here.
The C standard leaves it undefined. This allows other systems to
impose behavior upon it, if they choose.

The POSIX standard says that fflush() on an input-mode stream has
the effect of synchronizing the lseek() offset on the underlying
file descriptor (which only matters for regular files, not devices),
without doing any other "flushing". A call to fflush(stdin) must
therefore NOT discard ANY data.
If stdin refers to a file that can be written to, you
would flush whatever has been to this file.


This is not right (but not wrong either, it just makes no sense at
all): the fflush() operation will inspect the stdio stream, see
that the stream is in "read" mode, and lseek() the underlying file
descriptor, which may or may not be shared with other processes'
file descriptor(s) for the same underlying file. (The only reason
to do this kind of lseek() call is if it *is* in fact shared,
in particular after a POSIX fork().) The call will not even attempt
to find other stdio streams that might refer to the same file,
especially since they are most likely to be inside another process
entirely, and thus unreachable.
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Jonathan Neill | last post by:
I'm aware that there is no ANSI (or POSIX, or any standard, to my knowledge) way of flushing stdin or any other application-level input buffer, but if anyone knows a hack or a non-portable way to...
2
by: gc | last post by:
I was having trouble getting fgets to read a string from stdin, it was reading a '\n' already in the buffer. Someone told me to rewind stdin before calling fgets. It works, but is it permissible?
6
by: Charlie Zender | last post by:
Hi, I have a program which takes the output filename argument from stdin. Once the program knows the output filename, it tries to open it. If the output file exists, the program asks the user to...
11
by: Darklight | last post by:
is this correct or incorrect i just read the post below before posting this: In fflush(stdin), what happens to flushed data? this program is taken from sams teach yourself c in 21 days /*...
16
by: Chad | last post by:
How do I set the value of a = 3 in the following lines of code? #include <stdio.h> struct letter{ char a; }; struct add { struct letter addit;
5
by: Jack | last post by:
Why fflush in the following code does not work? #include <stdio.h> int main() { int n; char string; for ( n=0 ; n<12 ; n++ ) { printf( "Enter some words: " );
8
by: Jim Showalter | last post by:
I use getchar() to get the user's menu choice. One of the choices is to enter strings of information, for which I use fgets(str, 21, stdin). But when it's called, fgets() gets a null string. ...
0
by: Oliver Bleckmann | last post by:
hey guys, i have a little problem. my cgi routines are working so far, but i need to redirect to the cgi-programm and what the "posted" data to be cleared if redirected. i don't know how the post...
14
by: asit | last post by:
please fix the bugs...?? #include <stdio.h> int main() { int i; char j; printf("Enter any number ...(1 or 2) : "); scanf("%d",&i);
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.