Writing directly to monitor without buffering - Implementation 
Author Message
 Writing directly to monitor without buffering - Implementation

My code is ANSI C89-90 compliant.

Almost always, all streams are buffered except stderr which is unbuffered.
The buffered streams are more effective than the unbuffered one. So, a
buffered stdout has more fast overall output on screen from an unbuffered
stdout or stderr. But if you want to write directly on screen without
buffering for reasons you only know, here is the code:

a)

#include <stdio.h>

int main()
{
setbuf(stdio, 0);
...
return 0;

Quote:
}

setbuf(stdio ,0) must be used before any other use of stdio, preferably in
the beginning of main().

b) Second way, usage of stderr.

You can use all the file functions on stderr.

E.g..:
fprintf(stderr, "message");
fprintf(stderr, "%s", string);
fputs(string, stderr);

where string is char string[] or *string.



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation
On Wed, 26 Jul 2000 13:35:32 +0300, that hoopy frood Ioannis Vranos
scribbled the following:

Quote:
>My code is ANSI C89-90 compliant.

>Almost always, all streams are buffered except stderr which is unbuffered.
>The buffered streams are more effective than the unbuffered one.

I assume you mean "more efficient."

Quote:
> So, a
>buffered stdout has more fast overall output on screen from an unbuffered
>stdout or stderr. But if you want to write directly on screen without
>buffering for reasons you only know, here is the code:

C has no concept of a screen.

Quote:

>a)

>#include <stdio.h>

>int main()
>{
>setbuf(stdio, 0);
>...
>return 0;
>}

>setbuf(stdio ,0) must be used before any other use of stdio, preferably in
>the beginning of main().

>b) Second way, usage of stderr.

[snip]

Or you could just flush the buffer with fflush().

Note, of course, that avoiding the buffer with any of these methods
does not mean that the output will be displayed to any sort of screen.
The data is merely passed to the environment, which may do whatever it
likes with it.

--
Chris Mears
ICQ: 36697123
C-FAQ: http://www.eskimo.com/~scs/C-faq/top.html



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation
I am talking about today's pcs found in everybody's home or office. And i
wrote this code for people who want to write directly on screen. Back in
pdps stdout was something like a typewriter (they had not monitors). We can
analyze where stdout can lead to, but this was not my intention. :)


Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation

Quote:

> My code is ANSI C89-90 compliant.

That remains to be seen ;-)

Quote:
> Almost always, all streams are buffered except stderr which is unbuffered.

No.  stderr might be unbuffered, but it can also be
line-buffered.  stdout and stdin are fully buffered only if they
do not refer to "interactive devices"; in my experience this is
much less often than "almost always".

Quote:
> #include <stdio.h>

