Review Session 2

Example

Recording

File I/O

File streams

Opening a file

Closing a file

Reading from a file

Writing to a file

Handling End of File (EOF)


Practice Exercise 2

Email only the source code for each practice exercise as an email attachment.  There is no due date.  Use "Practice Exercise 2" as the email subject.   Add (a) comment(s) at the top of your program with your name, practice exercise #, your compiler and operating system.

Write a program in which you read in this file, partially displayed below and write out another file containing every other integer value on each line.  There are 50 lines in the input file and each line contains 15 integers.  The integers in the output file should each be written in a field of width 9.  Make sure you check for successful file opens.  Hint:  a "double for loop" should make the file processing easy.

Input file

77997913 38 19 16 16 16 20 20 16 20 16 16 56  60  3
87969978 50 20 11 14 19 20 13 14  8 19 10 60  77  7
81564051 21 14 12 11 18  9 17 11 15  9 20 66  90  6
25744204 37 18 16 19 14 16 13 16 15 17 20 68  94  8
53057551 44  9 12 15 10 15 11 20 16 17 20 22  62  8
49778442 41 19 18 16 17 20 10 16 17 16 15 69  45 10
01234567 47 19 18 15 19 14 14 17 15 16 20 37  65  5
34664035 48 20  7 15 20 17 15 16 16 16  5 34  83  9
50077769 28 10 14 13  7 20 13 18 19  1 18 55  49  6
...

Output file

 77997913       19       16       20       16       16       56        3
 87969978       20       14       20       14       19       60        7
 81564051       14       11        9       11        9       66        6
 25744204       18       19       16       16       17       68        8
 53057551        9       15       15       20       17       22        8
 49778442       19       16       20       16       16       69       10
  1234567       19       15       14       17       16       37        5
 34664035       20       15       17       16       16       34        9
 50077769       10       13       20       18        1       55        6
...