SlideShare a Scribd company logo
Input – Output in ‘C’

  www.eshikshak.co.in
Introduction
• Reading input data, processing it and displaying the
  results are the three tasks of any program.
• There are two ways to accept the data.
   – In one method, a data value is assigned to the variable with an
     assignment statement.
      • int year = 2005; char letter = ‘a’;   int x = 12345;
   – Another way of accepting the data is with functions.
• There are a number of I/O functions in C, based
  on the data type. The input/output functions are
  classified in two types.
   – Formatted functions
   – Unformatted functions
Formatted function
• With the formatted functions, the input or
  output is formatted as per our requirement.
• All the I/O function are defined as stdio.h
  header file.
• Header file should be included in the program
  at the beginning.
Input and Output Functions




Formatted Functions                                Unformatted Functions




      printf()
      scanf()
                                                       getch() putch()
                                                     getche() putchar()
                                                    getchar()      puts()
                                                            gets()
Formatted Functions             Unformatted Functions
• It read and write all types   • Works only with character
  of data values.                 data type
• Require format string to      • Do not require format
  produce formatted result        conversion for formatting
• Returns value after             data type
  execution
printf() function
• This function displays output with specified format
• It requires format conversion symbol or format string
  and variables names to the print the data
• The list of variables are specified in the printf()
  statement
• The values of the variables are printed as the
  sequence mentioned in printf()
• The format string symbol and variable name should
  be the same in number and type
printf() function
• Syntax
  printf(“control string”, varialbe1, variable2,..., variableN);


• The control string specifies the field format such as
  %d, %s, %g, %f and variables as taken by the
  programmer
void main()
{
   int NumInt = 2;
  float NumFloat=2.2;
  char LetterCh = ‘C’;

    printf(“%d %f %c”, NumInt, NumFloat, LetterCh);
}

Output :
2 2.2000 C
void main()
{
   int NumInt = 65;
   clrscr();
   printf(“%c %d”, NumInt, NumInt);
}

Output :
A 65
void main()
{
   int NumInt = 7;
   clrscr();
   printf(“%f”, NumInt);
    return 0;
}

Output :
Error Message : “Floating points formats not linked”
void main()
{
   int NumInt = 7;
   clrscr();
   printf(“%f”, NumInt);
    return 0;
}

Output :
Error Message : “Floating points formats not linked”
• All the format specification starts with % and a
  format specification letter after this symbol.
• It indicates the type of data and its format.
• If the format string does not match with the
  corresponding variable, the result will not be
  correct.
• Along with format specification use
  – Flags
  – Width
  – Precision
• Flag
  – It is used for output justification, numeric signs, decimal
    points, trailing zeros.
  – The flag (-) justifies the result. If it is not given the default
    result is right justification.
• Width
  – It sets the minimum field width for an output value.
  – Width can be specified through a decimal point or using an
    asterisk ‘*’.
void main()
{
   clrscr();
   printf(“n%.2s”,”abcdef”);
   printf(“n%.3s”,”abcdef”);
   printf(“n%.4s”,”abcdef”);
}
OUTPUT
ab
  abc
  abcd
void main()
{
  int x=55, y=33;
  clrscr();
  printf(“n %3d”, x – y);
  printf(“n %6d”, x – y);
}
OUTPUT
22
       22
void main()
{
  int x=55, y=33;
  clrscr();
  printf(“n %*d”, 15, x – y);
  printf(“n %*d”, 5,x – y);
}
OUTPUT
       22
  22
void main()
{
   float g=123.456789;
   clrscr();
   printf(“n %.1f”, g);
   printf(“n %.2f”, g);
   printf(“n %.3f”, g);
   printf(“n %.4f”, g);
}
OUTPUT
123.5
123.46
123.457
123.4568
Sr. No   Format   Meaning              Explanation


1        %wd      Format for integer   w is width in integer and d
                  output               is conversion specification
2        %w.cf    Format for float     w is width in integer, c
                  numbers              specifies the number of
                                       digits after decimal point
                                       and     f    specifies    the
                                       conversion specification
3        %w.cs    Format for string    w is width for total
                  output               characters, c are used
                                       displaying leading blanks
                                       and s specifies conversion
                                       specification
scanf() function
• scanf() function reads all the types of data
  values.
• It is used for runtime assignment of variables.
• The scanf() statement also requires
  conversion symbol to identify the data to be
  read during the execution of the program.
• The scanf() stops functioning when some
  input entered does not match format string.
