SlideShare a Scribd company logo
MANAGING INPUT AND OUTPUT OPERATIONS
REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY
MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
The operations which took place in order to take data and make
the display of the processed information are known as input &
output operations.
In C language, in general, user use scanf and printf functions for
input and output purpose respectively. The proper uses of these
functions are termed management of input & output operation.
There are also many functions which are used in C programming.
There exists several functions in ‘C’ language that can carry out
input output operations. These functions are collectively known
as standard Input/Output Library. Each program that uses
standard input / out put function must contain the statement.
Reading a character:
The basic operation done in input output is to read a characters from the
standard input device such as the keyboard and to output or writing it to
the output unit usually the screen.
The getchar function can be used to read a character from the standard
input device. This can also be done with the help of the scanf function.
The getchar has the following form.
variable name = getchar( );
variable name is a valid ‘C’ variable, that has been declared already and
that possess the type char.
# include < stdio.h >
void main ( )
{
char ch;
printf (“Type one character:”) ;
ch = getchar() ;
printf (” The character you typed is = %c”, ch) ;
}
Writing a character:-
The putchar function which in analogus to getchar function can be
used for writing characters one at a time to the output terminal.
The general form is
putchar (variable name);
Where variable is a valid C type variable that has already been declared
Ex:- putchar(ch);
Displays the value stored in variable C to the standard screen.
#include < stdio.h >
void main ( )
{
char in;
printf (” please enter one character”);
in = getchar ( ) ;
putchar (in);
}
Character test functions
C supports some character test functions that are contained in the file ctype.h and therefore the
statement. #include<ctype.h> must be included in the program.
Function Test
isalnum(c) is c an alphanumeric character
isalpha(c) is c an alphabetic character
isdigit(c) is c a digit
islower(c) is c a lowercase letter
isprint(c) is c a printable character
isupper(c) Is c an uppercase letter
ispunct(c) Is c a punctuation mark
isspace(c) Is c a white space character
Formatted Input:
The formatted input refers to input data that has been arranged in a
particular format. Input values are generally taken by using the scanf
function.
The scanf function has the general form:-
scanf (“control string”, arg1, arg2, arg3 ………….argn);
The format field is specified by the control string and the arguments arg1,
arg2, …...,argn specifies the address of location where address is to be
stored.
The control string specifies the field format which includes format
specifications and optional number specifying field width and the
conversion character % and also blanks, tabs and newlines.
The Blanks tabs and newlines are ignored by compiler. The
conversion character % is followed by the type of data that is to be assigned
to variable of the assignment. The field width specifier is optional.
Inputting Integer Numbers:-
The general format for reading a integer number is
% wd
Here percent sign (%) denotes that a specifier for conversion follows
and
w is an integer number which specifies the width of the field of the number
that is being read. The data type character d indicates that the number should
be read in integer mode.
Example : scanf (“%3d %4d”, &sum1, &sum2);
If the values input are 175 and 1342 here value 175 is assigned to sum1
and 1342 to sum 2.
Suppose the input data was follows 1342 and 175.
The number 134 will be assigned to sum1 and sum2 has the value 2
because of %3d the number 1342 will be cut to 134 and the remaining part is
assigned to second variable sum2.
If floating point numbers are assigned then the decimal or fractional part is
skipped by the computer.
To read the long integer data type we can use conversion specifier % ld & % hd
for short integer.
Inputting real numbers:
Unlike integer numbers, field specifications are not to be used
while representing a real number therefore real numbers are specified
in a straight forward manner using % f specifier.
The general format of specifying a real number input is
scanf (“% f “, &variable);
Example: scanf (“%f %f % f”, &a, &b, &c);
With the input data 321.76, 4.321, 678. The values 321.76 is assigned
to a , 4.321 to b & 678 to C.
If the number input is a double data type then the format specifier
should be % lf instead of %f.
Inputting character strings:
Single character or strings can be input by using the character
specifiers.
The general format is % wc or %ws
Where c and s represents character and string respectively and w
represents the field width.
The address operator need not be specified while we input
strings.
The specification %s terminates reading at the encounter of a
blank space.
Example : scanf (“%c %15s”, &ch, name):
Some versions of scanf support the following conversion specifications
for strings:-
%[characters]
%[^characters]
The specification %[characters] means that only the characters
specified within the brackets are permissible in the output string. If
the input string contains any other character, the string will be
terminated at the first encounter of such a character.
The specification %[^characters] does not permit the characters
specified after the circumflex(^) in the input string.
Reading mixed Data types:-
scanf statement can also be used to input a data line
containing mixed mode data.
For example:
scanf(“%d %c %f %s”, &count, &code, &ratio, name};
Formatted Output:-
Printf function is used to produce the outputs in such a way that they are
understandable and are in an easy to use form.
The general form of printf statement is
printf(“control string”, &arg1,&arg2,……….argn);
Control string consists of 3 types of items:
•Characters that will be printed on the screen as they appear.
•Format specifications that define the output format for display of each item.
•Escape sequence characters such as n, t and b.
The arguments arg1, arg2,……argn are the variables whose values are
formatted and printed according to the specifications of the control string.
A simple format specification has the following form:
% w.p type-specifier
Where w is an integer number that specifies the total
number of columns for the output value and
p is another integer number that specifies the number of digits
to the right of the decimal point or the number of characters to
be printed from a string.
A newline can be introduced by the help of a newline character.
For example:- printf (“Enter 2 numbers”);
For example
#include < stdio.h >
main ( )
{
printf (“Hello!”);
printf (“Welcome to the world of Engineering!”);
}
Output:
Hello! Welcome to the world of Engineering.
For Example :
printf (“Hello!n”);
OR
printf (“n Welcome to the world of Engineering”);
Output of integer numbers:-
The format specification for printing an integer number is
%wd
Where
w specifies the minimum field width for the output.
d specifies that the value to be printed is an integer.
For example:
printf(“%d”,9876);
printf(“%6d”, 9876)
printf(“%2d”, 9876);
printf(“%-6d”, 9876);
printf(“%06d”, 9876);
It is possible to force the printing to be left-justified by placing a
minus sign directly after the % character.
It is also possible to place zeroes before the field width as
shown in the last example.
Output of Real Numbers:-
The output of a real number may be displayed in decimal notation using
the following format specification:
% w.pf
The integer w indicates the minimum number of positions that are to
be used for the display of the value and the integer p indicates the number
of digits to be displayed after the decimal point.
The value, when displayed, is rounded to p decimal places and printed right-
justified in the field of w columns. Leading blanks and trailing zeros will
appear as necessary. The default precision is 6 decimal places. The negative
numbers will be printed with the minus sign.
y=98.7654
printf(“%7.2f”, y);
printf(“%-7.2f”, y);
printf(“%f”, y);
printf(“%10.2e”,y);
printf(“%11.4e”,-y);
printf(“%-10.2e”,y);
printf(“%e”,y);
printf(“%7.4f”, y)
Printing a single character:-
A single character can be displayed in a desired position using
the format:
%wc
The character will be displayed right-justified in the field of w
columns. We can make the display left-justified by placing a minus
sign before the integer w.
The default value for w is 1.
Printing of Strings:-
The format specification for outputting strings is similar to
that of real numbers that is
%w.ps
Where w specifies the field width for display and p instructs that
only the first p characters of the string are to be displayed. The
display is right-justified.
For example: Printing the string “NEW DELHI 110001”.
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
6 7 8 9 0
%s
%20s
%20.10s
%.5s
%-20.10s
%5s
Mixed Data Output:-
It is permitted to mix data types in one printf statement.
For example:-
printf(%d %f %s %c”, a, b, c, d);
printf uses its control string to decide how many variables
to be printed and what their types are. Therefore, the
format specifications should match the variables in
number, order, and type.
Specifier Meaning
%c – Print a character
%d – Print a Integer
%i – Print a Integer
%e – Print float value in exponential form.
%f – Print float value
%g – Print using %e or %f whichever is smaller
%o – Print actual value
%s – Print a string
%x – Print a hexadecimal integer (Unsigned) using lower case a – F
%X – Print a hexadecimal integer (Unsigned) using upper case A – F
%a – Print a unsigned integer.
%p – Print a pointer value
%hx – hex short
%lo – octal long
%ld – long

