Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 7 Formatted input and output. 7.1 introduction Tax:12345.500000 This result is correct; but it would be better Maybe as $13,545.50 Make formatting.

Similar presentations


Presentation on theme: "Chapter 7 Formatted input and output. 7.1 introduction Tax:12345.500000 This result is correct; but it would be better Maybe as $13,545.50 Make formatting."— Presentation transcript:

1 Chapter 7 Formatted input and output

2 7.1 introduction Tax:12345.500000 This result is correct; but it would be better Maybe as $13,545.50 Make formatting of input and output

3 7.2 interactive versus batch programs A data file consists of lines into which we type data values. A computer program that operates in this manner is said to have batch input If we want to save the output of a program in a file, we can direct it to a computer file. In this case the program has batch output.

4 7.5 OUTPUT FORMATTING 1. right-adjusted 2. Left-adjusted 3. a specified fill character. A fill character is any character that replaces the leading or trailing blanks in an output field. Specifying a Print Field of Fixed Width

5 Example 7.2 Printf(“%10d”, number); Specifying Left-Adjusted Printing in a Fixed-Width Field A minus after the symbol %

6 Example 7.3 Printf(“%-10d”, number); To proint an integer left-adjusted in a field of width 10. Example 7.4 Printf(“%010d”, number);

7 Example 7.5 Printf(“%+10d”, number); Printing Floating-Point Values with a Specified Precision Example 7.6 Printf(“%15.3f”, number);

8 Example 7.6 Printf(“%15.3f”, number); For strings a format specifier such as %15.3s results in a truncation of the string, and only the first three characters will be printed.

9 Specifying Variables for Field Width and Precision Printf(“%*d”, width, number); At run time is converted to the symbol * replaced by the variable Printf(“%15d”, number); 7.6 EXAMPLE PROGRAM1

10 7.7 MORE ON INTERACTIVE INPUT The InputList consists of variable addresses For variables of fundamental data types (such as int, double, and char) we must use the address operator The name of a string is a pointer to the memory location Where the string value is stored

11 Example 7.13 Scanf(“%4d”, &number); Assign the value 1155 to number.

12 Example 7.17 The following statement Scanf(“%d %c %lf”, &weight, &response, &height); Will permit us to separate the three values with whitespace. 7.8 EXAMPLE PROGRAM 2:


Download ppt "Chapter 7 Formatted input and output. 7.1 introduction Tax:12345.500000 This result is correct; but it would be better Maybe as $13,545.50 Make formatting."

Similar presentations


Ads by Google