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)

PPTX
C programming(part 3)
Dr. SURBHI SAROHA
 
PPTX
Programming in C (part 2)
Dr. SURBHI SAROHA
 
PPT
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
PPT
Lecture 17 - Strings
Md. Imran Hossain Showrov
 
PDF
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
PPTX
C programming(Part 1)
Dr. SURBHI SAROHA
 
PPTX
C Programming Unit-2
Vikram Nandini
 
PDF
7 functions
MomenMostafa
 
PDF
1 introducing c language
MomenMostafa
 
PPTX
Decision statements in c language
tanmaymodi4
 
PPTX
Conditional Statement in C Language
Shaina Arora
 
PPTX
Conditional and control statement
narmadhakin
 
PPTX
C Programming Unit-3
Vikram Nandini
 
PPT
Input And Output
Ghaffar Khan
 
PPTX
functions in C
Mehwish Mehmood
 
PPTX
Introduction to Basic C programming 02
Wingston
 
PDF
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
PPT
Lập trình C
Viet NguyenHoang
 
PDF
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 
C programming(part 3)
Dr. SURBHI SAROHA
 
Programming in C (part 2)
Dr. SURBHI SAROHA
 
Lecture 13 - Storage Classes
Md. Imran Hossain Showrov
 
Lecture 17 - Strings
Md. Imran Hossain Showrov
 
Python Unit 3 - Control Flow and Functions
DhivyaSubramaniyam
 
C programming(Part 1)
Dr. SURBHI SAROHA
 
C Programming Unit-2
Vikram Nandini
 
7 functions
MomenMostafa
 
1 introducing c language
MomenMostafa
 
Decision statements in c language
tanmaymodi4
 
Conditional Statement in C Language
Shaina Arora
 
Conditional and control statement
narmadhakin
 
C Programming Unit-3
Vikram Nandini
 
Input And Output
Ghaffar Khan
 
functions in C
Mehwish Mehmood
 
Introduction to Basic C programming 02
Wingston
 
[ITP - Lecture 13] Introduction to Pointers
Muhammad Hammad Waseem
 
Lập trình C
Viet NguyenHoang
 
[ITP - Lecture 16] Structures in C/C++
Muhammad Hammad Waseem
 

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

PPTX
20220823094225_PPT02-Formatted Input and Output.pptx
putrielisabeth3
 
PDF
3_Input_output.pdf this is about orogramminy
sumiyaahmedachol
 
PPTX
Managing input and output operation in c
yazad dumasia
 
PPT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
PPTX
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
PPTX
CHAPTER 4
mohd_mizan
 
PPTX
Input Output function in c programing language.pptx
amit0815q
 
PPTX
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
PDF
Chapter 13.1.3
patcha535
 
DOCX
UNIT-II CP DOC.docx
JavvajiVenkat
 
PPTX
Input and Output In C Language
Adnan Khan
 
PPTX
Unit 3. Input and Output
Ashim Lamichhane
 
PPTX
Ch3 Formatted Input/Output
SzeChingChen
 
PPTX
Data Input and Output
Sabik T S
 
PPTX
Chap 2 input output dti2143
alish sha
 
PPT
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
PDF
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
PPTX
I o functions
Dr.Sandhiya Ravi
 
PPTX
2.1 input and output in c
Jawad Khan
 
PPTX
Btech i pic u-4 function, storage class and array and strings
Rai University
 
20220823094225_PPT02-Formatted Input and Output.pptx
putrielisabeth3
 
3_Input_output.pdf this is about orogramminy
sumiyaahmedachol
 
Managing input and output operation in c
yazad dumasia
 
CPU INPUT OUTPUT
Aditya Vaishampayan
 
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
CHAPTER 4
mohd_mizan
 
Input Output function in c programing language.pptx
amit0815q
 
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
Chapter 13.1.3
patcha535
 
UNIT-II CP DOC.docx
JavvajiVenkat
 
Input and Output In C Language
Adnan Khan
 
Unit 3. Input and Output
Ashim Lamichhane
 
Ch3 Formatted Input/Output
SzeChingChen
 
Data Input and Output
Sabik T S
 
Chap 2 input output dti2143
alish sha
 
Fundamental of C Programming Language and Basic Input/Output Function
imtiazalijoono
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
I o functions
Dr.Sandhiya Ravi
 
2.1 input and output in c
Jawad Khan
 
Btech i pic u-4 function, storage class and array and strings
Rai University
 
Ad

More from Md. Imran Hossain Showrov (11)

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

Recently uploaded (20)

PDF
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
PPTX
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
PPTX
GENERAL BIOLOGY 1 - Subject Introduction
marvinnbustamante1
 
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
PDF
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
PPTX
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
PPTX
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
PPTX
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
PPTX
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PDF
Introduction presentation of the patentbutler tool
MIPLM
 
PDF
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
PPTX
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
PPTX
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
PPTX
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
PPTX
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
PPTX
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
Vani - The Voice of Excellence - Jul 2025 issue
Savipriya Raghavendra
 
Light Reflection and Refraction- Activities - Class X Science
SONU ACADEMY
 
GENERAL BIOLOGY 1 - Subject Introduction
marvinnbustamante1
 
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
 
Lean IP - Lecture by Dr Oliver Baldus at the MIPLM 2025
MIPLM
 
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
IMPORTANT GUIDELINES FOR M.Sc.ZOOLOGY DISSERTATION
raviralanaresh2
 
Marketing Management PPT Unit 1 and Unit 2.pptx
Sri Ramakrishna College of Arts and science
 
How to Send Email From Odoo 18 Website - Odoo Slides
Celine George
 
DIGITAL CITIZENSHIP TOPIC TLE 8 MATATAG CURRICULUM
ROBERTAUGUSTINEFRANC
 
Natural Language processing using nltk.pptx
Ramakrishna Reddy Bijjam
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
Introduction presentation of the patentbutler tool
MIPLM
 
Our Guide to the July 2025 USPS® Rate Change
Postal Advocate Inc.
 
Exploring Linear and Angular Quantities and Ergonomic Design.pptx
AngeliqueTolentinoDe
 
Nitrogen rule, ring rule, mc lafferty.pptx
nbisen2001
 
Iván Bornacelly - Presentation of the report - Empowering the workforce in th...
EduSkills OECD
 
How to Manage Allocation Report for Manufacturing Orders in Odoo 18
Celine George
 
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 

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.