1 / 30

Chapter 9

Input/Output Operations & Functions. Chapter 9. Input/output functions provided by I/O library. Header file is stdio.h. Two general I/O functions: printf() for output, scanf() for input. Input/Output. Format: printf( format-control-string , print-list ); Example:

Download Presentation

Chapter 9

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Input/Output Operations & Functions Chapter 9 Chapter 9: Input/Output Operations & Functions

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

  3. Format: printf(format-control-string, print-list); Example: printf("That equals %.2f centimetres.\n", cm); print-list format-control-string conversion specification escape sequence Formatting output: printf() Formatting output: printf()

  4. 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 Formatting output: printf() Formatting output: printf()

  5. 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 Formatting output: printf() Formatting output: printf()

  6. Conversion specification Conversion specification

  7. Conversion specification Conversion specification

  8. Conversion specification Conversion specification

  9. Conversion specification Conversion specification

  10. 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. Field Width & Precision Field Width & Precision

  11. Field Width & Precision Field Width & Precision

  12. 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 Field Width & Precision Field Width & Precision

  13. Field Width & Precision Field Width & Precision

  14. To provide more formatting features Flags Flags

  15. Flags Flags

  16. Flags Flags

  17. Flags Flags

  18. Flags Flags

  19. Flags Flags

  20. 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. Literals & Escape Sequences Literals & Escape Sequences

  21. Literals & Escape Sequences Literals & Escape Sequences

  22. Literals & Escape Sequences Literals & Escape Sequences

  23. Format: printf(format-control-string, scan-list); Example: scanf("%2f", &inch); format-control-string scan-list Formatting input: scanf() Formatting input: scanf()

  24. Conversion specification Conversion specification

  25. Conversion specification Conversion specification

  26. Conversion specification Conversion specification

  27. Conversion specification Conversion specification

  28. Field Width Field Width

  29. Assignment Suppression Character Assignment Suppression Character

  30. Try exercises behind chapter 9. Homework Homework

More Related