More Related Content

What's hot

Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
Appili Vamsi Krishna
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
Sowmya Jyothi
 
structure and union
structure and unionstructure and union
structure and unionstudent
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
Sowmya Jyothi
 
Function in C
Function in CFunction in C
Function in C
Dr. Abhineet Anand
 
C string
C stringC string
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
Thesis Scientist Private Limited
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
Sathish Narayanan
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
yndaravind
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
Ashim Lamichhane
 
String in c
String in cString in c
String in c
Suneel Dogra
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in CSahithi Naraparaju
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
madan reddy
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
MOHAMAD NOH AHMAD
 

What's hot (20)

Pointers C programming
Pointers  C programmingPointers  C programming
Pointers C programming
 
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdfUSER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
USER DEFINED FUNCTIONS IN C MRS.SOWMYA JYOTHI.pdf
 
Overview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya JyothiOverview of C Mrs Sowmya Jyothi
Overview of C Mrs Sowmya Jyothi
 
structure and union
structure and unionstructure and union
structure and union
 
Unit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in cUnit ii chapter 1 operator and expressions in c
Unit ii chapter 1 operator and expressions in c
 
Function
FunctionFunction
Function
 
Function in C
Function in CFunction in C
Function in C
 
C string
C stringC string
C string
 
Introduction to Input/Output Functions in C
Introduction to Input/Output Functions in CIntroduction to Input/Output Functions in C
Introduction to Input/Output Functions in C
 
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdfPOINTERS IN C MRS.SOWMYA JYOTHI.pdf
POINTERS IN C MRS.SOWMYA JYOTHI.pdf
 
Control statements in c
Control statements in cControl statements in c
Control statements in c
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
String in c
String in cString in c
String in c
 
constants, variables and datatypes in C
constants, variables and datatypes in Cconstants, variables and datatypes in C
constants, variables and datatypes in C
 
Function in c program
Function in c programFunction in c program
Function in c program
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 

Similar to MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf

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
 
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
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
mohd_mizan
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
input
inputinput
input
teach4uin
 
string , pointer
string , pointerstring , pointer
string , pointer
Arafat Bin Reza
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
simranjotsingh2908
 
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
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)indrasir
 
Chapter3
Chapter3Chapter3
Chapter3
Kamran
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143
alish sha
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
Rai University
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
ShreyaSingh291866
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
teach4uin
 

Similar to MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf (20)

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
 
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
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
input
inputinput
input
 
string , pointer
string , pointerstring , pointer
string , pointer
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
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’
 
C tutoria input outputl
C tutoria input outputlC tutoria input outputl
C tutoria input outputl
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)C basics 4 std11(GujBoard)
C basics 4 std11(GujBoard)
 
Chapter3
Chapter3Chapter3
Chapter3
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
Chap 2 input output dti2143
Chap 2  input output dti2143Chap 2  input output dti2143
Chap 2 input output dti2143
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
T03 b basicioscanf
T03 b basicioscanfT03 b basicioscanf
T03 b basicioscanf
 

Recently uploaded

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
Celine George
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
EduSkills OECD
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
AzmatAli747758
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
MIRIAMSALINAS13
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
PedroFerreira53928
 

Recently uploaded (20)