> int main()
> {
> setbuf(stdio, 0);

`stdio': unknown identifier.

Quote:
> ...
> return 0;
> }

--
"What is appropriate for the master is not appropriate for the novice.
 You must understand the Tao before transcending structure."
--The Tao of Programming


Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation


Quote:
> My code is ANSI C89-90 compliant.

> Almost always, all streams are buffered except stderr which is unbuffered.
> The buffered streams are more effective than the unbuffered one. So, a
> buffered stdout has more fast overall output on screen from an unbuffered
> stdout or stderr. But if you want to write directly on screen without
> buffering for reasons you only know, here is the code:

> a)

> #include <stdio.h>

> int main()
> {
> setbuf(stdio, 0);

setbuf(stdout,0);

Quote:
> ...
> return 0;
> }

> setbuf(stdio ,0) must be used before any other use of stdio, preferably in
> the beginning of main().

setbuf(stdout, 0);
Quote:

> b) Second way, usage of stderr.

> You can use all the file functions on stderr.

> E.g..:
> fprintf(stderr, "message");
> fprintf(stderr, "%s", string);
> fputs(string, stderr);

> where string is char string[] or *string.



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation

Quote:

> I am talking about today's pcs found in everybody's home or office.

This seems an odd thing to discuss in comp.lang.c.

Quote:
> And i wrote this code for people who want to write directly on screen.

Then you're in the wrong newsgroup. C has no concept of a screen. The
closest it comes to it is an "interactive device".

Quote:
> Back in
> pdps stdout was something like a typewriter (they had not monitors). We can
> analyze where stdout can lead to, but this was not my intention. :)

It seems to me that your intention is to restrict such advice as you can
give to one or two particular platforms. C is a portable language if
used carefully - portable not just between Windows and Unix, but between
just about anything and almost everything. My KVM almost certainly
contains code written in C; its output device comprises just eight
little lights and an occasional beep. No screen. I'm sure I could come
up with plenty more examples, like washing machines and so on, but I
hope the point is made...

--

Richard Heathfield

"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.

C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
58 K&R Answers: http://users.powernet.co.uk/eton/kandr2/index.html (39
to go)



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation

Quote:
>I am talking about today's pcs found in everybody's home or office. And i
>wrote this code for people who want to write directly on screen. Back in
>pdps stdout was something like a typewriter (they had not monitors). We can
>analyze where stdout can lead to, but this was not my intention. :)

I am sorry, but there is no screen on the telecom equipments I work for,
just some keys, LED's and of course some digital interfaces. No screen at
all. My code is 95% ANSI, (but I have no stdout at all on this
implementation)

--
-hs-    Tabs out, spaces in.
CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
ISO-C Library: http://www.dinkum.com/htm_cl
FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc
C-tips: http://jackklein.home.att.net



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation

Quote:

> I am sorry, i did not read anywhere we must speak and write only ANSI C in
> here. Am i wrong?

Yes.  This newsgroup is concerned only with the ANSI C language.
--
"Large amounts of money tend to quench any scruples I might be having."
  -- Stephan Wilms


Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation

Quote:

> My own observations of what is considered topical by the majority of
> regular posters here:

[...]
> 4) Topicality discussions (sigh)
> 5) Hairspray and rats (for reasons best known to Kaz and Dann)
> 6) Donald E Knuth
> 7) DEC tapes :-)

Say, does anyone know whether it would be topical to discuss
whether Donald Knuth uses DEC tapes to back up articles about
hairspray for rats?
--
"Large amounts of money tend to quench any scruples I might be having."
  -- Stephan Wilms


Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation


Quote:

>My own observations of what is considered topical by the majority of
>regular posters here:

>1) ISO C (known to many as ANSI C, for acceptable historical reasons) -
>C99
>2) ISO C90 / ANSI C89
>3) K&R C (again, for acceptable historical reasons)
>4) Topicality discussions (sigh)

I hope this post falls under this category, since otherwise it'd be
hopelessly off-topic.

Quote:
>5) Hairspray and rats (for reasons best known to Kaz and Dann)

Don't forget glass cleaner.

Quote:
>6) Donald E Knuth
>7) DEC tapes :-)

Without fighting with Deja to dig up your last comment on the subject,
I seem to recall that you claimed they *weren't* on-topic; have you
changed your mind?  Or are you just trying to summarize majority
opinion here?  ;)

dave

--
Dave Vandervies

Ambition is a poor excuse for not having enough sense to be lazy.



Sun, 12 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation
I am sorry, i did not read anywhere we must speak and write only ANSI C in
here. Am i wrong?


Quote:

> >I am talking about today's pcs found in everybody's home or office. And i
> >wrote this code for people who want to write directly on screen. Back in
> >pdps stdout was something like a typewriter (they had not monitors). We
can
> >analyze where stdout can lead to, but this was not my intention. :)

> I am sorry, but there is no screen on the telecom equipments I work for,
> just some keys, LED's and of course some digital interfaces. No screen at
> all. My code is 95% ANSI, (but I have no stdout at all on this
> implementation)

> --
> -hs-    Tabs out, spaces in.
> CLC-FAQ: http://www.eskimo.com/~scs/C-faq/top.html
> ISO-C Library: http://www.dinkum.com/htm_cl
> FAQ de FCLC : http://www.isty-info.uvsq.fr/~rumeau/fclc
> C-tips: http://jackklein.home.att.net



Mon, 13 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation
Second thought. Here i was talking ANSI compatible. I mentioned monitor
because i was refering to the most who happen to have monitors assigned to
stdout. :)) And please do not tell me about redirection. I jsut wrote some
code, that's all. :)


Mon, 13 Jan 2003 03:00:00 GMT  
 Writing directly to monitor without buffering - Implementation
Read my code, it is ansi


Quote:

> > I am sorry, i did not read anywhere we must speak and write only ANSI C
in
> > here. Am i wrong?

> Yes.  This newsgroup is concerned only with the ANSI C language.
> --
> "Large amounts of money tend to quench any scruples I might be having."
>   -- Stephan Wilms



Mon, 13 Jan 2003 03:00:00 GMT  
 
 [ 26 post ]  Go to page: [1] [2]

 Relevant Pages 

1. convert memory buffer directly to FILE * without using fopen()

2. Writing into file without buffering?

3. Drawing directly into a buffer using a device context

4. Display DIB directly from video buffers using SDI

5. How to programm hardware directly without using assembler?

6. how to create a GUID directly in a program without using GUIDGEN

7. CString buffer length - how to increase and monitor?

8. Is it possible to access Visual FoxPro5.0 tables directly from VC++ MFC(without using ODBC)

9. Writing directly to an IDE device with Win2K

10. Writing to the screen base directly.

11. how can i read/write to disk directly?

12. Writing directly to/from a harddrive w/ C?C++

 

 
Powered by phpBB® Forum Software