INPUT OUTPUT FUNCTIONS
INPUT OUTPUT FUNCTIONS
STANDARD INPUT
In c input is given to the computer by keyboard so keyboard is refferd as standard input.For
standard input scanf is used.
STANDARD OUTPUT
In c output is mainaly displayed on monitor so monitor is reffered as standard output for the
standard output printf is used.
PRINTF()
The printf function is an output function that is used to display formatted output of program on
monitor.it takes argument as format string and an optional list of variable to output.
SYNTAX:
Printf(format string);
Printf(“format string”,argument list);
Example:
Printf(“I love Pakistan”);
Printf(“area=%f”,A);
In above axample area=%f written in double quotes is known as format string and
A is variable known as argument list.
FORMAT STRING:
The format string is a character string. Also known as controle string.it is in double quotes. The
format may consist of:
1. Text
2. Format specifiers
3. Escape sequence
ARGUMENT LIST
The argument list is consist of constants,variables or expressions whose values are to be
printed.
Format string Argument list
Printf(“\n sum of%d and %d is %d”,value1,value2,value1+value2);
PUTS
Puts function is used to print a constant or stored sting on display screen.
INPUT FUNCTIONS
1. SCANF()
The scanf function is an input function that is used to get input from user through
keyboard during the program execution.
The Input is stored in a variable in a specified from like numeric,character and string
type variables.
SYNTAX:
Scanf(format string, variables)
EXAMPLE:
Scanf(“%f”,&num);
In above example %f is used as string and &num is used as argument list
and the & is the address variable.
FORMAT STRING ARGUMENT LIST
Scanf(“%d%d”,&a,&b)
GETS():
Gets is a input function. It is used to input a string from keyboard and
stored in memory.
GETCH()
Getch stands for get character. It means it get a character from keyboard
during program execution.
It does not echo the typed character means do not display the typed
character on screen.
The input process is completed automatically without pressing of “Enter
key”
CHAR(ch);
Printf(“type a character”)
Ch=getch
GETCHE():
Getche stands for get character echo. It means it get a character from
keyboard during program execution. It echo the typed character means
display the typed character on screen.
The input process is completed without pressing the “Enter key”
Char ch;
Printf (“Type a character”:);
Ch=getche