SlideShare une entreprise Scribd logo
1  sur  19
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

Contenu connexe

Tendances (20)

C programming(part 3)
C programming(part 3)C programming(part 3)
C programming(part 3)
 
Programming in C (part 2)
Programming in C (part 2)Programming in C (part 2)
Programming in C (part 2)
 
Lecture 13 - Storage Classes
Lecture 13 - Storage ClassesLecture 13 - Storage Classes
Lecture 13 - Storage Classes
 
Lecture 17 - Strings
Lecture 17 - StringsLecture 17 - Strings
Lecture 17 - Strings
 
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
 
C programming(Part 1)
C programming(Part 1)C programming(Part 1)
C programming(Part 1)
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
7 functions
7  functions7  functions
7 functions
 
1 introducing c language
1  introducing c language1  introducing c language
1 introducing c language
 
Decision statements in c language
Decision statements in c languageDecision statements in c language
Decision statements in c language
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
 
Conditional and control statement
Conditional and control statementConditional and control statement
Conditional and control statement
 
C Programming Unit-3
C Programming Unit-3C Programming Unit-3
C Programming Unit-3
 
Input And Output
 Input And Output Input And Output
Input And Output
 
functions in C
functions in Cfunctions in C
functions in C
 
Unit ii ppt
Unit ii pptUnit ii ppt
Unit ii ppt
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers[ITP - Lecture 13] Introduction to Pointers
[ITP - Lecture 13] Introduction to Pointers
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
[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++
 

Similaire à Lecture 8- Data Input and Output

Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta 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 cyazad 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 FocJAYA
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]Abhishek Sinha
 
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 OutputSabik T S
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C LanguageAdnan Khan
 
Function in c program
Function in c programFunction in c program
Function in c programumesh patil
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introductionraghukatagall2
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptSandipPradhan23
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input OutputBharat17485
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSivakumar R D .
 

Similaire à Lecture 8- Data Input and Output (20)

COM1407: Input/ Output Functions
COM1407: Input/ Output FunctionsCOM1407: Input/ Output Functions
COM1407: Input/ Output Functions
 
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
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
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
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
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
 
Unit 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
Data Input and Output
Data Input and OutputData Input and Output
Data Input and Output
 
Input and Output In C Language
Input and Output In C LanguageInput and Output In C Language
Input and Output In C Language
 
Function in c program
Function in c programFunction in c program
Function in c program
 
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
 
C Programming ppt for beginners . Introduction
C Programming ppt for beginners . IntroductionC Programming ppt for beginners . Introduction
C Programming ppt for beginners . Introduction
 
presentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.pptpresentation_functions_1443207686_140676.ppt
presentation_functions_1443207686_140676.ppt
 
Stream Based Input Output
Stream Based Input OutputStream Based Input Output
Stream Based Input Output
 
Sample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.SivakumarSample for Simple C Program - R.D.Sivakumar
Sample for Simple C Program - R.D.Sivakumar
 

Plus de Md. Imran Hossain Showrov (11)

Lecture 22 - Error Handling
Lecture 22 - Error HandlingLecture 22 - Error Handling
Lecture 22 - Error Handling
 
Lecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header FileLecture 21 - Preprocessor and Header File
Lecture 21 - Preprocessor and Header File
 
Lecture 20 - File Handling
Lecture 20 - File HandlingLecture 20 - File Handling
Lecture 20 - File Handling
 
Lecture 19 - Struct and Union
Lecture 19 - Struct and UnionLecture 19 - Struct and Union
Lecture 19 - Struct and Union
 
Lecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional ArrayLecture 16 - Multi dimensional Array
Lecture 16 - Multi dimensional Array
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language Lecture 5 - Structured Programming Language
Lecture 5 - Structured Programming Language
 
Lecture 4- Computer Software and Languages
Lecture 4- Computer Software and LanguagesLecture 4- Computer Software and Languages
Lecture 4- Computer Software and Languages
 
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
 
Lecture 2 - Introductory Concepts
Lecture 2 - Introductory ConceptsLecture 2 - Introductory Concepts
Lecture 2 - Introductory Concepts
 
Lecture 1- History of C Programming
Lecture 1- History of C Programming Lecture 1- History of C Programming
Lecture 1- History of C Programming
 

Dernier

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...PsychoTech Services
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 

Dernier (20)

Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
IGNOU MSCCFT and PGDCFT Exam Question Pattern: MCFT003 Counselling and Family...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 

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.