SlideShare a Scribd company logo
1 of 5
Download to read offline
For more Https://www.ThesisScientist.com
Unit 4
Input/Output Functions
Introduction to Input/Output
Input refers to accepting data while output refers to presenting data. Normally the data is accepted from
keyboard and is outputted onto the screen.
C language has a series of standard input-output (I/O) functions. Such I/O functions together form a library
named stdio.h. Irrespective of the version of C language, user will have access to all such library functions.
These library functions are classified into three broad categories.
a) Console I/O functions : Functions which accept input from keyboard and produce
output on the screen.
b) Disk I/O functions : Functions which perform I/O operations on secondary
storage devices like floppy disks or hard disks.
c) Port I/O functions : Functions which perform I/O operations on various ports
like printer port, mouse port, etc.
Console I/O Functions
Console I/O refers to the operations that occur at the keyboard and the screen of your computer. Console
I/O functions can be further classified as: 
 Formatted Console I/O
 Unformatted Console I/O
The basic difference between formatted and unformatted I/O functions is that the formatted I/O functions
allow input and output to be formatted as per the requirements of the user.
Console I/O Functions
Formatted Functions Unformatted Functions
Type Input Output Type Input Output
char scanf( ) printf( )
int scanf( ) printf( )
float scanf( ) printf( )
string scanf( ) printf( )
char getch( )
getche( )
getchar( )
putch( )
putchar( )
int - -
float - -
string gets( ) puts( )
Console I/O Functions
Formatted Functions Unformatted Functions
Type Input Output Type Input Output
char scanf( ) printf( )
int scanf( ) printf( )
float scanf( ) printf( )
string scanf( ) printf( )
char getch( )
getche( )
getchar( )
putch( )
putchar( )
int - -
float - -
string gets( ) puts( )
Formatted Console I/O Functions
Formatted I/O functions accept or present the data in a particular format. The standard C library consists of
two functions that perform output and input, viz., printf( ) and scanf( ). These functions can format the
information under the user's directions.
Formatted Output
It is highly desirable that the outputs are presented in such a way that they are understandable and are in a
form easy to use.
The printf( ) statement provides certain features through which the screen output is effectively controlled.
The general form of printf( ) function is:
printf ("Control String", arg1, arg2. . . );
Control string may contain:
 Characters that are simply printed as they are.
 Conversion specifications that begin with a % sign.
 Escape sequences that begin with  sign.
The control string indicates how many arguments follow and what their types are. The arguments arg1,
arg2. . . are the variables whose values are formatted and printed according to specifications of the control
string. The arguments must match in number, order, and type with the format specifications.
e.g.: main( )
{
int arg = 346;
float per = 69.2;
printf ("Average = % d n percentage = % f", arg, per);
}
output: Average = 346
Percentage = 69.2
Conversion Specifications
The conversion specifications are used to provide the type and size of the data. Each conversion
specification must begin with %.
In the above example %d and %f are the conversion characters. The general form of conversion specifier is
% fws fx
where fws = field width specifier
fx = format specifier
The field width specifier tells printf( ) how many columns on the screen should be used while printing a
value.
e.g.: %7d tells to print the variable as a decimal integer in the field of 7 columns.
If we include a minus sign in conversion specification (e.g., % - 7d), this means left justification is desired
and the value will be padded with blanks on the right.
Given below is a list of conversion characters that can be used with the printf( ) function.
Data Type Conversion Character
short signed %d or % i
Integer
short unsigned % u
Long signed % ld
Long unsigned % lu
unsigned hexadecimal % x
unsigned octal % 0
float % f
Real
double % lf
signed character % c
character
unsigned character % c
String % s
Escape Sequences
The backslash symbol () is considered as escape character because it causes an escape from the normal
interpretation of a string, so that the next character is recognized as the one having special meaning.
Escape sequence Purpose Escape sequence Purpose
n New line t Tab
b Backspace r Carriage return
f formfeed a Alert
' single quote " Double Quote
 Backslash
