You are on page 1of 8

Chapter 4

Managing
Input/Output operations

© Khalid Nazim S.A.


Assistant Professor,
Department of Computer Science & Engineering
PES School of Engineering, Bangalore -100
Input/Output

Program
Input / Output Functions

I/O Functions

Unformatted Formatted
getch( ) ,getche( ),putch( )
getchar( ), putchar ( )
scanf( )
gets( ), puts( ) printf( )
Formatted input
scanf (“control string”,&arg1,&arg2,…&argn);
Control string (format string) –
 It consists of field/ format specifications
consisting of the conversion character % ,
 a data type and a optional number specifying
the field width.
 arg1,arg2…argn- it specifies the address
of locations where the data is stored
Inputting integer numbers

The field specification for reading a integer


number is:
%w d
Where % denotes the conversion specification
follows.
w= integer number
d=indicates that the number to be read is in
integer mode
Formatted output
printf (“control string”,arg1,arg2,…argn);
Control string (format string) –
It consists of 3 things namely-
4. Characters that will be printed on the screen as they appear
5. Format specifications that define the output format for
display of each item
6. Escape sequence characters such as \n,\t etc..
arg1,arg2…argn-
The variables whose values are formatted and printed
according to the specifications of the control string
The arguments should match in number, order and type with the
format specifications
Types of Errors
Syntax errors- ( compilers / interpreters)
These errors are generated if the rules of the
language defined are not followed.
ex: missing of a semicolon after an assignment operation.
Logical errors- ( debugger)
They are also referred to as semantic errors, and
these result if the desired outputs are not obtained.
Run – Time errors-
These occur when a program attempts to perform a
task which is forbidden.
Examples of run time errors:
12. Null pointer assignment.
13. Divide by zero

You might also like