Professional Documents
Culture Documents
PPS Chapter 4
PPS Chapter 4
PPS Chapter 4
Output stream:It is used to move data from computer program to output devices.
The channel to move data from computer program to output devices.
Note: Streams are unidirectional. Input stream is only used to accept/ read data, they are not used to
display/write data.
Unformatted functions: These functions are only used to read/write data in the form of character
(char) data type.
They do not require “control string”/”format specifier” to differentiate one data type from other.
Formatted functions: These functions are used to read/write data in all data types (int, long, short,
float, double, char)
They require conversion symbol which differentiate one data type from other, called “control
string”/”format specifier”. (eg. %d, %f, %c etc)
1. getchar(): This function is used to read only one charcter at a time from keyboard.
General syntax: character_variable=getchar();
eg. char ch;
ch=getchar();
2. putchar(): This function is used to write only one charcter at a time on monitor.
General syntax: putchar(character_variable);
eg. char ch;
ch=getchar();
putchar(ch);
3. gets(): This function is used to read one or more charcters (string) at a time from keyboard.
General syntax: gets(string_variable);
4. puts():This function is used to write one or more charcters at a time on monitor.
General syntax: puts(string_variable);
eg. #include<stdio.h>
void main()
{
char line[80]; //declaration of string
gets(line); // read and store string in line variable
puts(line); // write/display sring on monitor
}
printf() function is used to display data in all data types (like int, float, char). To differentiate one
data type from another this function uses format specifier.
General syntax:
1. To print one value at a time
printf(“format_specifier”,argument);
2. To print more than one value at a time
printf(“format_specifier,format_specifier,format_specifier”,argument1,argument2,argument3);
3. To print simple message
printf(“your message”);
6. scanf(): The scanf() function is used to read/accept data from input device i.e. key board. scanf()
function is used to read data in all data types (like int, float, char). To differentiate one data type
from another this function uses format specifier.
General syntax:
1. To read one value at a time
scanf(“format_specifier”,&argument);
2. To read more than one value at a time
scanf(“format_specifier,format_specifier,format_specifier”,&argument1,&argument2,&argument3);
& => address operator. The scanf() function requires & operator. The address operator is used to
print address (memory location) of the variable.
In the scanf() statement the role of ‘&’ operator is to indicate memory location of the variable, so
that the value raed from key board is placed at that location.