Output of Integer Numbers
The format specification for printing an integer number is %wd where 'w' specifies minimum width for the
output. The number is written right justified in the given field width.
e.g.: printf ("%d", 12345); 12345
printf ("%10d", 12345); 12345
printf ("% 010d", 12345); 0000012345
printf ("% -10d", 12345); 12345
Output of Real Numbers
The real number is displayed in decimal notation with format specification % w.pf where'w' is the integer
which represents the minimum number of positions that are to be used and 'p' indicates that in the total
width, how many numbers will be placed after the decimal point.
e.g.: printf ("%7.4f", 98.7654); 98.7654
printf ("%7.2", 98.7654); 98.77
printf ("%f", 98.7654); 98.7654
Printing of Single Character
A single character can be displayed in a desired position using format %wc. By default, the character will
be displayed right justified in a field of 'w' columns. To make it left justified, place a minus sign in format
specification.
Formatted Input
Formatted input refers to an input data that has been arranged in a particular format. For the formatted input
we use the function scanf( ).
scanf( ) Function
scanf( ) function, allows us to read formatted data and automatically convert numeric information into
integers and float. The general from of scanf( ) is
scanf ("control string", arg1, arg2, . . . . . );
Control string specifies the field format in which data is to be entered and the arguments arg1, arg2 - - - - -
specify the ADDRESS OF LOCATION where value is to be stored. Control string and arguments are
separated by commas.
Given below is a list of format specifier used to read the inputs:
Code Meaning Code Meaning
% c Read a single character % d Read a decimal integer
% ld Read a long integer % i Read a decimal, or hexadecimal or octal
integer
% e Read a floating point number % f Read a floating point number
% h Read a short integer % o Read an octal number
% s Read a string % x Read a hexadecimal number
% p Read a pointer % n Read an integer value equal to the number
of
characters read so far.
Input of Integer Numbers
The format specification for reading an integer number is % wd where (%) sign indicates conversion
specification, 'w' is the integer number for field width specification and 'd' indicates that the number is to be
read in integer mode.
e.g.: scanf ("% 2d % 5d", & n1, &n2);
An input field may be skipped by specifying * in place of field width.
e.g.: scanf ("% 2d % * d % 6d", &n1, &n2);

More Related Content

What's hot

Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++Muhammad Waqas
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Jayanshu Gundaniya
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C LanguageShaina Arora
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in CJeya Lakshmi
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++HalaiHansaika
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentationMartin McBride
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in CHarendra Singh
 

What's hot (20)

Array and string
Array and stringArray and string
Array and string
 
OOPS Basics With Example
OOPS Basics With ExampleOOPS Basics With Example
OOPS Basics With Example
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
Basics of pointer, pointer expressions, pointer to pointer and pointer in fun...
 
Type conversion
Type conversionType conversion
Type conversion
 
c-programming
c-programmingc-programming
c-programming
 
Python exception handling
Python   exception handlingPython   exception handling
Python exception handling
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Looping statements in C
Looping statements in CLooping statements in C
Looping statements in C
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member[OOP - Lec 18] Static Data Member
[OOP - Lec 18] Static Data Member
 
Print input-presentation
Print input-presentationPrint input-presentation
Print input-presentation
 
User defined functions in C
User defined functions in CUser defined functions in C
User defined functions in C
 

Similar to Introduction to Input/Output Functions in C

MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in cniyamathShariff
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and OutputSabik T S
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Chapter3
Chapter3Chapter3
Chapter3Kamran
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingMd. Ashikur Rahman
 

Similar to Introduction to Input/Output Functions in C (20)

MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
2 data and c
2 data and c2 data and c
2 data and c
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Chapter3
Chapter3Chapter3
Chapter3
 
First c program
First c programFirst c program
First c program
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 

More from Thesis Scientist Private Limited

Latest Research Topics On Flying Ad-Hoc Networks (FANETs):
Latest Research Topics On Flying Ad-Hoc Networks (FANETs):Latest Research Topics On Flying Ad-Hoc Networks (FANETs):
Latest Research Topics On Flying Ad-Hoc Networks (FANETs):Thesis Scientist Private Limited
 

More from Thesis Scientist Private Limited (20)

HTML guide for beginners
HTML guide for beginnersHTML guide for beginners
HTML guide for beginners
 
Ransomware attacks 2017
Ransomware attacks 2017Ransomware attacks 2017
Ransomware attacks 2017
 
How to write a Great Research Paper?
How to write a Great Research Paper?How to write a Great Research Paper?
How to write a Great Research Paper?
 
Research Process design
Research Process designResearch Process design
Research Process design
 
How to write a good Dissertation/ Thesis
How to write a good Dissertation/ ThesisHow to write a good Dissertation/ Thesis
How to write a good Dissertation/ Thesis
 
How to write a Research Paper
How to write a Research PaperHow to write a Research Paper
How to write a Research Paper
 
