8.Lect-9 IO
-
Upload
vidit-vishnoi -
Category
Documents
-
view
226 -
download
0
Transcript of 8.Lect-9 IO
-
7/28/2019 8.Lect-9 IO
1/14
DATA INPUT AND OUTPUT
Mohit Arora
Lecturer , LIECA
LPU
-
7/28/2019 8.Lect-9 IO
2/14
INPUT/OUTPUT IN C
C has no built-in statements for input or
output.
A library of functions is supplied to perform
these operations. The I/O library functions
are listed the header file .
You do not need to memorize them, just be
familiar with them.
-
7/28/2019 8.Lect-9 IO
3/14
STREAMS
All input and output is performed with
streams.
A "stream" is a sequence of characters
organized into lines.
Each line consists of zero or more characters
and ends with the "newline" character.
-
7/28/2019 8.Lect-9 IO
4/14
TYPES OF STREAMS IN C
Standard input stream is called "stdin" and is
normally connected to the keyboard
Standard output stream is called "stdout" and
is normally connected to the display screen.
Standard error stream is called "stderr" and
is also normally connected to the screen
-
7/28/2019 8.Lect-9 IO
5/14
I/O FUNCTIONS IN C
There are six i/o functions in C are:
1. getchar()
2. putchar() 3. printf()
4.scanf()
5.gets() 6.puts()
-
7/28/2019 8.Lect-9 IO
6/14
GETCHAR()
getchar();
Single character can be entered in computer
using C.
Example: Char c;
.
C=getchar();
-
7/28/2019 8.Lect-9 IO
7/14
PUTCHAR()
putchar();
It is used to display single char.
Examplechar c=H;
putchar(c);
-
7/28/2019 8.Lect-9 IO
8/14
SCANF
scanf ( ) ; This function provides for formatted input from
the keyboard. The syntax is:scanf( format , &var1, &var2, ) ;
The format is a listing of the data types of thevariables to be input and the & in front of eachvariable name tells the system WHERE to storethe value that is input. It provides the addressfor the variable.
Example:float a; int b;scanf(%f%d, &a, &b
-
7/28/2019 8.Lect-9 IO
9/14
FORMAT OF DATA
Format Conversion Specifiers:d -- displays a decimal (base 10) integer
l -- used with other specifies to indicate a "long"
e -- displays a floating point value in exponentialnotation
f -- displays a floating point value
g -- displays a number in either "e" or "f" format
c -- displays a single characters -- displays a string of characters
-
7/28/2019 8.Lect-9 IO
10/14
STRINGS
When you enter string data the compiler
automatically add \0 in the end of string;
Char name[22];
gets(name);
ROHIT
But actual value stored in computer isROHIT\0
-
7/28/2019 8.Lect-9 IO
11/14
PRINTF
This function provides for formatted output tothe screen. The syntax is:
printf( format, var1, var2, ) ;
The format includes a listing of the datatypes of the variables to be output and,optionally, some text and controlcharacter(s).
Example:float a ; int b ;
scanf( %f%d, &a, &b ) ;
printf( You entered %f and %d \n, a, b );
-
7/28/2019 8.Lect-9 IO
12/14
GETS AND PUTS
To input a string to computer
gets(name);
Puts is used to display string data on screen puts(name);
-
7/28/2019 8.Lect-9 IO
13/14
ANY QUESTIONS
-
7/28/2019 8.Lect-9 IO
14/14
THANK YOU