SlideShare une entreprise Scribd logo
1  sur  17
COM1407
Computer Programming
Lecture 10
Input/ Output Functions
K.A.S.H. Kulathilake
B.Sc. (Hons) IT, MCS , M.Phil., SEDA(UK)
Rajarata University of Sri Lanka
Department of Physical Sciences
1
Objectives
• At the end of this lecture students should be able
to;
▫ Define the C standard functions for managing
input output.
▫ Apply taught concepts for writing programs.
2
Input/ Output Methods
• When we say Input, it means to feed some data into
a program.
• An input can be given in the form of a file or from
the command line.
• C programming provides a set of built-in functions
to read the given input and feed it to the program as
per requirement.
• When we say Output, it means to display some data
on screen, printer, or in any file.
• C programming provides a set of built-in functions
to output the data on the computer screen as well as
to save it in text or binary files.
3
Input/ Output Methods (Cont…)
• In order to perform input output functions,
there are some standard C functions.
• Some of the input/ output functions are used to
format the input/ output and the others for
unformatted input/ output.
4
Input/ Output Methods (Cont…)
• The standard files
▫ C programming treats all the devices as files.
▫ So devices such as the display are addressed in the
same way as files and the following three files are
automatically opened when a program executes to
provide access to the keyboard and screen.
5
Standard File File Pointer Device Purpose
Standard input stdin Keyboard Console input from the user
Standard output stdout Screen Message output to the user
Standard error stderr Your screen System error message output to
the user
Input/ Output Methods (Cont…)
• Some standard input output functions are;
▫ getchar
▫ putchar
▫ scanf
▫ printf
▫ gets
▫ puts
• These functions permits the transfer of
information between the computer and the
standard input/output devices.
6
The getchar() and putchar() functions
• The int getchar(void) function reads the next
available character from the screen and returns it as
an integer.
• This function reads only single character at a time.
• You can use this method in the loop in case you want
to read more than one character from the screen.
• The int putchar(int c) function puts the passed
character on the screen and returns the same
character.
• This function puts only single character at a time.
• You can use this method in the loop in case you want
to display more than one character on the screen.
7
The getchar() and putchar() functions
(Cont…)
#include <stdio.h>
int main( )
{
int c;
printf( "Enter a value :");
c = getchar( );
printf( "nYou entered: ");
putchar( c );
return 0;
}
8
The getchar() and putchar() functions
(Cont…)
#include <stdio.h>
int main( )
{
int response;
printf( "Do you wish to learn C language (y/n) : ?");
response = getchar();
if (response == 'y')
printf("nRead the referencen");
else if (response == 'n')
printf("nFollow language you liken");
else
printf("nSorry wrong answern");
return 0;
}
9
The getchar() and putchar() functions
(Cont…)
#include <stdio.h>
int main( )
{
int i;
char let[20] = {'C', ' ', 'P',
'R', 'O', 'G', 'R', 'A', 'M'};
printf ("Your name is : ");
for ( i = 0; i<20; i++)
putchar(let[i]);
return 0;
}
10
The scanf and printf Functions
• scanf(format string, arg1, arg2, ..., argn)
▫ Reads the input from the standard input stream stdin and scans
that input according to the format provided.
▫ Conversion characters
 %c single character
 %d decimal integer
 %e, %f, %g floating point value
 %h short integer
 %i decimal, hexadecimal or octal integer
 %o octal integer
 %s string of characters
 %u unsigned decimal integer
 %x hexadecimal integer
▫ Each variable name must be preceded by an ampersand (&).
▫ However, array names should not begin with an &.
11
The scanf and printf Functions (Cont…)
• printf(format string, arg1, arg2,…., argn)
▫ function writes the output to the standard output
stream stdout and produces the output according to
the format provided.
▫ printf function moves data from the computers
memory to the standard output device.
▫ The format can be a simple constant string, but you
can specify %s, %d, %c, %f, etc., to print or read
strings, integer, character or float respectively.
▫ There are many other formatting options available
which can be used based on requirements.
12
The scanf and printf Functions (Cont…)
#include <stdio.h>
int main( ) {
char str[100];
int i;
printf( "Enter a value :");
scanf("%s %d", str, &i);
i = i * 2;
printf( "nYou entered: %s %d ", str, i);
return 0;
}
13
The gets() and puts() Functions
• The char *gets(char *s) function reads a line
from stdin into the buffer pointed to by s until
either a terminating newline or EOF (End of
File).
• Unlike the scanf fucntion, the gets function
allows to include spaces and other characters.
• The int puts(const char *s) function writes
the string 's' and 'a' trailing newline to stdout.
14
The gets() and puts() Functions (Cont…)
#include <stdio.h>
int main( ) {
char str[100];
printf( "Enter a value :");
gets( str );
printf( "nYou entered: ");
puts( str );
return 0;
}
15
Objective Re-cap
• Now you should be able to:
▫ Define the C standard functions for managing
input output.
▫ Apply taught concepts for writing programs.
16
Next: Working with Pointers
17

Contenu connexe

Tendances

Tendances (20)

Python programming : Files
Python programming : FilesPython programming : Files
Python programming : Files
 
Strings
StringsStrings
Strings
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Methods in Java
Methods in JavaMethods in Java
Methods in Java
 
String in c programming
String in c programmingString in c programming
String in c programming
 
Loops in Python
Loops in PythonLoops in Python
Loops in Python
 
Programming in ansi C by Balaguruswami
Programming in ansi C by BalaguruswamiProgramming in ansi C by Balaguruswami
Programming in ansi C by Balaguruswami
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 
Python programming : Standard Input and Output
Python programming : Standard Input and OutputPython programming : Standard Input and Output
Python programming : Standard Input and Output
 
File handling in C
File handling in CFile handling in C
File handling in C
 
Control statements
Control statementsControl statements
Control statements
 
Strings IN C
Strings IN CStrings IN C
Strings IN C
 
Strings in python
Strings in pythonStrings in python
Strings in python
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 

Similaire à COM1407: Input/ Output Functions

C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 

Similaire à COM1407: Input/ Output Functions (20)

Lecture 8- Data Input and Output
Lecture 8- Data Input and OutputLecture 8- Data Input and Output
Lecture 8- Data Input and Output
 
CP Handout#2
CP Handout#2CP Handout#2
CP Handout#2
 
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
 
Discussing Fundamentals of C
Discussing Fundamentals of CDiscussing Fundamentals of C
Discussing Fundamentals of C
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
UNIT-II CP DOC.docx
UNIT-II CP DOC.docxUNIT-II CP DOC.docx
UNIT-II CP DOC.docx
 
Building Simple C Program
Building Simple  C ProgramBuilding Simple  C Program
Building Simple C Program
 
C programming language tutorial
C programming language tutorial C programming language tutorial
C programming language tutorial
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. AnsariBasic of C Programming | 2022 Updated | By Shamsul H. Ansari
Basic of C Programming | 2022 Updated | By Shamsul H. Ansari
 
Programming Fundamentals lecture 5
Programming Fundamentals lecture 5Programming Fundamentals lecture 5
Programming Fundamentals lecture 5
 
CGI.ppt
CGI.pptCGI.ppt
CGI.ppt
 
270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt270_1_CIntro_Up_To_Functions.ppt
270_1_CIntro_Up_To_Functions.ppt
 
Functions of stdio conio
Functions of stdio   conio Functions of stdio   conio
Functions of stdio conio
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
 
Quiz 9
Quiz 9Quiz 9
Quiz 9
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
C language
C languageC language
C language
 

Plus de Hemantha Kulathilake

Plus de Hemantha Kulathilake (20)

NLP_KASHK:Parsing with Context-Free Grammar
NLP_KASHK:Parsing with Context-Free Grammar NLP_KASHK:Parsing with Context-Free Grammar
NLP_KASHK:Parsing with Context-Free Grammar
 
NLP_KASHK:Context-Free Grammar for English
NLP_KASHK:Context-Free Grammar for EnglishNLP_KASHK:Context-Free Grammar for English
NLP_KASHK:Context-Free Grammar for English
 
NLP_KASHK:POS Tagging
NLP_KASHK:POS TaggingNLP_KASHK:POS Tagging
NLP_KASHK:POS Tagging
 
NLP_KASHK:Markov Models
NLP_KASHK:Markov ModelsNLP_KASHK:Markov Models
NLP_KASHK:Markov Models
 
NLP_KASHK:Smoothing N-gram Models
NLP_KASHK:Smoothing N-gram ModelsNLP_KASHK:Smoothing N-gram Models
NLP_KASHK:Smoothing N-gram Models
 
NLP_KASHK:Evaluating Language Model
NLP_KASHK:Evaluating Language ModelNLP_KASHK:Evaluating Language Model
NLP_KASHK:Evaluating Language Model
 
NLP_KASHK:N-Grams
NLP_KASHK:N-GramsNLP_KASHK:N-Grams
NLP_KASHK:N-Grams
 
NLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit DistanceNLP_KASHK:Minimum Edit Distance
NLP_KASHK:Minimum Edit Distance
 
NLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological ParsingNLP_KASHK:Finite-State Morphological Parsing
NLP_KASHK:Finite-State Morphological Parsing
 
NLP_KASHK:Morphology
NLP_KASHK:MorphologyNLP_KASHK:Morphology
NLP_KASHK:Morphology
 
NLP_KASHK:Text Normalization
NLP_KASHK:Text NormalizationNLP_KASHK:Text Normalization
NLP_KASHK:Text Normalization
 
NLP_KASHK:Finite-State Automata
NLP_KASHK:Finite-State AutomataNLP_KASHK:Finite-State Automata
NLP_KASHK:Finite-State Automata
 
NLP_KASHK:Regular Expressions
NLP_KASHK:Regular Expressions NLP_KASHK:Regular Expressions
NLP_KASHK:Regular Expressions
 
NLP_KASHK: Introduction
NLP_KASHK: Introduction NLP_KASHK: Introduction
NLP_KASHK: Introduction
 
COM1407: File Processing
COM1407: File Processing COM1407: File Processing
COM1407: File Processing
 
COm1407: Character & Strings
COm1407: Character & StringsCOm1407: Character & Strings
COm1407: Character & Strings
 
COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation COM1407: Structures, Unions & Dynamic Memory Allocation
COM1407: Structures, Unions & Dynamic Memory Allocation
 
COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
COM1407: Arrays
COM1407: ArraysCOM1407: Arrays
COM1407: Arrays
 
COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops COM1407: Program Control Structures – Repetition and Loops
COM1407: Program Control Structures – Repetition and Loops
 

Dernier

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
kauryashika82
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

Dernier (20)

Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
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
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
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
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 