scanf() function
Syntax :
scanf(“%d %f %c”, &a, &b, &c);
 Scanf statement requires ‘&’ operator called address
  operator
 The address operator prints the memory location of
  the variable
 scanf() statement the role of ‘&’ operator is to
  indicate the memory location of the variable, so that
  the value read would be placed at that location.
scanf() function
 The scanf() function statement also return values.
  The return value is exactly equal to the number of
  values correctly read.
 If the read value is convertible to the given format,
  conversion is made.
void main()
{
  int a;
  clrscr();
  printf(“Enter value of ‘A’ : “);
  scanf(“%c”, &a);
  printf(“A : %c”,a);
}
OUTPUT
Enter value of ‘A’ : 8
A:8
void main()
{
  char a;
  clrscr();
  printf(“Enter value of ‘A’ : “);
  scanf(“%d”, &a);
  printf(“A : %d”,a);
}
OUTPUT
Enter value of ‘A’ : 255
A : 255
Enter value of ‘A’ : 256
A : 256
Sr. No   Format   Meaning              Explanation


1        %wd      Format for integer   w is width in integer and d
                  input                is conversion specification
2        %w.cf    Format for float     w is width in integer, c
                  point input          specifies the number of
                                       digits after decimal point
                                       and     f    specifies    the
                                       conversion specification
3        %w.cs    Format for string    w is width for total
                  input                characters, c are used
                                       displaying leading blanks
                                       and s specifies conversion
                                       specification
Data Type                                      Format string
Integer                 Short Integer          %d or %i
                        Short unsigned         %u
                        Long signed            %ld
                        Long unsigned          %lu
                        Unsigned hexadecimal   %u
                        Unsigned octal         %o
Real                    Floating               %f or %g
                        Double Floating        %lf
Character               Signed Character       %c
                        Unsigned Character     %c
                        String                 %s
Octal number                                   %o
Displays Hexa decimal                          %hx
number in lowercase
Displays Hexa decimal                          %p
number in lowercase


Aborts program with                            %n
error
Escape Sequence
                                   Escape Sequence   Use               ASCII value

• printf() and scanf() statement   n                New Line          10
  follows the combination of
  characters called escape         b                Backspace         8
  sequence                         f                Form feed         12
• Escape sequence are special      ’                Single quote      39
  characters starting with ‘’                     Backslash         92
                                   0                Null              0
                                   t                Horizontal Tab    9
                                   r                Carriage Return   13
                                   a                Alert             7
                                   ”                Double Quote      34
                                   v                Variable tab      11
                                   ?                Question mark     63
void main()
{
   int a = 1, b = a + 1, c = b + 1, d = c + 1;
   clrscr();
   printf(“t A = %dnB = %d ’C = %d’”,a,b,c);
   printf(“nb***D = %d**”,d);
   printf(“n*************”);
   printf(“rA = %d B = %d”, a, b);
}

OUTPUT
         A=1
B=2      ‘C = 3’
***D=4**
A = 1 B = 2******
Unformatted Functions
• C has three types of I/O functions
  – Character I/O
  – String I/O
  – File I/O
  – Character I/O
getchar
• This function reads a character type data from
  standard input.
• It reads one character at a time till the user presses
  the enter key.
• Syntax
   VariableName = getchar();
• Example
   char c;
   c = getchar();
putchar
• This function prints one character on the
  screen at a time, read by the standard input.
• Syntax
  – puncher(variableName)
• Example
    char c = ‘C’;
    putchar(c);
getch() and getche()
• These functions read any alphanumeric character
  from the standard input device.
• The character entered is not displayed by the getch()
  function.
• The character entered is displayed by the getche()
  function.
• Exampe
    ch = getch();
    ch = getche();
gets()
• This function is used for accepting any string through stdin
  keyword until enter key is pressed.
• The header file stdio.h is needed for implementing the
  above function.
• Syntax
   char str[length of string in number];
   gets(str);
 void main()
 {
       char ch[30];
       clrscr();
       printf(“Enter the string : “);
       gets();
       printf(“n Entered string : %s”, ch);
 }
puts()
• This function prints the string or character array.
• It is opposite to gets()

  char str[length of string in number];
  gets(str);
  puts(str);

More Related Content

What's hot

Major Function of i/o module
Major Function of i/o moduleMajor Function of i/o module
Major Function of i/o module
Delowar Hossain
 
C tokens
C tokensC tokens
C tokens
Manu1325
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
sangrampatil81
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
Sokngim Sa
 
Different loops in C
Different loops in CDifferent loops in C
Different loops in C
Md. Arif Hossain
 
Jumping statements
Jumping statementsJumping statements
Jumping statementsSuneel Dogra
 
Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtl
Mazin Alwaaly
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
Tasnima Hamid
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
v_jk
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
Prabhu Govind
 
