Powered By Blogger

Monday 14 January 2013

I-P-O

I-P-O stands for Input-Process-Output ,each and every program in any programming language performs I-P-O operation ,I/O (Input-Output) is all we need in our C Program .
 
In C Language :
stdin is used for Input
stdout is used for Output
 
Input & Output takes place as a stream of character .
we can perform or use two types of ,mainly two types of Input & Output ,
 
1.Character-Based I/O
2.String-Based I/O
 
 
Character-based I/O includes :-
 
#getc()
#putc()
#getchar()
#putchar()
 
getc() : getc() is also a function/inbuilt function ,or you can say a keyword .getc() is used to accept a single character .example : getc(a); ,so this statement will accept a single character 'a' .
 
putc() : putc() is also a function/ inbuilt function ,putc() is used to generate an output or to display the accepted character on console window (Console window is the responsible window ,where you actually visualize you output of you C Program) .
 
Illustration :
 
#include<stdio.h>
main()
{
 char c;
 c=getc(stdin);
 putc(c,stdout);

 
so here we are declaring a character type variable c ,c=getc(stdin); statement is storing and accepting variable's value ,putc(c,stdout); is used to display the stored variable's value onto the console :
 

 
 
getchar() : is also used to accept a single character ,the only difference between getc() and getchar() is about parameters, parameters are the additional information we pass between (...) .
 
putchar() : is also used to display a single character ,parameters are bit different as compare to
 putc() .
 
Illustration :
 
#include<stdio.h>
main()
{
 char c;
 c=getchar();
 putchar(c);
 printf("\n");
}


 
 
you can see here that there is no need to specify stdin or stdout .so a different way to implement character-based I/O operations .

String-Based I/O includes :-

#gets()
#puts()

gets() : is used to accept a string (sequence of characters ) ,example : "Programming" .
puts() : is used to display the string

Illustration :
#include<stdio.h>
main()
{
 char c[20];
 puts("Enter Something :\n");
 gets(c);
 puts("You Entered: ");
 puts(c);
 printf("\n");
}


so here we are declaring a character type variable c which holds sequence of  20 character .
you can see here gets and puts used to accept and display strings .



No comments:

Post a Comment