SlideShare a Scribd company logo
Data Input and Output
Md. Imran Hossain Showrov (showrovsworld@gmail.com)
8
1
Outline
 Input/Output Functions
 Single Character Input
 Single Character Output
 The scanf Function
 The printf Function
Input/Output Functions
 There are several library functions which includes a
number of input/output functions.
 Six common functions are: getchar, putchar, scanf,
printf, get and puts.
 These six functions permit the transfer of
information between the computer and the standard
input/output devices.
Single Character Input- The getchar Functions
 Single character can be entered into the computer
using getchar.
 It returns a single character from standard input
device(typically keyboard).
 Can be represented as:
character variable = getchar()
 Where, character variable refers to some previously
declared character variable.
Single Character Input- The getchar Functions
(cont..)
 Example:
char c;
………
c = getchar();
The first statement declares that c is a character-type
variable. The second statement causes a single character to
be entered from the standard input device and then assigned
to c.
Single Character Output- The putchar Functions
 Single character can be displayed using putchar.
 This function is complementary to the character input
function getchar.
 It transmits a single character to a standard output device.
 Can be represented as
putchar(character variable)
Single Character Output- The putchar Functions
(cont..)
 Example:
char c;
………
putchar();
The first statement declares that c is a character-type variable. The
second statement causes the current value of c to be transmitted to
the standard output device where it will be displayed.
Example 1: getchar and putchar
#include<stdio.h>
#include<ctype.h>
main()
{
char ch;
printf(“Enter any character value: ”);
ch = getchar();
printf(“The equivalent upper case: ”);
putchar(toupper(ch));
}
Example 1: getchar and putchar (cont..)
This program converts lowercase to uppercase.
Sample input: a
Sample output: A
Sample input: d
Sample output: D
Sample input: l
Sample output: L
Entering Input Data- The scanf Function
 The scanf() function reads data from the standard
input stream stdin into the locations given by each
entry in argument-list.
 A non-whitespace character causes the scanf()
function to read, but not to store, a matching non-
whitespace character.
The scanf Function
 The skeletal structure is:
#include<stdio.h>
main()
{
int a,b,c;
…………..
scanf(“%d %d %d”, &a, &b, &c);
………………..
}
The scanf Function (cont..)
 Consider the last skeleton-
When the program is executed, three integer quantities will be entered
1 2 3
Then the following assignments will result:
a = 1, b = 2, c = 3
If the data had been entered as
123 456 789
Than the assignment would be
a = 123, b = 456, c = 789
The scanf Function (cont..)
 Example:
#include<stdio.h>
main()
{
int i;
float x;
char c;
…………….
scanf(“%3d %5f %c”, &l, &x, &c);
………………………
}
The scanf Function (cont..)
 If the data items are entered as
10 256.875 T
When the program is executed, then 10 will be assigned to I,
256.8 will be assigned to x and the character 7 will be assigned to
c. The remaining two input characters (5 and T) will be ignored.
The printf Function
 Output data can be written from the computer onto a
standard output device using the library function printf.
printf(control string, arg1, arg2, ….. , argn)
 Where control string refers to a string that controls
formatting information, and arg1, arg2…… argn are
arguments that represent the individual output data
items.
The printf Function (cont..)
 Commonly used conversion characters for data i/o
The printf Function (cont..)
 The following C program illustrates the use of the minimum field
width feature,
#include<stdio.h>
main()
{
int i = 12345;
float x = 345.678;
printf(“%3d %5d %8dnn”,i,i,i);
printf(“%3f %10f %13fnn”,x,x,x);
}
The printf Function (cont..)
 When the program is executed, the following output is
generated
12345 12345 12345
345.678000 345.678000 345.678000
 The first and second line of output displays a decimal
integer using three different minimum field widths.
Lecture 8- Data Input and Output

More Related Content

What's hot (20)

C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
Dr. SURBHI SAROHA
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
Dr. SURBHI SAROHA
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
Md. Imran Hossain Showrov
 
Python Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and FunctionsPython Unit 3 - Control Flow and Functions
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
Dr. SURBHI SAROHA
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
Vikram Nandini
 
