Re: How it works?




"Mohan" <mohan.smvec@xxxxxxxxx> wrote in message
news:1146353770.445575.238950@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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.


Can anyone give me clear explanations... ?

See above.

-Mike


.



Relevant Pages

  • Re: How it works?
    ... The following code is working fine and printing the string "Mohan S". ... int main ...
    (comp.lang.c)
  • How it works?
    ... The following code is working fine and printing the string "Mohan S". ... int main ...
    (comp.lang.c)
  • Re: Segmentation fault error
    ... void main (int argc, char *argv) ... the standard output stream, like any text stream, should have a newline ...
    (comp.lang.c)
  • Re: Help with changing char *string to int * string for sorting.
    ... > otherwise the string may not appear. ... You can always turn off the buffering on the standard output stream using ... setvbuf(). ... It would save a lot of calls to fflush() every time you want to ...
    (comp.lang.c)