SlideShare a Scribd company logo
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.
Most read
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
Most read
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);
Most read
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 (20)

Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
Kuppusamy P
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
Java Data Types
Java Data TypesJava Data Types
Java Data Types
Spotle.ai
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Abhilash Nair
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Garbage collection
Garbage collectionGarbage collection
Garbage collection
Somya Bagai
 
Algorithm analysis
Algorithm analysisAlgorithm analysis
Algorithm analysis
sumitbardhan
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Algorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to AlgorithmsAlgorithms Lecture 1: Introduction to Algorithms
Algorithms Lecture 1: Introduction to Algorithms
Mohamed Loey
 
Function in C program
Function in C programFunction in C program
Function in C program
Nurul Zakiah Zamri Tan
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
Mohammed Sikander
 
Strings
StringsStrings
Strings
Mitali Chugh
 
This pointer
This pointerThis pointer
This pointer
Kamal Acharya
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Method overriding
Method overridingMethod overriding
Method overriding
Azaz Maverick
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
Introduction to problem solving in C
Introduction to problem solving in CIntroduction to problem solving in C
Introduction to problem solving in C
Diwakar Pratap Singh 'Deva'
 
Arrays in c
Arrays in cArrays in c
Arrays in c
CHANDAN KUMAR
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
ABHISHEK fulwadhwa
 

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
SowmyaJyothi3
 
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
imtiazalijoono
 
Input And Output
 Input And Output Input And Output
Input And Output
Ghaffar Khan
 
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
niyamathShariff
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
mohd_mizan
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
Adnan Khan
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
Input Output function in c programing language.pptx
Input  Output function in c programing language.pptxInput  Output function in c programing language.pptx
Input Output function in c programing language.pptx
amit0815q
 
2 data and c
2 data and c2 data and c
2 data and c
MomenMostafa
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
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.pdf
SergiuMatei7
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
arnold 7490
 
Unit1 C
Unit1 CUnit1 C
Unit1 C
arnold 7490
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
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
SowmyaJyothi3
 
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
imtiazalijoono
 
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
niyamathShariff
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
Adnan Khan
 
Input Output function in c programing language.pptx
Input  Output function in c programing language.pptxInput  Output function in c programing language.pptx
Input Output function in c programing language.pptx
amit0815q
 
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.pdf
SergiuMatei7
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
vijayapraba1
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
Ad

More from Thesis Scientist Private Limited (20)

HTML guide for beginners
HTML guide for beginnersHTML guide for beginners
HTML guide for beginners
Thesis Scientist Private Limited
 
Ransomware attacks 2017
Ransomware attacks 2017Ransomware attacks 2017
Ransomware attacks 2017
Thesis Scientist Private Limited
 
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?
Thesis Scientist Private Limited
 
Research Process design
Research Process designResearch Process design
Research Process design
Thesis Scientist Private Limited
 
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
Thesis Scientist Private Limited
 
How to write a Research Paper
How to write a Research PaperHow to write a Research Paper
How to write a Research Paper
Thesis Scientist Private Limited
 
Internet security tips for Businesses
Internet security tips for BusinessesInternet security tips for Businesses
Internet security tips for Businesses
Thesis Scientist Private Limited
 
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
Thesis Scientist Private Limited
 
Driverless car Google
Driverless car GoogleDriverless car Google
Driverless car Google
Thesis Scientist Private Limited
 
Podcast tips beginners
Podcast tips beginnersPodcast tips beginners
Podcast tips beginners
Thesis Scientist Private Limited
 
Vastu for Career Success
Vastu for Career SuccessVastu for Career Success
Vastu for Career Success
Thesis Scientist Private Limited
 
Reliance jio broadband
Reliance jio broadbandReliance jio broadband
Reliance jio broadband
Thesis Scientist Private Limited
 
Job Satisfaction definition
Job Satisfaction definitionJob Satisfaction definition
Job Satisfaction definition
Thesis Scientist Private Limited
 
Mistakes in Advertising
Mistakes in AdvertisingMistakes in Advertising
Mistakes in Advertising
Thesis Scientist Private Limited
 
Contributor in a sentence
Contributor in a sentenceContributor in a sentence
Contributor in a sentence
Thesis Scientist Private Limited
 
Different Routing protocols
Different Routing protocolsDifferent Routing protocols
Different Routing protocols
Thesis Scientist Private Limited
 
Ad hoc network routing protocols
Ad hoc network routing protocolsAd hoc network routing protocols
Ad hoc network routing protocols
Thesis Scientist Private Limited
 
IPTV Thesis
IPTV ThesisIPTV Thesis
IPTV Thesis
Thesis Scientist Private Limited
 
Latest Thesis Topics for Fog computing
Latest Thesis Topics for Fog computingLatest Thesis Topics for Fog computing
Latest Thesis Topics for Fog computing
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
 
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
 
Ad

Recently uploaded (20)

Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
A Comprehensive Investigation into the Accuracy of Soft Computing Tools for D...
Journal of Soft Computing in Civil Engineering
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025ACEP Magazine Fifth Edition on 5june2025
ACEP Magazine Fifth Edition on 5june2025
Rahul
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
362 Alec Data Center Solutions-Slysium Data Center-AUH-Glands & Lugs, Simplex...
djiceramil
 
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journeyRigor, ethics, wellbeing and resilience in the ICT doctoral journey
Rigor, ethics, wellbeing and resilience in the ICT doctoral journey
Yannis
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
David Boutry - Mentors Junior Developers
David Boutry - Mentors Junior DevelopersDavid Boutry - Mentors Junior Developers
David Boutry - Mentors Junior Developers
David Boutry
 
First Review PPT gfinal gyft ftu liu yrfut go
First Review PPT gfinal gyft  ftu liu yrfut goFirst Review PPT gfinal gyft  ftu liu yrfut go
First Review PPT gfinal gyft ftu liu yrfut go
Sowndarya6
 
chemistry investigatory project for class 12
chemistry investigatory project for class 12chemistry investigatory project for class 12
chemistry investigatory project for class 12
Susis10
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
Artificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowyArtificial Power 2025 raport krajobrazowy
Artificial Power 2025 raport krajobrazowy
dominikamizerska1
 
operationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagementoperationg systemsdocumentmemorymanagement
operationg systemsdocumentmemorymanagement
SNIGDHAAPPANABHOTLA
 
Présentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptxPrésentation_gestion[1] [Autosaved].pptx
Présentation_gestion[1] [Autosaved].pptx
KHADIJAESSAKET
 
11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)11th International Conference on Data Mining (DaMi 2025)
11th International Conference on Data Mining (DaMi 2025)
kjim477n
 
Ppt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineeringPpt on the related on the solar power system for electric vehicle engineering
Ppt on the related on the solar power system for electric vehicle engineering
ravindrabodke
 
社内勉強会資料_Chain of Thought .
社内勉強会資料_Chain of Thought                           .社内勉強会資料_Chain of Thought                           .
社内勉強会資料_Chain of Thought .
NABLAS株式会社
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 

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);