Home | Hindi | Kabir | Poetry | Workshop | BoloKids | Writers | Contribute | Search | Contact | Share This Page!                      Shop Online

  News
Channels
In Focus

Analysis  
Bolography  
Cartoons
Environment   
Opinion 

Columns
 Business
 My Word 
 PlainSpeak 
 Random Thoughts 
Our Heritage

Architecture
Astrology
Ayurveda
Buddhism
Cinema 
Culture
Dances
Festivals
Hinduism
History  
People  
Places 
Sikhism
Spirituality 
Vastu 
Vithika  

Society & Lifestyle

Family Matters 
Health
Parenting
Perspective 
Recipes
Society
Teens 
Women 

Creative Writings

Book Reviews
Ghalib's Corner
Humor
Individuality
Jagoji
Literary Shelf 
Love Letters  
Memoirs
Musings
Ramblings
Stories
Travelogues

Computing
  General Articles
 
CC++ 
  Flash 
  Internet Security 
 
Java 
 
Linux     
  Networking  

Computing | CC++   
Managing Output Operations

Last time, we had a brief look on the input operations in C language. Naturally, the logical following to it will be managing the output operations. This section will tell you the proper ways to display output so that it will be presented in an acceptable form to the user.

Writing a Character

Like getchar, there is an analogous function putchar for writing characters one at a time to the terminal. It takes the form as shown below :

putchar(variable_name);

where variable_name is a type char variable containing a character. This statement displays the character contained in the variable_name at the terminal. For example, the statements

answer = 'S'
putchar(answer);

will display the character Y to the screen.

Formatted Output

It is highly desirable that the outputs are produced in such a way that they are understandable and are in an easy-to-use form. The printf statement provides certain features that can be effectively exploited to control the alignment and spacing of printouts on the terminals. The general form of printf statement is:

printf("control string", arg1, arg2,....argn);

Control string consists of three types of items:

1. Characters that will be printed on the screen as they appear.

2. Format specifications that define the output format for display of each item.

3. Escape sequence characters such as \n, \t , and \b.

The control string indicates how many arguments follow and what their types are. The arguments arg1 ,arg2 , ...argn are the variables whose values are formatted and printed according to the specifications of the control string. The arguments should match in number , order and type with the format specifications .

Output of Integer Numbers

The format specification for printing an integer number is % w d

where w specifies the minimum field width for the output . However , if a number is greater than the specified width , it will be printed in full , overriding the minimum specification . d specifies that the value to be printed is an integer. The number is written right-justified in the given field width. Leading blanks will appear as necessa- ry.

Output of Real Numbers

The output of a real number may be displayed in decimal notation using the following format:

% w.p f

The integer w indicates the minimum number of positions that are to be used for the display of the value and the integer p indicates the number of digits to be displayed after the decimal point. The value, when displayed, is rounded to p decimal places and printed right justified in the field of w columns. Leading blanks and trailing zeros will appear as necessary. The default precision is 6 decimal places.

Printing of strings

The format specification for outputting strings is similar to that of real numbers. It is of the form

%w.p s

where w specifies the field width for display and p instructs that only the first p characters of the string are to be displayed. The display is right-justified.

Printf format codes are same as that for scanf , with the meaning of each associated with printing.( %[..] not applicable).

– Sachin Mehta
December 28, 2000

C/C ++        
Managing Input-Output Operations
     
Managing Output Operations
    
Decision Making And Branching
     
Decision Making and Branching (if statement)
     
Decision Making and Looping
    
The Do Statement
   
Arrays
    
Arrays - Multi-Dimensional
    
Handling of Character Strings
    
Handling of Character Strings - 2  
User Defined Functions   
   User Defined Functions...contd    
Handling of Functions  

Computing
Flash | Internet Security 
Java | Linux | Networking  

General Articles  

Top | Previous | Next  
 


 

Recommend This Page!

Analysis | Architecture | Astrology | Ayurveda | Book Reviews | Buddhism | Cartoons | Cinema | Computing | Culture | Dances
Environment | Fables | Family Matters | Festivals | Hinduism | Health | History | Home Remedies | Humor | Individuality | Jagoji
Literary Shelf | Memoirs | Musings | Opinion | Parenting | Perspective | Photo Essays | Places | Ramblings
Random Thoughts | Recipes | Sikhism | Society | Spirituality | Stories | Teens | Travelogues | Vastu | Vithika | Women

Home | Hindi | Bolography | BoloKids | Kabir | Poetry | Quotes | Workshop | Writers | Contribute | Search | Contact


Boloji.com is owned and managed by Boloji Media Inc

Privacy Policy | Disclaimer
No part of this Internet site may be reproduced without prior written permission of the copyright holder.