Internet security tips for Businesses
Internet security tips for BusinessesInternet security tips for Businesses
Internet security tips for Businesses
 
How to deal with a Compulsive liar
How to deal with a Compulsive liarHow to deal with a Compulsive liar
How to deal with a Compulsive liar
 
Driverless car Google
Driverless car GoogleDriverless car Google
Driverless car Google
 
Podcast tips beginners
Podcast tips beginnersPodcast tips beginners
Podcast tips beginners
 
Vastu for Career Success
Vastu for Career SuccessVastu for Career Success
Vastu for Career Success
 
Reliance jio broadband
Reliance jio broadbandReliance jio broadband
Reliance jio broadband
 
Job Satisfaction definition
Job Satisfaction definitionJob Satisfaction definition
Job Satisfaction definition
 
Mistakes in Advertising
Mistakes in AdvertisingMistakes in Advertising
Mistakes in Advertising
 
Contributor in a sentence
Contributor in a sentenceContributor in a sentence
Contributor in a sentence
 
Different Routing protocols
Different Routing protocolsDifferent Routing protocols
Different Routing protocols
 
Ad hoc network routing protocols
Ad hoc network routing protocolsAd hoc network routing protocols
Ad hoc network routing protocols
 
IPTV Thesis
IPTV ThesisIPTV Thesis
IPTV Thesis
 
Latest Thesis Topics for Fog computing
Latest Thesis Topics for Fog computingLatest Thesis Topics for Fog computing
Latest Thesis Topics for Fog computing
 
Latest Research Topics On Flying Ad-Hoc Networks (FANETs):
Latest Research Topics On Flying Ad-Hoc Networks (FANETs):Latest Research Topics On Flying Ad-Hoc Networks (FANETs):
Latest Research Topics On Flying Ad-Hoc Networks (FANETs):
 

Recently uploaded

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxSCMS School of Architecture
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsmeharikiros2
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)ChandrakantDivate1
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARKOUSTAV SARKAR
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...ronahami
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.Kamal Acharya
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257subhasishdas79
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxpritamlangde
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...josephjonse
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptAfnanAhmad53
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesChandrakantDivate1
 

Recently uploaded (20)

Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Query optimization and processing for advanced database systems
Query optimization and processing for advanced database systemsQuery optimization and processing for advanced database systems
Query optimization and processing for advanced database systems
 
Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)Introduction to Artificial Intelligence ( AI)
Introduction to Artificial Intelligence ( AI)
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...Max. shear stress theory-Maximum Shear Stress Theory ​  Maximum Distortional ...
Max. shear stress theory-Maximum Shear Stress Theory ​ Maximum Distortional ...
 