7 functions
7  functions7  functions
7 functions
MomenMostafa
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
MomenMostafa
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
tanmaymodi4
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
narmadhakin
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
Vikram Nandini
 
Input And Output
 Input And Output Input And Output
Input And Output
Ghaffar Khan
 
functions in C
functions in Cfunctions in C
functions in C
Mehwish Mehmood
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
ANJALAI AMMAL MAHALINGAM ENGINEERING COLLEGE
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
Lập trình C
Lập trình CLập trình C
Lập trình C
Viet NguyenHoang
 
[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++[ITP - Lecture 16] Structures in C/C++
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 

Similar to Lecture 8- Data Input and Output (20)

POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
3_Input_output.pdf this is about orogramminy
3_Input_output.pdf this is about orogramminy3_Input_output.pdf this is about orogramminy
3_Input_output.pdf this is about orogramminy
sumiyaahmedachol
 
COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
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
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
JavvajiVenkat
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
trupti1976
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
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
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
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
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcyLecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
hamzah7958
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S
 
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
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
String Manipulation Function and Header File Functions
String Manipulation Function and Header File FunctionsString Manipulation Function and Header File Functions
String Manipulation Function and Header File Functions
Bosco Technical Training Society, Don Bosco Technical School (Aff. GGSIP University, New Delhi)
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
3_Input_output.pdf this is about orogramminy
3_Input_output.pdf this is about orogramminy3_Input_output.pdf this is about orogramminy
3_Input_output.pdf this is about orogramminy
sumiyaahmedachol
 
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
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
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
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
Bhavik Vashi
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcyLecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
Lecture-2.pptxefygefyeyyegfygcyewvwvvcvywcy
hamzah7958
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
javaTpoint s
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
Sabik T S
 
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
 
Function in c program
Function in c programFunction in c program
Function in c program
umesh patil
 
C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...C programming is a powerful, general-purpose language used for developing ope...
C programming is a powerful, general-purpose language used for developing ope...
nadeemsk351
 
Ad

More from Md. Imran Hossain Showrov (11)

Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
Md. Imran Hossain Showrov
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
Md. Imran Hossain Showrov
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
Md. Imran Hossain Showrov
 
Lecture 19 - Struct and Union
Lecture 19 - Struct and UnionLecture 19 - Struct and Union
Lecture 19 - Struct and Union
Md. Imran Hossain Showrov
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
Md. Imran Hossain Showrov
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
Md. Imran Hossain Showrov
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
Md. Imran Hossain Showrov
 
Lecture 4- Computer Software and Languages
Lecture 4- Computer Software and LanguagesLecture 4- Computer Software and Languages
Lecture 4- Computer Software and Languages
Md. Imran Hossain Showrov
 
Lecture 3 - Processors, Memory and I/O devices
Lecture 3 - Processors, Memory and I/O devicesLecture 3 - Processors, Memory and I/O devices
Lecture 3 - Processors, Memory and I/O devices
Md. Imran Hossain Showrov
 
Lecture 2 - Introductory Concepts
Lecture 2 - Introductory ConceptsLecture 2 - Introductory Concepts
Lecture 2 - Introductory Concepts
Md. Imran Hossain Showrov
 
Lecture 1- History of C Programming
Lecture 1- History of C Programming Lecture 1- History of C Programming
Lecture 1- History of C Programming
Md. Imran Hossain Showrov
 
Ad

Recently uploaded (20)

Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
Gibson "Secrets to Changing Behaviour in Scholarly Communication: A 2025 NISO...
National Information Standards Organization (NISO)
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18How to Create a Rainbow Man Effect in Odoo 18
How to Create a Rainbow Man Effect in Odoo 18
Celine George
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Strengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptxStrengthened Senior High School - Landas Tool Kit.pptx
Strengthened Senior High School - Landas Tool Kit.pptx
SteffMusniQuiballo
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptxDiptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Diptera: The Two-Winged Wonders, The Fly Squad: Order Diptera.pptx
Arshad Shaikh
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition OecdEnergy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Rose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdfRose Cultivation Practices by Kushal Lamichhane.pdf
Rose Cultivation Practices by Kushal Lamichhane.pdf
kushallamichhame
 
Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.Artificial intelligence Presented by JM.
Artificial intelligence Presented by JM.
jmansha170
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 

Lecture 8- Data Input and Output

  • 1. Data Input and Output Md. Imran Hossain Showrov ([email protected]) 8 1
  • 2. Outline  Input/Output Functions  Single Character Input  Single Character Output  The scanf Function  The printf Function
  • 3. Input/Output Functions  There are several library functions which includes a number of input/output functions.  Six common functions are: getchar, putchar, scanf, printf, get and puts.  These six functions permit the transfer of information between the computer and the standard input/output devices.
  • 4. Single Character Input- The getchar Functions  Single character can be entered into the computer using getchar.  It returns a single character from standard input device(typically keyboard).  Can be represented as: character variable = getchar()  Where, character variable refers to some previously declared character variable.
  • 5. Single Character Input- The getchar Functions (cont..)  Example: char c; ……… c = getchar(); The first statement declares that c is a character-type variable. The second statement causes a single character to be entered from the standard input device and then assigned to c.
  • 6. Single Character Output- The putchar Functions  Single character can be displayed using putchar.  This function is complementary to the character input function getchar.  It transmits a single character to a standard output device.  Can be represented as putchar(character variable)
  • 7. Single Character Output- The putchar Functions (cont..)  Example: char c; ……… putchar(); The first statement declares that c is a character-type variable. The second statement causes the current value of c to be transmitted to the standard output device where it will be displayed.
  • 8. Example 1: getchar and putchar #include<stdio.h> #include<ctype.h> main() { char ch; printf(“Enter any character value: ”); ch = getchar(); printf(“The equivalent upper case: ”); putchar(toupper(ch)); }
  • 9. Example 1: getchar and putchar (cont..) This program converts lowercase to uppercase. Sample input: a Sample output: A Sample input: d Sample output: D Sample input: l Sample output: L
  • 10. Entering Input Data- The scanf Function  The scanf() function reads data from the standard input stream stdin into the locations given by each entry in argument-list.  A non-whitespace character causes the scanf() function to read, but not to store, a matching non- whitespace character.
  • 11. The scanf Function  The skeletal structure is: #include<stdio.h> main() { int a,b,c; ………….. scanf(“%d %d %d”, &a, &b, &c); ……………….. }
  • 12. The scanf Function (cont..)  Consider the last skeleton- When the program is executed, three integer quantities will be entered 1 2 3 Then the following assignments will result: a = 1, b = 2, c = 3 If the data had been entered as 123 456 789 Than the assignment would be a = 123, b = 456, c = 789
  • 13. The scanf Function (cont..)  Example: #include<stdio.h> main() { int i; float x; char c; ……………. scanf(“%3d %5f %c”, &l, &x, &c); ……………………… }
  • 14. The scanf Function (cont..)  If the data items are entered as 10 256.875 T When the program is executed, then 10 will be assigned to I, 256.8 will be assigned to x and the character 7 will be assigned to c. The remaining two input characters (5 and T) will be ignored.
  • 15. The printf Function  Output data can be written from the computer onto a standard output device using the library function printf. printf(control string, arg1, arg2, ….. , argn)  Where control string refers to a string that controls formatting information, and arg1, arg2…… argn are arguments that represent the individual output data items.
  • 16. The printf Function (cont..)  Commonly used conversion characters for data i/o
  • 17. The printf Function (cont..)  The following C program illustrates the use of the minimum field width feature, #include<stdio.h> main() { int i = 12345; float x = 345.678; printf(“%3d %5d %8dnn”,i,i,i); printf(“%3f %10f %13fnn”,x,x,x); }
  • 18. The printf Function (cont..)  When the program is executed, the following output is generated 12345 12345 12345 345.678000 345.678000 345.678000  The first and second line of output displays a decimal integer using three different minimum field widths.