COM1407: Input/ Output Functions

  • 1. COM1407 Computer Programming Lecture 10 Input/ Output Functions K.A.S.H. Kulathilake B.Sc. (Hons) IT, MCS , M.Phil., SEDA(UK) Rajarata University of Sri Lanka Department of Physical Sciences 1
  • 2. Objectives • At the end of this lecture students should be able to; ▫ Define the C standard functions for managing input output. ▫ Apply taught concepts for writing programs. 2
  • 3. Input/ Output Methods • When we say Input, it means to feed some data into a program. • An input can be given in the form of a file or from the command line. • C programming provides a set of built-in functions to read the given input and feed it to the program as per requirement. • When we say Output, it means to display some data on screen, printer, or in any file. • C programming provides a set of built-in functions to output the data on the computer screen as well as to save it in text or binary files. 3
  • 4. Input/ Output Methods (Cont…) • In order to perform input output functions, there are some standard C functions. • Some of the input/ output functions are used to format the input/ output and the others for unformatted input/ output. 4
  • 5. Input/ Output Methods (Cont…) • The standard files ▫ C programming treats all the devices as files. ▫ So devices such as the display are addressed in the same way as files and the following three files are automatically opened when a program executes to provide access to the keyboard and screen. 5 Standard File File Pointer Device Purpose Standard input stdin Keyboard Console input from the user Standard output stdout Screen Message output to the user Standard error stderr Your screen System error message output to the user
  • 6. Input/ Output Methods (Cont…) • Some standard input output functions are; ▫ getchar ▫ putchar ▫ scanf ▫ printf ▫ gets ▫ puts • These functions permits the transfer of information between the computer and the standard input/output devices. 6
  • 7. The getchar() and putchar() functions • The int getchar(void) function reads the next available character from the screen and returns it as an integer. • This function reads only single character at a time. • You can use this method in the loop in case you want to read more than one character from the screen. • The int putchar(int c) function puts the passed character on the screen and returns the same character. • This function puts only single character at a time. • You can use this method in the loop in case you want to display more than one character on the screen. 7
  • 8. The getchar() and putchar() functions (Cont…) #include <stdio.h> int main( ) { int c; printf( "Enter a value :"); c = getchar( ); printf( "nYou entered: "); putchar( c ); return 0; } 8
  • 9. The getchar() and putchar() functions (Cont…) #include <stdio.h> int main( ) { int response; printf( "Do you wish to learn C language (y/n) : ?"); response = getchar(); if (response == 'y') printf("nRead the referencen"); else if (response == 'n') printf("nFollow language you liken"); else printf("nSorry wrong answern"); return 0; } 9
  • 10. The getchar() and putchar() functions (Cont…) #include <stdio.h> int main( ) { int i; char let[20] = {'C', ' ', 'P', 'R', 'O', 'G', 'R', 'A', 'M'}; printf ("Your name is : "); for ( i = 0; i<20; i++) putchar(let[i]); return 0; } 10
  • 11. The scanf and printf Functions • scanf(format string, arg1, arg2, ..., argn) ▫ Reads the input from the standard input stream stdin and scans that input according to the format provided. ▫ Conversion characters  %c single character  %d decimal integer  %e, %f, %g floating point value  %h short integer  %i decimal, hexadecimal or octal integer  %o octal integer  %s string of characters  %u unsigned decimal integer  %x hexadecimal integer ▫ Each variable name must be preceded by an ampersand (&). ▫ However, array names should not begin with an &. 11
  • 12. The scanf and printf Functions (Cont…) • printf(format string, arg1, arg2,…., argn) ▫ function writes the output to the standard output stream stdout and produces the output according to the format provided. ▫ printf function moves data from the computers memory to the standard output device. ▫ The format can be a simple constant string, but you can specify %s, %d, %c, %f, etc., to print or read strings, integer, character or float respectively. ▫ There are many other formatting options available which can be used based on requirements. 12
  • 13. The scanf and printf Functions (Cont…) #include <stdio.h> int main( ) { char str[100]; int i; printf( "Enter a value :"); scanf("%s %d", str, &i); i = i * 2; printf( "nYou entered: %s %d ", str, i); return 0; } 13
  • 14. The gets() and puts() Functions • The char *gets(char *s) function reads a line from stdin into the buffer pointed to by s until either a terminating newline or EOF (End of File). • Unlike the scanf fucntion, the gets function allows to include spaces and other characters. • The int puts(const char *s) function writes the string 's' and 'a' trailing newline to stdout. 14
  • 15. The gets() and puts() Functions (Cont…) #include <stdio.h> int main( ) { char str[100]; printf( "Enter a value :"); gets( str ); printf( "nYou entered: "); puts( str ); return 0; } 15
  • 16. Objective Re-cap • Now you should be able to: ▫ Define the C standard functions for managing input output. ▫ Apply taught concepts for writing programs. 16
  • 17. Next: Working with Pointers 17