473,397 Members | 1,960 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How it works?

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....Why it didn't throw any error;instead its running
fine...

Can anyone give me clear explanations... ?
Thanks in advance...
Mohan Shanmugam

Apr 29 '06 #1
3 2022

"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.

Can anyone give me clear explanations... ?


See above.

-Mike
Apr 30 '06 #2
"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.
Apr 30 '06 #3
On 29 Apr 2006 16:36:10 -0700, "Mohan" <mo*********@gmail.com> wrote:
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....Why it didn't throw any error;instead its running
fine...

Can anyone give me clear explanations... ?
Thanks in advance...

stdout is a FILE* that is declared in stdio.h and defined and
initialized by the startup code that executes prior to main. fp is a
FILE* defined in your program. It is perfectly legal for two pointers
to point to the same object.

Remove del for email
Apr 30 '06 #4

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

Similar topics

0
by: Puneet Jain | last post by:
I am tryin to use Microsoft Works Wordprocessor from Python After generating the .py module from the type library using makepy utility, I runt he following commands, >>> from win32com.client...
1
by: Gerd Güldenast | last post by:
Hi, I am having a problem with a replication over a Modem-Connection, which works fine over LAN. Has anyone experienced this problem before? Settings are: 2 SQL Servers 2000, SP3 on Windows...
10
by: tony kulik | last post by:
This code works fine in ie and opera but not at all in Mozilla. Anybody got a clue as to how to get it right? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <script...
1
by: Moi | last post by:
I have tried repeatedly to import a MS Works database (simple address database) into Access, but I am having little luck. I have saved the Works file as DbaseIII DbaseIV and neither is seen by the...
2
by: Enrique Bustamante | last post by:
Casting arrays that works on watch and command window but not in code. My application is casting arrays in a way it should work. To test if I was doing something invalid, I wrote a test code that...
4
by: puja | last post by:
hi all, I have an asp.net website where am including .css file dynamically on page load event. For diff users, there is diff CSS file. So after user logs in, I am setting CSS href on page load....
0
by: patmg | last post by:
Hello, We use a SQL Server database to manage accounts in AD via a COM object using ADSI written in VB6. I have to move this database to a new server. The only real difference between the two...
3
by: Miro | last post by:
First off...thanks in advance for getting me this far. Sorry for all these class posts but im having a heck of a time here trying to get something to work, and have finally got it to work (...
6
by: nild | last post by:
Hello i have a strange problem. I'm using LogonUser to impersonate the user under which my program must run. On Win XP or Server 2003 it works. But on 2000 it doesn't. So i found out, to set...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.