SlideShare une entreprise Scribd logo
1  sur  5
Télécharger pour lire hors ligne
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);

Contenu connexe

Tendances

Tendances (20)

Strings in C
Strings in CStrings in C
Strings in C
 
Strings Functions in C Programming
Strings Functions in C ProgrammingStrings Functions in C Programming
Strings Functions in C Programming
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Looping statements in Java
Looping statements in JavaLooping statements in Java
Looping statements in Java
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
String C Programming
String C ProgrammingString C Programming
String C Programming
 
Typecasting in c
Typecasting in cTypecasting in c
Typecasting in c
 
Function in C
Function in CFunction in C
Function in C
 
Array Of Pointers
Array Of PointersArray Of Pointers
Array Of Pointers
 
Enums in c
Enums in cEnums in c
Enums in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Loops c++
Loops c++Loops c++
Loops c++
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Constants in C Programming
Constants in C ProgrammingConstants in C Programming
Constants in C Programming
 
Data types in C language
Data types in C languageData types in C language
Data types in C language
 
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
 

Similaire à C Input/Output Functions Guide

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

Similaire à C Input/Output Functions Guide (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
 
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
 
Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 

Plus de 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
 

Plus de 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):
 

Dernier

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 

Dernier (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur EscortsRussian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
Russian Call Girls in Nagpur Grishma Call 7001035870 Meet With Nagpur Escorts
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 

C Input/Output Functions Guide

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