String Library Functions
String Library FunctionsString Library Functions
String Library Functions
Nayan Sharma
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Rao Mubashar
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
Leela Koneru
 
Computer registers
Computer registersComputer registers
Computer registers
DeepikaT13
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
Sowmya Jyothi
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
Kamal Acharya
 
C presentation book
C presentation bookC presentation book
C presentation book
krunal1210
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
Ashim Lamichhane
 

What's hot (20)

Major Function of i/o module
Major Function of i/o moduleMajor Function of i/o module
Major Function of i/o module
 
C tokens
C tokensC tokens
C tokens
 
Basic Input and Output
Basic Input and OutputBasic Input and Output
Basic Input and Output
 
Scope rules : local and global variables
Scope rules : local and global variablesScope rules : local and global variables
Scope rules : local and global variables
 
C Programming: Control Structure
C Programming: Control StructureC Programming: Control Structure
C Programming: Control Structure
 
Different loops in C
Different loops in CDifferent loops in C
Different loops in C
 
Jumping statements
Jumping statementsJumping statements
Jumping statements
 
Computer architecture register transfer languages rtl
Computer architecture register transfer languages rtlComputer architecture register transfer languages rtl
Computer architecture register transfer languages rtl
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
RECURSION IN C
RECURSION IN C RECURSION IN C
RECURSION IN C
 
Memory allocation in c
Memory allocation in cMemory allocation in c
Memory allocation in c
 
String Library Functions
String Library FunctionsString Library Functions
String Library Functions
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
How to execute a C program
How to execute a C  program How to execute a C  program
How to execute a C program
 
Data types
Data typesData types
Data types
 
Computer registers
Computer registersComputer registers
Computer registers
 
Unit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in CUnit ii chapter 2 Decision making and Branching in C
Unit ii chapter 2 Decision making and Branching in C
 
Data Types and Variables In C Programming
Data Types and Variables In C ProgrammingData Types and Variables In C Programming
Data Types and Variables In C Programming
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 

Viewers also liked

Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
eShikshak
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
eShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
eShikshak
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
eShikshak
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
eShikshak
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02eShikshak
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
eShikshak
 
Algorithm
AlgorithmAlgorithm
Algorithm
eShikshak
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
eShikshak
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
eShikshak
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
eShikshak
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
eShikshak
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11chidabdu
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppteShikshak
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
eShikshak
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formattingeShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssionseShikshak
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
eShikshak
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
eShikshak
 

Viewers also liked (20)

Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Html phrase tags
Html phrase tagsHtml phrase tags
Html phrase tags
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02Lecture7relationalandlogicaloperators 110823181038-phpapp02
Lecture7relationalandlogicaloperators 110823181038-phpapp02
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Algorithm
AlgorithmAlgorithm
Algorithm
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Algorithm chapter 11
Algorithm chapter 11Algorithm chapter 11
Algorithm chapter 11
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Html text and formatting
Html text and formattingHtml text and formatting
Html text and formatting
 
Linked list
Linked listLinked list
Linked list
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 

Similar to Mesics lecture 5 input – output in ‘c’

CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
Aditya Vaishampayan
 
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
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
input
inputinput
input
teach4uin
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
simranjotsingh2908
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
mohd_mizan
 
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 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
JAYA
 
2 data and c
2 data and c2 data and c
2 data and c
MomenMostafa
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
Janani Satheshkumar
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
Abhishek Sinha
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
Md. Ashikur Rahman
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
Mahira Banu
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
Wingston
 
Chapter 13.1.3
Chapter 13.1.3Chapter 13.1.3
Chapter 13.1.3patcha535
 
C Programming
C ProgrammingC Programming
C Programming
Raj vardhan
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
ShreyaSingh291866
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogramprincepavan
 

Similar to Mesics lecture 5 input – output in ‘c’ (20)

CPU INPUT OUTPUT
CPU INPUT OUTPUT CPU INPUT OUTPUT
CPU INPUT OUTPUT
 
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
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
input
inputinput
input
 
Input And Output
 Input And Output Input And Output
Input And Output
 
Unit 2- Module 2.pptx
Unit 2- Module 2.pptxUnit 2- Module 2.pptx
Unit 2- Module 2.pptx
 
CHAPTER 4
CHAPTER 4CHAPTER 4
CHAPTER 4
 
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 5 Foc
Unit 5 FocUnit 5 Foc
Unit 5 Foc
 
2 data and c
2 data and c2 data and c
2 data and c
 
Fucntions & Pointers in C
Fucntions & Pointers in CFucntions & Pointers in C
Fucntions & Pointers in C
 
Concepts of C [Module 2]
Concepts of C [Module 2]Concepts of C [Module 2]
Concepts of C [Module 2]
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
 
Cse115 lecture04introtoc programming
Cse115 lecture04introtoc programmingCse115 lecture04introtoc programming
Cse115 lecture04introtoc programming
 
C programing Tutorial
C programing TutorialC programing Tutorial
C programing Tutorial
 
Introduction to Basic C programming 02
Introduction to Basic C programming 02Introduction to Basic C programming 02
Introduction to Basic C programming 02
 
Chapter 13.1.3
Chapter 13.1.3Chapter 13.1.3
Chapter 13.1.3
 
C Programming
C ProgrammingC Programming
C Programming
 
C programming language for beginners
C programming language for beginners C programming language for beginners
C programming language for beginners
 
T02 a firstcprogram
T02 a firstcprogramT02 a firstcprogram
T02 a firstcprogram
 

More from eShikshak

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
eShikshak
 
Operators in python
Operators in pythonOperators in python
Operators in python
eShikshak
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
eShikshak
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
eShikshak
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
eShikshak
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
eShikshak
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
eShikshak
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
eShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
eShikshak
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
eShikshak
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppteShikshak
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
eShikshak
 
Language processors
Language processorsLanguage processors
Language processorseShikshak
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
eShikshak
 

More from eShikshak (15)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Language processors
Language processorsLanguage processors
Language processors
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 

