473,511 Members | 15,818 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

program doesn't "seem" to print "hello-out"

The following program doesn't "seem" to print "hello-out". (Try
executing it)

#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
What could be the reason?

Aug 25 '06 #1
16 4159
saurabhnsit2001 wrote:
The following program doesn't "seem" to print "hello-out". (Try
executing it)

#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}
What could be the reason?
if you add a line
fflush(stdout);

in the while loop , you will find out what really happenen.
Aug 25 '06 #2
output to stderr goes out ASAP, output to stdout is often buffered up.
If you wait long enough you'll see the output appear.

Aug 25 '06 #3
saurabhnsit2001 wrote:
>
The following program doesn't "seem" to print "hello-out". (Try
executing it)

#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}

What could be the reason?
Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
function, in standard C (which is the subject of discussion here).
If you eliminate those things, resulting in:

#include <stdio.h>

int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}

there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout). stderr
is unbuffered, so it's output will probably appear. Terminate the
strings with '\n'.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Aug 25 '06 #4
In article <44***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
....
>Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng.

Aug 25 '06 #5

Kenny McCormack is a troll; do not respond to him/her. He/she only posts here
as a form of pathetic self-affirmation.

The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.

Information on trolls: http://members.aol.com/intwg/trolls.htm

--

Frederick Gotham
Aug 25 '06 #6
Frederick Gotham wrote:
Kenny McCormack is a troll; do not respond to him/her. He/she only posts here
as a form of pathetic self-affirmation.

The only way to deal with trolls is to limit your reaction to reminding
others not to respond to trolls.
This _is_ bending the rules a bit, isn't it?

I prefer the "high-jack the thread for your own off-topic nonsense"
tactic, myself.

Hmmm. I have no off-topic nonsense to add. Unless this is it.

Yup. That's all I got.
Aug 25 '06 #7

CBFalconer wrote:
#include <stdio.h>

int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}

there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout).
Well, that's an interesting answer. If it were true, that would
require every implementation of fprintf to by default allocate an
infinitely large output buffer, and every computer out there to have
infinite memory.

Or have an intelligent fprintf that could recognize repeated patterns
in what's passed to it and compress the output buffer on the fly.
Just 128 bits of repeat count would be enough for most purposes.

Hey! That's (to me) a new, and somewhat useful idea!. Think of all
the logging code that prints out humdrum, mostly repeated strings!

Out of the mouths of .......

stderr
is unbuffered, so it's output will probably appear. Terminate the
strings with '\n'.

--
Some informative links:
news:news.announce.newusers
http://www.geocities.com/nnqweb/
http://www.catb.org/~esr/faqs/smart-questions.html
http://www.caliburn.nl/topposting.html
http://www.netmeister.org/news/learn2quote.html
Aug 26 '06 #8
"Ancient_Hacker" <gr**@comcast.netwrites:
CBFalconer wrote:
>#include <stdio.h>

int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}

there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout).

Well, that's an interesting answer. If it were true, that would
require every implementation of fprintf to by default allocate an
infinitely large output buffer, and every computer out there to have
infinite memory.
No, it just allows such an implementation. It doesn't require
it. Furthermore, an implementation is not required to support
text files with lines longer than 254 characters, including the
terminating new-line character.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman
Aug 26 '06 #9
Kenny McCormack wrote:
In article <44***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
...
>>Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep

Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng.
Frederick Gotham wrote:
Kenny McCormack is a troll; do not respond to him/her. He/she only
posts here as a form of pathetic self-affirmation.
I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files and can link
to library routines, it just doesn't define them, so "needn't" is more
precise. Although the original post didn't define what these
non-ISO-9899 standard header and routine do, you could make an
intelligent guess. ;-)

This newsgroup revels in pedantry, so Kenny's non-abusive and, IMO,
accurate post certainly fits in.

--
Thad
Aug 26 '06 #10
On Sat, 26 Aug 2006 17:04:42 -0600, in comp.lang.c , Thad Smith
<Th*******@acm.orgwrote:
>I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files and can link
to library routines, it just doesn't define them, so "needn't" is more
precise.
Strictly speaking the original quote was correct, and Kenny was wrong.
The header was nonstandard.
The header wasn't included in the post.
So the compiler cannot find it, and must issue a diagnostic and stop.
>This newsgroup revels in pedantry, so Kenny's non-abusive and, IMO,
accurate post certainly fits in.
Although it was wrong... :-)

--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 26 '06 #11
Mark McIntyre wrote:
On Sat, 26 Aug 2006 17:04:42 -0600, in comp.lang.c , Thad Smith
<Th*******@acm.orgwrote:
I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files and can link
to library routines, it just doesn't define them, so "needn't" is more
precise.

Strictly speaking the original quote was correct, and Kenny was wrong.
Strictly speaking the original quote was wrong, and Kenny was correct.
The header was nonstandard.
Yes.
The header wasn't included in the post.
Yes.
So the compiler cannot find it,
No. An implementation is permitted to provide it, and if it does, the
compiler /can/ find it.
and must issue a diagnostic and stop.
Aug 26 '06 #12

"CBFalconer" <cb********@yahoo.com??????:44***************@yaho o.com...
saurabhnsit2001 wrote:
>>
The following program doesn't "seem" to print "hello-out". (Try
executing it)

#include <stdio.h>
#include <unistd.h>
int main()
{
while(1)
{
fprintf(stdout,"hello-out");
fprintf(stderr,"hello-err");
sleep(1);
}
return 0;
}

