Professional Documents
Culture Documents
Assistant Professor
ajay.cse@iitbhu.ac.in
Types of I/O
Console I/O Functions
Types of I/O
Console I/O Functions
Formatted Console I/O Functions
sprintf( ) and sscanf( ) Functions
Types of I/O
Console I/O Functions
Formatted Console I/O Functions
sprintf( ) and sscanf( ) Functions
Unformatted Console I/O Functions
All input and output is performed with streams, which are sequences
of bytes
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
Normally, the standard input stream is connected to the keyboard and
the standard output stream is connected to the screen.
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
Normally, the standard input stream is connected to the keyboard and
the standard output stream is connected to the screen.
Operating systems often allow these streams to be redirected to other
devices.
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
Normally, the standard input stream is connected to the keyboard and
the standard output stream is connected to the screen.
Operating systems often allow these streams to be redirected to other
devices.
A third stream, the standard error stream, is connected to the screen.
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
Normally, the standard input stream is connected to the keyboard and
the standard output stream is connected to the screen.
Operating systems often allow these streams to be redirected to other
devices.
A third stream, the standard error stream, is connected to the screen.
Error messages are output to the standard error stream.
All input and output is performed with streams, which are sequences
of bytes
In input operations, the bytes flow from a device (e.g., a keyboard, a
disk drive, a network connection) to main memory.
In output operations, bytes flow from main memory to a device (e.g., a
display screen, a printer, a disk drive, a network connection, and so on).
Normally, the standard input stream is connected to the keyboard and
the standard output stream is connected to the screen.
Operating systems often allow these streams to be redirected to other
devices.
A third stream, the standard error stream, is connected to the screen.
Error messages are output to the standard error stream.
Console I/O functions
File I/O functions
\b moves the cursor one position to the left of its current position.
\r takes the cursor to the beginning of the line in which it is currently
placed.
\a alerts the user by sounding the speaker inside the computer.
The argument to the * before the . is the field width and the argument to
the * after the . is the precision.
1
https:
//stackoverflow.com/questions/17566886/how-does-d-work-in-printf
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 18 / 32
scanf()
1
POSIX: Portable Operating System Interface is a family of standards specified by
the IEEE Computer Society for maintaining compatibility between operating systems.
2
ANSI C, ISO C and Standard C are successive standards for the C programming
language published by the American National Standards Institute (ANSI) and the
International Organization for Standardization (ISO). Historically, the names referred
specifically to the original and best-supported version of the standard (known as C89 or
C90).
3
IDE:An integrated development environment is a software application that provides
comprehensive facilities to computer programmers for software development. An IDE
normally consists of at least a source code editor, build automation tools and a debugger.
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 22 / 32
Unformatted Console I/O Functions
1
POSIX: Portable Operating System Interface is a family of standards specified by
the IEEE Computer Society for maintaining compatibility between operating systems.
2
ANSI C, ISO C and Standard C are successive standards for the C programming
language published by the American National Standards Institute (ANSI) and the
International Organization for Standardization (ISO). Historically, the names referred
specifically to the original and best-supported version of the standard (known as C89 or
C90).
3
IDE:An integrated development environment is a software application that provides
comprehensive facilities to computer programmers for software development. An IDE
normally consists of at least a source code editor, build automation tools and a debugger.
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 22 / 32
Unformatted Console I/O Functions
1
POSIX: Portable Operating System Interface is a family of standards specified by
the IEEE Computer Society for maintaining compatibility between operating systems.
2
ANSI C, ISO C and Standard C are successive standards for the C programming
language published by the American National Standards Institute (ANSI) and the
International Organization for Standardization (ISO). Historically, the names referred
specifically to the original and best-supported version of the standard (known as C89 or
C90).
3
IDE:An integrated development environment is a software application that provides
comprehensive facilities to computer programmers for software development. An IDE
normally consists of at least a source code editor, build automation tools and a debugger.
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 22 / 32
Unformatted Console I/O Functions
1
Macros are pre-processed which means that all the macros would be processed
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 24 / 32
Unformatted Console I/O Functions
1
An array is collection of items stored at contiguous memory locations. The idea is
to store multiple items of same type together.
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 29 / 32
gets( ) and puts( )
The moment blank was typed after “Jonty” scanf( ) assumed that the
name being entered has ended.
The solution to this problem is to use gets( ) function.
gets( ) gets a newline (\n) terminated string of characters from the
keyboard.
The puts( ) function works exactly opposite to gets( ) function. It
outputs a string to the screen.
1
An array is collection of items stored at contiguous memory locations. The idea is
to store multiple items of same type together.
Ajay Pratap (IIT (BHU), Varanasi) C input/output functions ajay.cse@iitbhu.ac.in 29 / 32
gets( ) and puts( )
The moment blank was typed after “Jonty” scanf( ) assumed that the
name being entered has ended.
The solution to this problem is to use gets( ) function.
gets( ) gets a newline (\n) terminated string of characters from the
keyboard.