Mesics lecture 5 input – output in ‘c’

  • 1. Input – Output in ‘C’ www.eshikshak.co.in
  • 2. Introduction • Reading input data, processing it and displaying the results are the three tasks of any program. • There are two ways to accept the data. – In one method, a data value is assigned to the variable with an assignment statement. • int year = 2005; char letter = ‘a’; int x = 12345; – Another way of accepting the data is with functions. • There are a number of I/O functions in C, based on the data type. The input/output functions are classified in two types. – Formatted functions – Unformatted functions
  • 3. Formatted function • With the formatted functions, the input or output is formatted as per our requirement. • All the I/O function are defined as stdio.h header file. • Header file should be included in the program at the beginning.
  • 4. Input and Output Functions Formatted Functions Unformatted Functions printf() scanf() getch() putch() getche() putchar() getchar() puts() gets()
  • 5. Formatted Functions Unformatted Functions • It read and write all types • Works only with character of data values. data type • Require format string to • Do not require format produce formatted result conversion for formatting • Returns value after data type execution
  • 6. printf() function • This function displays output with specified format • It requires format conversion symbol or format string and variables names to the print the data • The list of variables are specified in the printf() statement • The values of the variables are printed as the sequence mentioned in printf() • The format string symbol and variable name should be the same in number and type
  • 7. printf() function • Syntax printf(“control string”, varialbe1, variable2,..., variableN); • The control string specifies the field format such as %d, %s, %g, %f and variables as taken by the programmer
  • 8. void main() { int NumInt = 2; float NumFloat=2.2; char LetterCh = ‘C’; printf(“%d %f %c”, NumInt, NumFloat, LetterCh); } Output : 2 2.2000 C
  • 9. void main() { int NumInt = 65; clrscr(); printf(“%c %d”, NumInt, NumInt); } Output : A 65
  • 10. void main() { int NumInt = 7; clrscr(); printf(“%f”, NumInt); return 0; } Output : Error Message : “Floating points formats not linked”
  • 11. void main() { int NumInt = 7; clrscr(); printf(“%f”, NumInt); return 0; } Output : Error Message : “Floating points formats not linked”
  • 12. • All the format specification starts with % and a format specification letter after this symbol. • It indicates the type of data and its format. • If the format string does not match with the corresponding variable, the result will not be correct. • Along with format specification use – Flags – Width – Precision
  • 13. • Flag – It is used for output justification, numeric signs, decimal points, trailing zeros. – The flag (-) justifies the result. If it is not given the default result is right justification. • Width – It sets the minimum field width for an output value. – Width can be specified through a decimal point or using an asterisk ‘*’.
  • 14. void main() { clrscr(); printf(“n%.2s”,”abcdef”); printf(“n%.3s”,”abcdef”); printf(“n%.4s”,”abcdef”); } OUTPUT ab abc abcd
  • 15. void main() { int x=55, y=33; clrscr(); printf(“n %3d”, x – y); printf(“n %6d”, x – y); } OUTPUT 22 22
  • 16. void main() { int x=55, y=33; clrscr(); printf(“n %*d”, 15, x – y); printf(“n %*d”, 5,x – y); } OUTPUT 22 22
  • 17. void main() { float g=123.456789; clrscr(); printf(“n %.1f”, g); printf(“n %.2f”, g); printf(“n %.3f”, g); printf(“n %.4f”, g); } OUTPUT 123.5 123.46 123.457 123.4568
  • 18. Sr. No Format Meaning Explanation 1 %wd Format for integer w is width in integer and d output is conversion specification 2 %w.cf Format for float w is width in integer, c numbers specifies the number of digits after decimal point and f specifies the conversion specification 3 %w.cs Format for string w is width for total output characters, c are used displaying leading blanks and s specifies conversion specification
  • 19. scanf() function • scanf() function reads all the types of data values. • It is used for runtime assignment of variables. • The scanf() statement also requires conversion symbol to identify the data to be read during the execution of the program. • The scanf() stops functioning when some input entered does not match format string.
  • 20. scanf() function Syntax : scanf(“%d %f %c”, &a, &b, &c);  Scanf statement requires ‘&’ operator called address operator  The address operator prints the memory location of the variable  scanf() statement the role of ‘&’ operator is to indicate the memory location of the variable, so that the value read would be placed at that location.
  • 21. scanf() function  The scanf() function statement also return values. The return value is exactly equal to the number of values correctly read.  If the read value is convertible to the given format, conversion is made.
  • 22. void main() { int a; clrscr(); printf(“Enter value of ‘A’ : “); scanf(“%c”, &a); printf(“A : %c”,a); } OUTPUT Enter value of ‘A’ : 8 A:8
  • 23. void main() { char a; clrscr(); printf(“Enter value of ‘A’ : “); scanf(“%d”, &a); printf(“A : %d”,a); } OUTPUT Enter value of ‘A’ : 255 A : 255 Enter value of ‘A’ : 256 A : 256
  • 24. Sr. No Format Meaning Explanation 1 %wd Format for integer w is width in integer and d input is conversion specification 2 %w.cf Format for float w is width in integer, c point input specifies the number of digits after decimal point and f specifies the conversion specification 3 %w.cs Format for string w is width for total input characters, c are used displaying leading blanks and s specifies conversion specification
  • 25. Data Type Format string Integer Short Integer %d or %i Short unsigned %u Long signed %ld Long unsigned %lu Unsigned hexadecimal %u Unsigned octal %o Real Floating %f or %g Double Floating %lf Character Signed Character %c Unsigned Character %c String %s Octal number %o Displays Hexa decimal %hx number in lowercase Displays Hexa decimal %p number in lowercase Aborts program with %n error
  • 26. Escape Sequence Escape Sequence Use ASCII value • printf() and scanf() statement n New Line 10 follows the combination of characters called escape b Backspace 8 sequence f Form feed 12 • Escape sequence are special ’ Single quote 39 characters starting with ‘’ Backslash 92 0 Null 0 t Horizontal Tab 9 r Carriage Return 13 a Alert 7 ” Double Quote 34 v Variable tab 11 ? Question mark 63
  • 27. void main() { int a = 1, b = a + 1, c = b + 1, d = c + 1; clrscr(); printf(“t A = %dnB = %d ’C = %d’”,a,b,c); printf(“nb***D = %d**”,d); printf(“n*************”); printf(“rA = %d B = %d”, a, b); } OUTPUT A=1 B=2 ‘C = 3’ ***D=4** A = 1 B = 2******
  • 28. Unformatted Functions • C has three types of I/O functions – Character I/O – String I/O – File I/O – Character I/O
  • 29. getchar • This function reads a character type data from standard input. • It reads one character at a time till the user presses the enter key. • Syntax VariableName = getchar(); • Example char c; c = getchar();
  • 30. putchar • This function prints one character on the screen at a time, read by the standard input. • Syntax – puncher(variableName) • Example char c = ‘C’; putchar(c);
  • 31. getch() and getche() • These functions read any alphanumeric character from the standard input device. • The character entered is not displayed by the getch() function. • The character entered is displayed by the getche() function. • Exampe  ch = getch();  ch = getche();
  • 32. gets() • This function is used for accepting any string through stdin keyword until enter key is pressed. • The header file stdio.h is needed for implementing the above function. • Syntax char str[length of string in number]; gets(str); void main() { char ch[30]; clrscr(); printf(“Enter the string : “); gets(); printf(“n Entered string : %s”, ch); }
  • 33. puts() • This function prints the string or character array. • It is opposite to gets() char str[length of string in number]; gets(str); puts(str);