What could be the reason?

Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
function, in standard C (which is the subject of discussion here).
If you eliminate those things, resulting in:

#include <stdio.h>

int main(void)
{
while(1) {
fprintf(stdout, "hello-out");
fprintf(stderr, "hello-err");
}
return 0;
}

there is never any reason for any output to appear, due to the lack
of any '\n' in the output nor any calls to fflush(stdout). stderr
is unbuffered, so it's output will probably appear. Terminate the
strings with '\n'.
No, the output is appeared. After running the code without "sleep" function,
I got a full screen of interlaced "hello-out" and "hello-err".
Aug 27 '06 #13
[snips]

On Sat, 26 Aug 2006 04:41:39 -0700, Ancient_Hacker wrote:
>there is never any reason for any output to appear, due to the lack of
any '\n' in the output nor any calls to fflush(stdout).

Well, that's an interesting answer. If it were true, that would require
every implementation of fprintf to by default allocate an infinitely large
output buffer, and every computer out there to have infinite memory.
You neglect many options. Not least of which is a system that monitors
output and blocks apparent runaway applications from flooding the system
with pointless crud.
Aug 27 '06 #14

Kelsey Bjarnason wrote:
[snips]

On Sat, 26 Aug 2006 04:41:39 -0700, Ancient_Hacker wrote:
there is never any reason for any output to appear, due to the lack of
any '\n' in the output nor any calls to fflush(stdout).
Well, that's an interesting answer. If it were true, that would require
every implementation of fprintf to by default allocate an infinitely large
output buffer, and every computer out there to have infinite memory.

You neglect many options. Not least of which is a system that monitors
output and blocks apparent runaway applications from flooding the system
with pointless crud.
That would be a good thing. But one suspects that it's a hard AI
problem to tell with any degree of certainty whether a program is
printing crud. Plenty of programs might have good reasons to
occasionally write out large amounts of repeating stuff.

Aug 27 '06 #15
On 26 Aug 2006 15:58:58 -0700, in comp.lang.c , "Harald van D?k"
<tr*****@gmail.comwrote:
>
>The header was nonstandard.

Yes.
>The header wasn't included in the post.

Yes.
>So the compiler cannot find it,

No. An implementation is permitted to provide it, and if it does, the
compiler /can/ find it.
You're wrong but I really can't be bothered to explain why. Just think
"Standard" for a couple of minutes and see if it filters through.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Aug 27 '06 #16
Thad Smith <Th*******@acm.orgwrote:
Kenny McCormack wrote:
In article <44***************@yahoo.com>,
CBFalconer <cb********@maineline.netwrote:
...
>Probably the fact that it shouldn't even compile on a standard C
compiler. There is no such thing as <unistd.h>, nor a sleep
Now, that's just bogus. I suppose it could be said to be pedantically
correct if you replace "shouldn't" with "needn't". Pedantically
correct, but useless, of course, like most of the dreck posted to this ng.

Frederick Gotham wrote:
Kenny McCormack is a troll; do not respond to him/her. He/she only
posts here as a form of pathetic self-affirmation.

I don't know about Kenny's other posts, but his point above is
legitimate. Standard C accepts non-standard header files
Yes. However, ISO C doesn't guarantee that headers specified with <are
files at all. If it had been "unistd.h", he'd have had a point.

Richard
Aug 28 '06 #17

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

Similar topics

12
6352
by: zhi | last post by:
Really confused, when I use keyword style argument as following: >>> input(prompt="hello") Traceback (most recent call last): File "<pyshell#52>", line 1, in -toplevel- input(prompt="hello")...
1
1952
by: Philippe C. Martin | last post by:
Hi, I just got the pywin32 "hello world" COM server to install and I did manage to use it from VB 6.0. However, there are some glitches I do not comprehend: 1) at one point I got a python...
0
1319
by: chris | last post by:
Hello, I have been reading the c++ standard recently, in particular the part about input iterators. I note that given an input iterator a for type T, then *a only has to be "convertable to T",...
13
2467
by: Hans | last post by:
Hello, Thanks for all your response on my question about signed/unsigned chars. The problem is this: I want to use the char array for a ArrayLookup, so I need to convert char to unsigned int....
5
1869
by: Jim Bancroft | last post by:
New to ASP.Net over here, so apologies if this is a basic question-- I'm using VB .Net to build a managed dll, which I then use in some aspx files. Works fine, except every time I recompile I...
4
3863
by: kiln | last post by:
I have a simple simple ws that runs fine locally. I'd like to put it up on a public asp.net website as a test. All of the examples seem to stop describing the creation of a bare bones ws with a...
51
4055
by: Spidey | last post by:
for(;0;) printf("hello"); even the condition s wrong i get a hello printed on the screen y s this happening
0
1588
by: ytterbius | last post by:
Hello All, I'm trying to become more Google-friendly, which involves adding the "rel = "nofollow"" attribute to many of my outgoing links. I can't seem to find instructions on how to do this,...
3
2380
by: Miki | last post by:
Hello, Tk.lift doesn't seem to work on OSX (Python 2.5.1). The below starts OK, but the window is the behind all other windows. from Tkinter import * root = Tk() Button(root, text="OK",...
49
2842
by: aarklon | last post by:
Hi all, See:- http://www.cs.princeton.edu/introcs/faq/c2java.html for C vs Java in number crunching http://husnusensoy.blogspot.com/2006/06/c-vs-java-in-number-crunching.html
0
7252
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7153
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7432
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7093
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7517
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5676
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3230
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3218
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
791
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.