SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Control Flow Statements
Control Flow Statements Control Flow Statements
Control Flow Statements
 
Pointers and Dynamic Memory Allocation
Pointers and Dynamic Memory AllocationPointers and Dynamic Memory Allocation
Pointers and Dynamic Memory Allocation
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
Presentation on C++ Programming Language
Presentation on C++ Programming LanguagePresentation on C++ Programming Language
Presentation on C++ Programming Language
 
Conditional statement c++
Conditional statement c++Conditional statement c++
Conditional statement c++
 
Strings in C language
Strings in C languageStrings in C language
Strings in C language
 
C basics
C   basicsC   basics
C basics
 
Variables in C and C++ Language
Variables in C and C++ LanguageVariables in C and C++ Language
Variables in C and C++ Language
 
Basic concept of c++
Basic concept of c++Basic concept of c++
Basic concept of c++
 
Printf and scanf
Printf and scanfPrintf and scanf
Printf and scanf
 
Pointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cppPointers,virtual functions and polymorphism cpp
Pointers,virtual functions and polymorphism cpp
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
C PROGRAMMING
C PROGRAMMINGC PROGRAMMING
C PROGRAMMING
 
C language unit-1
C language unit-1C language unit-1
C language unit-1
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Managing input and output operations in c
Managing input and output operations in cManaging input and output operations in c
Managing input and output operations in c
 
Strings in c++
Strings in c++Strings in c++
Strings in c++
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
Formatted input and output
Formatted input and outputFormatted input and output
Formatted input and output
 

Similar a 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
 

Similar a 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
 

Más de Hemantha Kulathilake

Más 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
 

Último

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
 
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
 

Último (20)

HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
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
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
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
 
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...
 
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
 
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
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
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Ữ Â...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

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