GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Programming  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 26 of 453    Print  
How do you redirect a standard stream?
Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; it can be redirected to a file or printer port. Similarly, your program’s input (stdin) can come from a file rather than the keyboard. In DOS, this task is accomplished using the redirection characters, < and >. For example, if you wanted a program named PRINTIT.EXE to receive its input (stdin) from a file named STRINGS.TXT, you would enter the following command at the DOS prompt:
C:>PRINTIT < STRINGS.TXT
Notice that the name of the executable file always comes first. The less-than sign (<) tells DOS to take the strings contained in STRINGS.TXT and use them as input for the PRINTIT program. 
The following example would redirect the program’s output to the prn device, usually the printer attached on LPT1:
C :> REDIR > PRN
Alternatively, you might want to redirect the program’s output to a file, as the following example shows:
C :> REDIR > REDIR.OUT
In this example, all output that would have normally appeared on-screen will be written to the file
REDIR.OUT.
 
Redirection of standard streams does not always have to occur at the operating system. You can redirect a standard stream from within your program by using the standard C library function named freopen(). For example, if you wanted to redirect the stdout standard stream within your program to a file named
OUTPUT.TXT, you would implement the freopen() function as shown here:
...
freopen(“output.txt”, “w”, stdout);
...
Now, every output statement (printf(), puts(), putch(), and so on) in your program will appear in the file
OUTPUT.TXT.
 


  
Total Answers and Comments: 2 Last Update: June 09, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
August 13, 2007 09:21:08   #1  
Lance Norteno        

RE: How do you redirect a standard stream? ...
How you redirect your output depends on your operating system. Basically when your program finishes your output goes to a sysout queue. From there it has to be picked up. I have seen sites where they poll the sysout and send it through Adobe or through a pipe to the printer or even to hard drive. There are even ways to log on from your terminal and manually redirect jobs to their destination. Not knowing what type of configuration you have it would be hard to be more specific.
 
Is this answer useful? Yes | No
June 09, 2008 07:46:26   #2  
jintojos Member Since: May 2008   Contribution: 29    

RE: How do you redirect a standard stream?
By using the operators "<" and ">" we can redirect the standard input and out streams.

example : d:> jinto.exe > outputredirected

d:> jinto.exe < inputredirected

 
Is this answer useful? Yes | No

 Related Questions

Floating-point numbers are the “black art” of computer programming. One reason why this is so is that there is no optimal way to represent an arbitrary number. The Institute of Electrical 
Latest Answer : A program running in the database that can take complex actions based on the inputs you send it. Using a stored procedure is faster than doing the same work on a client, because the program runs right inside the database server. ...

A global variable that must be accessed from more than one file can and should be declared in a header file. In addition, such a variable must be defined in one source file. Variables should not be defined 
Latest Answer : A variable can be declare/define in a C Header without any kind of compilational/ logical errors. But it is against the coding specifications and it is not normally practiced. If proper Multiple inclusion protection macro is used, then there will be no ...

The answer is the standard library function qsort(). It’s the easiest sort by far for several reasons: It is already written. It is already debugged. It has been optimized as much as possible (usually). 
Latest Answer : Greetings!can u plz explain me the sorting function with its implementation in a small program and send it to my e-mail Id : venki_m182003@yahoo.com ...

Just as qsort() was the easiest sorting method, because it is part of the standard library, bsearch() is the easiest searching method to use. If the given array is in the sorted order bsearch() is the 

Most operating systems, including DOS, provide a means to redirect program input and output to and from different devices. This means that rather than your program output (stdout) going to the screen; 
Latest Answer : By using the operators "" we can redirect the standard input and out streams.example : d:> jinto.exe > outputredirected                d:> ...

The preceding example showed how you can redirect a standard stream from within your program. But what if later in your program you wanted to restore the standard stream to its original state? By using 
Tags : Restore

Streams can be classified into two types: text streams and binary streams. Text streams are interpreted, with a maximum length of 255 characters. With text streams, carriage return/line feed combinations 
Latest Answer : Will you please explain how binary mode takes less memory? ...

Stream functions such as fread() and fwrite() are buffered and are more efficient when reading and writing text or binary data to files. You generally gain better performance by using stream functions 

When writing your C program, you can include files in two ways. The first way is to surround the file you want to include with the angled brackets < and >. This method of inclusion tells the preprocessor 
Latest Answer : if you used #include" filename.h" for including header files then the compiler will check only in the current directory.but if you used #include for including header files then the compiler will checks all directories specified ...

The ANSI C standard defines six predefined macros for use in the C language: Macro Name Purpose _ _LINE_ _ Inserts the current source code line number in your code. _ _FILE_ _ Inserts the current source 


 Sponsored Links

 
Related Articles

Taking Advantage of Standard Internet Protocols

Taking Advantage of Standard Internet Protocols As mentioned Oracle XML DB provides native support for standard internet protocols such as S WebDAV and Continuing with the preceding sample you might for example upload another employee XML document into the XML repository with one of the above prot
 

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Standard Input Output Stream

C Standard Input Output Stream In this C tutorial you will learn about standard input stream and standard output stream explained along with syntax and examples C programming language uses the concept of streams to perform input and output operations using the keyboard and to display information on
 

What is AES Standard

Advanced Encryption Standard (AES), also known as US FIPS PUB 197, is a block cipher which has been adopted as an encryption standard by the U.S. government, superseding the Data Encryption Standard (DES). It is also known as Rijndael, which is a portmanteau of the surnames of the two Belgian crypto
 

What is AMPS Standard

Advanced Mobile Phone System (AMPS) is a first-generation (1G) analog mobile phone system standard developed by Bell Labs and introduced in America in 1983, with variants such as Total Access Communication System (TACS) available in Europe and Japanese Total Access Communication (JTAC) available in
 

What is 1000BASE-T Standard

1000BASE-T, or IEEE 802.3ab, is a Gigabit Ethernet wiring standard for Local Area Networks (LAN) that uses copper-based networking hardware as its medium. It is one of the most widely used standards of Ethernet over twisted pair. The Institute of Electrical and Electronics Engineers Standards Associ
 

What is 100BASE-T Standard

100BASE-T is a subset of Fast Ethernet that refers collectively to a number of Ethernet wiring standards that carry signals at 100Mbps over twisted pair cables. Its IEEE-designated identifier is derived from its characteristics. &quot;100&quot; refers to its rate of transmission of Ethernet
 

What is 10BASE-T Standard

10BASE-T is an Ethernet standard for local area networks (LAN) that requires only one copper twisted pair cable of Category 3 (CAT-3) or higher, either unshielded twisted pair (UTP) or shielded twisted pair (STP), for a maximum network segment length of 100 meters for UTP, or 200 meters for STP. I
 

What is 10BASE5 Standard

10BASE5 is an Ethernet standard that requires a specialized coaxial cable to transmit Ethernet frames at a rate of 10Mbps. It is also known as &quot;Thick Ethernet&quot; or &quot;Thicknet&quot; because of the thick coaxial cable it uses, which is 0.375 inches in diameter. Its desig
 

What is 10BASE2 Standard

10BASE2, or IEEE 802.3, is an early Ethernet Standard that makes use of industry-standard RG-58 coaxial communications cables connected to BNC T-connectors. 10BASE2 gets its identifier, assigned by the Institute of Electrical and Electronics engineers (IEEE), from the following characteristics: &
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape