"Mike Wahler" <mk******@mkwahler.net> writes:
"Mohan" <mo*********@gmail.com> wrote in message
news:11**********************@g10g2000cwb.googlegr oups.com... Hi Friends,
The following code is working fine and printing the string "Mohan S".
#include<stdio.h>
int main()
{
FILE *fp;
fp=stdout;
fprintf(fp,"%s","Mohan S");
}
My doubt is how it is possible to assign a standard output stream to a
file stream....
Because they have the same type. 'stdout' has
type 'FILE *'. 'stdout', 'stdin', and 'stderr'
*are* FILE* streams.
Why it didn't throw any error;
Why should it? What error do you expect?
instead its running
fine...
It should, except for one thing: The last character output
should be a '\n', or 'fflush()' should be called, or the
output isn't guaranteed to appear.
Even with fflush(), it's implementation-defined whether a stream (such
as stdout) is required to end in a newline.
It's very likely that the output will appear (though on many systems
it may be immediately overwritten), but it's not guaranteed. Just add
a '\n', and you'll be fine.
--
Keith Thompson (The_Other_Keith)
ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.