InputOutput - PowerPoint PPT Presentation

About This Presentation
Title:

InputOutput

Description:

Flags. 14. Flags. To provide more formatting features. Chapter 9 ... Flags. 19. Flags. Chapter 9. Literals & Escape Sequences. 20. Literals & Escape Sequences ... – PowerPoint PPT presentation

Number of Views:80
Avg rating:3.0/5.0
Slides: 31
Provided by: cen7150
Category:

less

Transcript and Presenter's Notes

Title: InputOutput


1
Chapter 9
  • Input/Output
  • Operations Functions

2
Input/Output
  • Input/output functions provided by I/O library.
  • Header file is stdio.h.
  • Two general I/O functions printf() for output,
    scanf() for input.

3
Formatting output printf()
  • Format
  • printf(format-control-string, print-list)
  • Example
  • printf("That equals .2f centimetres.\n", cm)

4
Formatting output printf()
  • printf() displays the value of its format control
    string
  • after substituting in left-to-right order the
    value of the expressions in the print list for
    their conversion specifications in the format
    string and
  • after replacing escape sequences by their
    meanings

5
Formatting output printf()
  • Example
  • sum 20 count 30
  • printf("d divided by d equals f\n",
  • sum, count, (float)sum/count)
  • Output
  • 20 divided by 3 equals 6.666667

6
Conversion specification
7
Conversion specification
8
Conversion specification
9
Conversion specification
10
Field Width Precision
  • Field place where an argument is displayed
  • Field width number of characters in field
  • Field width and precision are specified between
    the symbol and the conversion specifier.
  • Example 9.3f
  • Display right justified if field width is larger
    than what the value requires. For numeric data,
    if field width is too small, it is ignored.

11
Field Width Precision
12
Field Width Precision
  • Precision
  • for specifier d minimum number of digits
    (default 1)
  • for e, E and f number of digits after decimal
    point
  • for g and G maximum number of significant digits
  • for s maximum number of characters

13
Field Width Precision
14
Flags
  • To provide more formatting features

15
Flags
16
Flags
17
Flags
18
Flags
19
Flags
20
Literals Escape Sequences
  • Non-printing characters \n, \0.
  • Escape sequences to represent special characters.
    Examples \n, \t.
  • Literals to appear in string ", \, etc. Need to
    be escaped since " is used to delimit strings,
    and \ to start an escape sequence.

21
Literals Escape Sequences
22
Literals Escape Sequences
23
Formatting input scanf()
  • Format
  • printf(format-control-string, scan-list)
  • Example
  • scanf("2f", inch)

24
Conversion specification
25
Conversion specification
26
Conversion specification
27
Conversion specification
28
Field Width
29
Assignment Suppression Character
30
Homework
  • Try exercises behind chapter 9.
Write a Comment
User Comments (0)
About PowerShow.com