2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS ModuleHow to Split Bills in the Odoo 17 POS Module
How to Split Bills in the Odoo 17 POS Module
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...Cambridge International AS  A Level Biology Coursebook - EBook (MaryFosbery J...
Cambridge International AS A Level Biology Coursebook - EBook (MaryFosbery J...
 
Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......Ethnobotany and Ethnopharmacology ......
Ethnobotany and Ethnopharmacology ......
 
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXXPhrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
Phrasal Verbs.XXXXXXXXXXXXXXXXXXXXXXXXXX
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
Basic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumersBasic phrases for greeting and assisting costumers
Basic phrases for greeting and assisting costumers
 

MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf

  • 1. MANAGING INPUT AND OUTPUT OPERATIONS REFERENCE: PROGRAMMING IN C BY BALAGURUSWAMY MRS. SOWMYA JYOTHI, SDMCBM, MANGALORE
  • 2. The operations which took place in order to take data and make the display of the processed information are known as input & output operations. In C language, in general, user use scanf and printf functions for input and output purpose respectively. The proper uses of these functions are termed management of input & output operation. There are also many functions which are used in C programming. There exists several functions in ‘C’ language that can carry out input output operations. These functions are collectively known as standard Input/Output Library. Each program that uses standard input / out put function must contain the statement.
  • 3. Reading a character: The basic operation done in input output is to read a characters from the standard input device such as the keyboard and to output or writing it to the output unit usually the screen. The getchar function can be used to read a character from the standard input device. This can also be done with the help of the scanf function. The getchar has the following form. variable name = getchar( ); variable name is a valid ‘C’ variable, that has been declared already and that possess the type char.
  • 4. # include < stdio.h > void main ( ) { char ch; printf (“Type one character:”) ; ch = getchar() ; printf (” The character you typed is = %c”, ch) ; }
  • 5. Writing a character:- The putchar function which in analogus to getchar function can be used for writing characters one at a time to the output terminal. The general form is putchar (variable name); Where variable is a valid C type variable that has already been declared Ex:- putchar(ch); Displays the value stored in variable C to the standard screen.
  • 6. #include < stdio.h > void main ( ) { char in; printf (” please enter one character”); in = getchar ( ) ; putchar (in); }
  • 7. Character test functions C supports some character test functions that are contained in the file ctype.h and therefore the statement. #include<ctype.h> must be included in the program. Function Test isalnum(c) is c an alphanumeric character isalpha(c) is c an alphabetic character isdigit(c) is c a digit islower(c) is c a lowercase letter isprint(c) is c a printable character isupper(c) Is c an uppercase letter ispunct(c) Is c a punctuation mark isspace(c) Is c a white space character
  • 8. Formatted Input: The formatted input refers to input data that has been arranged in a particular format. Input values are generally taken by using the scanf function. The scanf function has the general form:- scanf (“control string”, arg1, arg2, arg3 ………….argn); The format field is specified by the control string and the arguments arg1, arg2, …...,argn specifies the address of location where address is to be stored. The control string specifies the field format which includes format specifications and optional number specifying field width and the conversion character % and also blanks, tabs and newlines. The Blanks tabs and newlines are ignored by compiler. The conversion character % is followed by the type of data that is to be assigned to variable of the assignment. The field width specifier is optional.
  • 9. Inputting Integer Numbers:- The general format for reading a integer number is % wd Here percent sign (%) denotes that a specifier for conversion follows and w is an integer number which specifies the width of the field of the number that is being read. The data type character d indicates that the number should be read in integer mode.
  • 10. Example : scanf (“%3d %4d”, &sum1, &sum2); If the values input are 175 and 1342 here value 175 is assigned to sum1 and 1342 to sum 2. Suppose the input data was follows 1342 and 175. The number 134 will be assigned to sum1 and sum2 has the value 2 because of %3d the number 1342 will be cut to 134 and the remaining part is assigned to second variable sum2. If floating point numbers are assigned then the decimal or fractional part is skipped by the computer. To read the long integer data type we can use conversion specifier % ld & % hd for short integer.
  • 11. Inputting real numbers: Unlike integer numbers, field specifications are not to be used while representing a real number therefore real numbers are specified in a straight forward manner using % f specifier. The general format of specifying a real number input is scanf (“% f “, &variable); Example: scanf (“%f %f % f”, &a, &b, &c); With the input data 321.76, 4.321, 678. The values 321.76 is assigned to a , 4.321 to b & 678 to C. If the number input is a double data type then the format specifier should be % lf instead of %f.
  • 12. Inputting character strings: Single character or strings can be input by using the character specifiers. The general format is % wc or %ws Where c and s represents character and string respectively and w represents the field width. The address operator need not be specified while we input strings. The specification %s terminates reading at the encounter of a blank space.
  • 13. Example : scanf (“%c %15s”, &ch, name): Some versions of scanf support the following conversion specifications for strings:- %[characters] %[^characters] The specification %[characters] means that only the characters specified within the brackets are permissible in the output string. If the input string contains any other character, the string will be terminated at the first encounter of such a character. The specification %[^characters] does not permit the characters specified after the circumflex(^) in the input string.
  • 14. Reading mixed Data types:- scanf statement can also be used to input a data line containing mixed mode data. For example: scanf(“%d %c %f %s”, &count, &code, &ratio, name};
  • 15. Formatted Output:- Printf function is used to produce the outputs in such a way that they are understandable and are in an easy to use form. The general form of printf statement is printf(“control string”, &arg1,&arg2,……….argn); Control string consists of 3 types of items: •Characters that will be printed on the screen as they appear. •Format specifications that define the output format for display of each item. •Escape sequence characters such as n, t and b. The arguments arg1, arg2,……argn are the variables whose values are formatted and printed according to the specifications of the control string.
  • 16. A simple format specification has the following form: % w.p type-specifier Where w is an integer number that specifies the total number of columns for the output value and p is another integer number that specifies the number of digits to the right of the decimal point or the number of characters to be printed from a string. A newline can be introduced by the help of a newline character. For example:- printf (“Enter 2 numbers”);
  • 17. For example #include < stdio.h > main ( ) { printf (“Hello!”); printf (“Welcome to the world of Engineering!”); } Output: Hello! Welcome to the world of Engineering. For Example : printf (“Hello!n”); OR printf (“n Welcome to the world of Engineering”);
  • 18. Output of integer numbers:- The format specification for printing an integer number is %wd Where w specifies the minimum field width for the output. d specifies that the value to be printed is an integer.
  • 19. For example: printf(“%d”,9876); printf(“%6d”, 9876) printf(“%2d”, 9876); printf(“%-6d”, 9876); printf(“%06d”, 9876); It is possible to force the printing to be left-justified by placing a minus sign directly after the % character. It is also possible to place zeroes before the field width as shown in the last example.
  • 20. Output of Real Numbers:- The output of a real number may be displayed in decimal notation using the following format specification: % w.pf The integer w indicates the minimum number of positions that are to be used for the display of the value and the integer p indicates the number of digits to be displayed after the decimal point. The value, when displayed, is rounded to p decimal places and printed right- justified in the field of w columns. Leading blanks and trailing zeros will appear as necessary. The default precision is 6 decimal places. The negative numbers will be printed with the minus sign. y=98.7654
  • 21. printf(“%7.2f”, y); printf(“%-7.2f”, y); printf(“%f”, y); printf(“%10.2e”,y); printf(“%11.4e”,-y); printf(“%-10.2e”,y); printf(“%e”,y); printf(“%7.4f”, y)
  • 22. Printing a single character:- A single character can be displayed in a desired position using the format: %wc The character will be displayed right-justified in the field of w columns. We can make the display left-justified by placing a minus sign before the integer w. The default value for w is 1.
  • 23. Printing of Strings:- The format specification for outputting strings is similar to that of real numbers that is %w.ps Where w specifies the field width for display and p instructs that only the first p characters of the string are to be displayed. The display is right-justified. For example: Printing the string “NEW DELHI 110001”. 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
  • 25. Mixed Data Output:- It is permitted to mix data types in one printf statement. For example:- printf(%d %f %s %c”, a, b, c, d); printf uses its control string to decide how many variables to be printed and what their types are. Therefore, the format specifications should match the variables in number, order, and type.
  • 26. Specifier Meaning %c – Print a character %d – Print a Integer %i – Print a Integer %e – Print float value in exponential form. %f – Print float value %g – Print using %e or %f whichever is smaller %o – Print actual value %s – Print a string %x – Print a hexadecimal integer (Unsigned) using lower case a – F %X – Print a hexadecimal integer (Unsigned) using upper case A – F %a – Print a unsigned integer. %p – Print a pointer value %hx – hex short %lo – octal long %ld – long