472,107 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

fpurge()

Can someone please show me an example of how fpurge might be used? Does
anyone use this function anymore and is it anything like fflush() ?

Bill
Oct 13 '08 #1
12 17285
Bill Cunningham wrote:
Can someone please show me an example of how fpurge might be used? Does
anyone use this function anymore and is it anything like fflush() ?
fpurge is not in the standard C library. It is nonstandard and not
portable. It is a BSD function. The similar _fpurge is a Solaris
function, available in some versions of glibc. Any questions about them
belong, therefore, in a forum for BSD or Solaris or GNU.
Oct 13 '08 #2
"Bill Cunningham" <no****@nspam.invalidwrites:
Can someone please show me an example of how fpurge might be used? Does
anyone use this function anymore and is it anything like fflush() ?
No. fpurge is non-standard (it's not even POSIX) and extremely
non-portable; even on systems that support it, it's not recommended.

Did you read the man page before posting? If so, didn't it tell you
this? If not, why?

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 13 '08 #3
On 13 Oct 2008 at 1:51, Bill Cunningham wrote:
Can someone please show me an example of how fpurge might be used?
Does anyone use this function anymore and is it anything like
fflush() ?
Here's the description from the manpage:

<quote>
The function fpurge() clears the buffers of the given stream. For
output streams this discards any unwritten output. For input streams
this discards any input read from the underlying object but not yet
obtained via getc(3); this includes any text pushed back via
ungetc(3).
</quote>

IME, use of this function is rare. Here's an example of a function where
it comes in useful for dealing with line-buffered input from a terminal:
int getyesno(const char *prompt)
{
int ch;

for (;;) {
fpurge(stdin);
printf("%s?\n", prompt);
ch = toupper(getchar());
switch (ch) {
case 'N':
case EOF:
return 0;
case 'Y':
return 1;
default:
printf("'%c' is not a valid answer: enter 'Y' or 'N'\n", ch);
continue;
}
}
}

Oct 13 '08 #4
In article <gc**********@registered.motzarella.org>,
Martin Ambuhl <ma*****@earthlink.netwrote his usual blather, so I've
edited it for content:
>Bill Cunningham wrote:
> Can someone please show me an example of how fpurge might be used? Does
anyone use this function anymore and is it anything like fflush() ?
>Someone can, but I can't, because I am a clueless fool.
Hope that clarifies things.

Oct 13 '08 #5

"Martin Ambuhl" <ma*****@earthlink.netwrote in message
news:gc**********@registered.motzarella.org...
fpurge is not in the standard C library. It is nonstandard and not
portable. It is a BSD function. The similar _fpurge is a Solaris
function, available in some versions of glibc. Any questions about them
belong, therefore, in a forum for BSD or Solaris or GNU.
Oh I was looking online thought it was with the standard library Sorry.
I'll check where appropriate.

Bill
Oct 13 '08 #6

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
No. fpurge is non-standard (it's not even POSIX) and extremely
non-portable; even on systems that support it, it's not recommended.

Did you read the man page before posting? If so, didn't it tell you
this? If not, why?
Look at this Keith this is where I got this. They better correct their
info. And they show good examples at times.

http://www.cppreference.com/wiki/c/io/start
Oct 13 '08 #7
"Bill Cunningham" <no****@nspam.invalidwrites:
"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
>No. fpurge is non-standard (it's not even POSIX) and extremely
non-portable; even on systems that support it, it's not recommended.

Did you read the man page before posting? If so, didn't it tell you
this? If not, why?

Look at this Keith this is where I got this. They better correct their
info. And they show good examples at times.

http://www.cppreference.com/wiki/c/io/start
That web page is a wiki. I just deleted the reference to fpurge. I
also added a note to the fpurge page itself (which is no longer in the
index, but the page still exists).

The fact that I was able to do so, without even setting up an account,
suggests that it's not a reliable source of information. I could just
as easily have deleted correct information or added deliberate
misinformation.

I think I've mentioned K&R2 to you many many times.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Oct 13 '08 #8

"Keith Thompson" <ks***@mib.orgwrote in message
news:ln************@nuthaus.mib.org...
That web page is a wiki. I just deleted the reference to fpurge. I
also added a note to the fpurge page itself (which is no longer in the
index, but the page still exists).

The fact that I was able to do so, without even setting up an account,
suggests that it's not a reliable source of information. I could just
as easily have deleted correct information or added deliberate
misinformation.

I think I've mentioned K&R2 to you many many times.
It's helpful at times. At times the depth of info blasts me.

Bill
Oct 13 '08 #9
"Bill Cunningham" <no****@nspam.invalidwrites:
"Keith Thompson" <ks***@mib.orgwrote:
>I think I've mentioned K&R2 to you many many times.

It's helpful at times. At times the depth of info blasts me.
Unlike many of the other sources of information you seem to be using,
K&R2 does _not_ contain [too much] stuff that's Just Wrong.

Bill, if you want to use a function, look it up in K&R2 first.
If it's not there, don't use it.

mlp
Oct 14 '08 #10

"Mark L Pappin" <ml*@acm.orgwrote in message
"Bill Cunningham" <no****@nspam.invalidwrites:
Bill, if you want to use a function, look it up in K&R2 first.
If it's not there, don't use it.
If it's not in K and R it isn't in the standard library. However that
doesn't mean you should never use non-standard functions. In fact, some
common tasks, such as listing the files in a directory, can't be done
without going outside the confines of the standard.
However if you use a non-standard fucntion, be aware that it won't be
portable to all systems. In fact between them Windows and Unix manage to
break most non-conservative programs.

--
Free games and programming goodies.
http://www.personal.leeds.ac.uk/~bgy1mm

Oct 14 '08 #11
On 14 Oct 2008 at 19:08, Malcolm McLean wrote:
"Mark L Pappin" <ml*@acm.orgwrote in message
>Bill, if you want to use a function, look it up in K&R2 first.
If it's not there, don't use it.
If it's not in K and R it isn't in the standard library.
This is not true. There are plenty of functions in the standard library
of the CURRENT standard that aren't mentioned in K&R. They may not be
Heathfield-approved since they're post-C90, but indisputably they're in
the standard library.

This K&R acid test is particularly amusing when you remember that
Section 8.3 of K&R2 is entitled "Open, creat, close, unlink". According
to the dogma of most of the regulars, these functions are "not C" and
"off-topic" for this group.
However that doesn't mean you should never use non-standard functions.
Absolutely right.

Oct 14 '08 #12
Malcolm McLean said:
>
"Mark L Pappin" <ml*@acm.orgwrote in message
>"Bill Cunningham" <no****@nspam.invalidwrites:
Bill, if you want to use a function, look it up in K&R2 first.
If it's not there, don't use it.
If it's not in K and R it isn't in the standard library.
Counter-example: strcoll (and it isn't the only one).

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
Oct 14 '08 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

30 posts views Thread by Jonathan Neill | last post: by
18 posts views Thread by JG | last post: by
232 posts views Thread by robert maas, see http://tinyurl.com/uh3t | last post: by
15 posts views Thread by Eoghan | last post: by
reply views Thread by leo001 | last post: by

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.