Employee leave management system project.
Employee leave management system project.Employee leave management system project.
Employee leave management system project.
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...8th International Conference on Soft Computing, Mathematics and Control (SMC ...
8th International Conference on Soft Computing, Mathematics and Control (SMC ...
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Computer Graphics Introduction To Curves
Computer Graphics Introduction To CurvesComputer Graphics Introduction To Curves
Computer Graphics Introduction To Curves
 

Introduction to Input/Output Functions in C

  • 1. For more Https://www.ThesisScientist.com Unit 4 Input/Output Functions Introduction to Input/Output Input refers to accepting data while output refers to presenting data. Normally the data is accepted from keyboard and is outputted onto the screen. C language has a series of standard input-output (I/O) functions. Such I/O functions together form a library named stdio.h. Irrespective of the version of C language, user will have access to all such library functions. These library functions are classified into three broad categories. a) Console I/O functions : Functions which accept input from keyboard and produce output on the screen. b) Disk I/O functions : Functions which perform I/O operations on secondary storage devices like floppy disks or hard disks. c) Port I/O functions : Functions which perform I/O operations on various ports like printer port, mouse port, etc. Console I/O Functions Console I/O refers to the operations that occur at the keyboard and the screen of your computer. Console I/O functions can be further classified as:   Formatted Console I/O  Unformatted Console I/O The basic difference between formatted and unformatted I/O functions is that the formatted I/O functions allow input and output to be formatted as per the requirements of the user.
  • 2. Console I/O Functions Formatted Functions Unformatted Functions Type Input Output Type Input Output char scanf( ) printf( ) int scanf( ) printf( ) float scanf( ) printf( ) string scanf( ) printf( ) char getch( ) getche( ) getchar( ) putch( ) putchar( ) int - - float - - string gets( ) puts( ) Console I/O Functions Formatted Functions Unformatted Functions Type Input Output Type Input Output char scanf( ) printf( ) int scanf( ) printf( ) float scanf( ) printf( ) string scanf( ) printf( ) char getch( ) getche( ) getchar( ) putch( ) putchar( ) int - - float - - string gets( ) puts( ) Formatted Console I/O Functions Formatted I/O functions accept or present the data in a particular format. The standard C library consists of two functions that perform output and input, viz., printf( ) and scanf( ). These functions can format the information under the user's directions. Formatted Output It is highly desirable that the outputs are presented in such a way that they are understandable and are in a form easy to use. The printf( ) statement provides certain features through which the screen output is effectively controlled. The general form of printf( ) function is: printf ("Control String", arg1, arg2. . . ); Control string may contain:  Characters that are simply printed as they are.  Conversion specifications that begin with a % sign.  Escape sequences that begin with sign.
  • 3. The control string indicates how many arguments follow and what their types are. The arguments arg1, arg2. . . are the variables whose values are formatted and printed according to specifications of the control string. The arguments must match in number, order, and type with the format specifications. e.g.: main( ) { int arg = 346; float per = 69.2; printf ("Average = % d n percentage = % f", arg, per); } output: Average = 346 Percentage = 69.2 Conversion Specifications The conversion specifications are used to provide the type and size of the data. Each conversion specification must begin with %. In the above example %d and %f are the conversion characters. The general form of conversion specifier is % fws fx where fws = field width specifier fx = format specifier The field width specifier tells printf( ) how many columns on the screen should be used while printing a value. e.g.: %7d tells to print the variable as a decimal integer in the field of 7 columns. If we include a minus sign in conversion specification (e.g., % - 7d), this means left justification is desired and the value will be padded with blanks on the right. Given below is a list of conversion characters that can be used with the printf( ) function. Data Type Conversion Character short signed %d or % i Integer short unsigned % u Long signed % ld Long unsigned % lu unsigned hexadecimal % x unsigned octal % 0 float % f Real double % lf signed character % c character unsigned character % c String % s
  • 4. Escape Sequences The backslash symbol () is considered as escape character because it causes an escape from the normal interpretation of a string, so that the next character is recognized as the one having special meaning. Escape sequence Purpose Escape sequence Purpose n New line t Tab b Backspace r Carriage return f formfeed a Alert ' single quote " Double Quote Backslash Output of Integer Numbers The format specification for printing an integer number is %wd where 'w' specifies minimum width for the output. The number is written right justified in the given field width. e.g.: printf ("%d", 12345); 12345 printf ("%10d", 12345); 12345 printf ("% 010d", 12345); 0000012345 printf ("% -10d", 12345); 12345 Output of Real Numbers The real number is displayed in decimal notation with format specification % w.pf where'w' is the integer which represents the minimum number of positions that are to be used and 'p' indicates that in the total width, how many numbers will be placed after the decimal point. e.g.: printf ("%7.4f", 98.7654); 98.7654 printf ("%7.2", 98.7654); 98.77 printf ("%f", 98.7654); 98.7654 Printing of Single Character A single character can be displayed in a desired position using format %wc. By default, the character will be displayed right justified in a field of 'w' columns. To make it left justified, place a minus sign in format specification. Formatted Input Formatted input refers to an input data that has been arranged in a particular format. For the formatted input we use the function scanf( ).
  • 5. scanf( ) Function scanf( ) function, allows us to read formatted data and automatically convert numeric information into integers and float. The general from of scanf( ) is scanf ("control string", arg1, arg2, . . . . . ); Control string specifies the field format in which data is to be entered and the arguments arg1, arg2 - - - - - specify the ADDRESS OF LOCATION where value is to be stored. Control string and arguments are separated by commas. Given below is a list of format specifier used to read the inputs: Code Meaning Code Meaning % c Read a single character % d Read a decimal integer % ld Read a long integer % i Read a decimal, or hexadecimal or octal integer % e Read a floating point number % f Read a floating point number % h Read a short integer % o Read an octal number % s Read a string % x Read a hexadecimal number % p Read a pointer % n Read an integer value equal to the number of characters read so far. Input of Integer Numbers The format specification for reading an integer number is % wd where (%) sign indicates conversion specification, 'w' is the integer number for field width specification and 'd' indicates that the number is to be read in integer mode. e.g.: scanf ("% 2d % 5d", & n1, &n2); An input field may be skipped by specifying * in place of field width. e.g.: scanf ("% 2d % * d % 6d", &n1, &n2);