computer science: a structured programming approach using c1 13-3 converting file type a rather...

37
Computer Science: A Structured Programming Approach Using C 1 3-3 Converting File Type A rather common but somewhat trivial problem A rather common but somewhat trivial problem is to convert a text file to a binary file and vice is to convert a text file to a binary file and vice versa. C has no standard functions for these versa. C has no standard functions for these tasks. We must write a program to make the tasks. We must write a program to make the conversion. We describe the file conversion conversion. We describe the file conversion logic in this section. logic in this section. Creating a Binary File from a Text File Creating a Text File from a Binary File Topics discussed in this section: Topics discussed in this section:

Upload: april-webster

Post on 17-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 1

13-3 Converting File Type

A rather common but somewhat trivial problem is to A rather common but somewhat trivial problem is to convert a text file to a binary file and vice versa. C has convert a text file to a binary file and vice versa. C has no standard functions for these tasks. We must write a no standard functions for these tasks. We must write a program to make the conversion. We describe the file program to make the conversion. We describe the file conversion logic in this section.conversion logic in this section.

Creating a Binary File from a Text FileCreating a Text File from a Binary File

Topics discussed in this section:Topics discussed in this section:

Page 2: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 2

FIGURE 13-14 Create Binary File Structure Chart

Page 3: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 3

PROGRAM 13-5 Text to Binary Student File

Page 4: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 4

PROGRAM 13-5 Text to Binary Student File

Page 5: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 5

PROGRAM 13-5 Text to Binary Student File

Page 6: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 6

PROGRAM 13-5 Text to Binary Student File

Page 7: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 7

PROGRAM 13-5 Text to Binary Student File

Page 8: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 8

PROGRAM 13-5 Text to Binary Student File

Page 9: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 9

FIGURE 13-15 Design for Print Student Data

Page 10: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 10

PROGRAM 13-6 Print Student Data

Page 11: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 11

PROGRAM 13-6 Print Student Data

Page 12: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 12

PROGRAM 13-6 Print Student Data

Page 13: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 13

PROGRAM 13-6 Print Student Data

Page 14: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 14

PROGRAM 13-6 Print Student Data

Page 15: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 15

PROGRAM 13-6 Print Student Data

Page 16: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 16

PROGRAM 13-6 Print Student Data

Page 17: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 17

PROGRAM 13-6 Print Student Data

Page 18: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 18

13-4 File Program Examples

This section contains two common file applications. This section contains two common file applications. The first uses the file positioning functions to The first uses the file positioning functions to randomly process the data in a file. The second merges randomly process the data in a file. The second merges two files.two files.

Random File ProcessingMerge Files

Topics discussed in this section:Topics discussed in this section:

Page 19: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 19

PROGRAM 13-7 Random File Application

Page 20: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 20

PROGRAM 13-7 Random File Application

Page 21: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 21

PROGRAM 13-8 Random File: Build File

Page 22: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 22

PROGRAM 13-8 Random File: Build File

Page 23: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 23

PROGRAM 13-9 Random File: Sequential Print

Page 24: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 24

PROGRAM 13-9 Random File: Sequential Print

Page 25: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 25

PROGRAM 13-10 Random File: Random Print

Page 26: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 26

PROGRAM 13-10 Random File: Random Print

Page 27: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 27

FIGURE 13-16 File Merge Concept

Page 28: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 28

ALGORITHM 13-1 Pseudocode for Merging Two Files

Page 29: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 29

PROGRAM 13-11 Merge Two Files

Page 30: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 30

PROGRAM 13-11 Merge Two Files

Page 31: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 31

PROGRAM 13-11 Merge Two Files

Page 32: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 32

PROGRAM 13-11 Merge Two Files

Page 33: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 33

13-5 Software Engineering

Any file environment requires some means of keeping Any file environment requires some means of keeping the file current. The function that keeps files current is the file current. The function that keeps files current is known as known as updating. To complete our discussion of . To complete our discussion of files, we discuss some of the software engineering files, we discuss some of the software engineering design considerations for file updating. design considerations for file updating.

Update FilesSequential File UpdateThe Update Program DesignUpdate ErrorsUpdate Structure Chart and Logic

Topics discussed in this section:Topics discussed in this section:

Page 34: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 34

FIGURE 13-17 Sequential File Update Environment

Page 35: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 35

FIGURE 13-18 File Updating Example

Page 36: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 36

FIGURE 13-19 Update Structure Chart

Page 37: Computer Science: A Structured Programming Approach Using C1 13-3 Converting File Type A rather common but somewhat trivial problem is to convert a text

Computer Science: A Structured Programming Approach Using C 37

ALGORITHM 13-2 Pseudocode for File Update