Overview of I/O Statements of C Language i.e puts() , gets() , getchar() and putchar() with Examples

Input_Output Statement

UnFormatted Input Statements:
These statements are primarily concerned with reading the character type data from the keyboard. 
The getchar() and gets() Functions are used for this purpose. Since, they are included in the stdio.h Header File, the C Program that uses these functions should exclusively have the following preprocessor statement :


   #include<stdio.h>  


 a) getchar() Function:
This Function reads a single character from the standard input device. There is no parameter within the parentheses. Its syntax is:

    char_var = getchar();    

where
char_var is a character type variable to which an accepted character is assigned.

Example:
main()
{
char letter;
letter = getchar();
}

b) gets() Function:
This Function reads in everything you enter from the keyboard until the ENTER key or RETURN is pressed. Here everything means a string which is a sequence of all printable ASCII characters. The syantax is:


    gets(string);    

where
string is a sequence of characters and is of type char.

Example:
main()
{
char name[25];
printf(" Enter your Name\n");
gets(name);
}

UnFormatted output Statements:
These statements are mainly concerned with displaying or printing the character type data on the monitor(screen). The putchar() and puts() Functions are used for this purpose. They are included in the stdio.h Header File. So if we use unformatted statements in C Programs then
#include<stdio.h>  Header File is required.

a) putchar() Function:
This Function prints a single character on the screen. The character to be displayed is of type char. Its syntax is:


   putchar(ch_var);    

where
ch_var is a character variable which is enclosed within the parenthesis.

Example:
main()
{
char ch;
putchar(ch);
}

Program:
#include<stdio.h>
main()
{
char dhoni;
dhoni = getchar();
putchar(letter);
}
The following Program illustrates both reading and printing of a single character.

b) puts() Function:
This Function prints a string of characters on the screen. The syntax is:


   puts(string);   

where
string is a sequence of characters.

Example:
#include<stdio.h>
main()
{
char msg[20];
puts(msg);
}

Program:
#include<stdio.h>
main()
{
char msg[20];
printf(" Enter the msg\n");
gets(msg);
puts(msg);
}

0 Response to "Overview of I/O Statements of C Language i.e puts() , gets() , getchar() and putchar() with Examples"

Post a Comment

Popular Posts

Label

1 Sidebar 2 Columns 3 Columns Footer 3rdball 4 Columns Footer Alex Alvaro Antsasia Arlinadesign Averie Barry BASIC CONCEPTS Basil Bayna Fast BeautyPress BeautyTemplates Beckel Best Best - Clean Beyonce Pro BioMag BlackMag Blanter Nova Blogger Card Bloggertheme9 Blogish Bpress Brakt C LANGUAGE C PROGRAMS C++ LANGUAGE C++ PROGRAMS Carella Cellar Charlotte Chooko Lite Clara Clean Combo One Cooperate Crusade Darry Dorman Dreamway Dunia Blanter eCars EduAcademy EducationPress Elise Elvan Eva Everyday FabNews Fashion Fashion Blogger Template Fashion Gossip FastCars Fedo FlashNews Fredy Portfolio Gaming Globus GoodTime Goomsite HTML LANGUAGE iGaming Indicate Innove Insomnia InspiredNews iSoft Jasmine Kalem Landscaping Lashira Lavelle Lily Fashion Limax Linea Lionex Luminescence Lite Lumix Luxury Magazine MagazinePro MAJOR DIFFERENCES MarketingBlog Martin MaxiMag Medica Mega Melissa Mercury MeshMag Minimag Minimalist MiniNews MovieKhor msdesignbd MusicLand Neko NetZine New Spread News16 Newsflash NewsForce NewsIdea Newspaper News NewsPro Nubie Fast Odd Themes Optima PaperMag PaperMag blog Parhlo Perfection Personal Personal Blog Photosout PixelZ Power Blog Premium Themes ProfileMag Purez Rano ReadNews Real estate Remito Grid Responsive Revo Robusta Rotario Saara SeoBoost Settle Shouters Simple Catch SimpleClean Sketchly SNews SolidMag Someo Sophie Sora Sora Bank Sora Home Sora News Responsive Sora One Sora Ribbon Spido Sticko Stucco Sure Mag Swift Tech Tech Pro Techia Techmax TechSpot TemplateClue Templateism Templatesilk Templatesyard Templatezy The Freelancer TheBlogger TheFocus Themeforest Themexpose TIPS AND TRICKS Topside TravelMag Trendy Trendy Travel Tumblr Under Construction Uong Jowo Veethemes Vertox VideoPlay Vigo Waverly way2themes WebBiz Wedding X-Mag Zealer ZetaMag