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
Ad

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
 
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
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
raghukatagall2
 
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjkPOEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
POEPPSGNHwkejnkweoewnkenjwjewkjewoewkjewijewjk
hanumanthumanideeph6
 
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
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
raghukatagall2
 
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)

*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
*"The Segmented Blueprint: Unlocking Insect Body Architecture"*.pptx
Arshad Shaikh
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
PHYSIOLOGY MCQS By DR. NASIR MUSTAFA (PHYSIOLOGY)
Dr. Nasir Mustafa
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
BÀI TẬP BỔ TRỢ TIẾNG ANH 9 THEO ĐƠN VỊ BÀI HỌC - GLOBAL SUCCESS - CẢ NĂM (TỪ...
Nguyen Thanh Tu Collection
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE  BY sweety Tamanna Mahapatra MSc PediatricAPGAR SCORE  BY sweety Tamanna Mahapatra MSc Pediatric
APGAR SCORE BY sweety Tamanna Mahapatra MSc Pediatric
SweetytamannaMohapat
 

Lecture 8- Data Input and Output

  • 1. Data Input and Output Md. Imran Hossain Showrov (showrovsworld@gmail.com) 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.
  翻译: