Exercise 2: Opening a File to Be Read, But With OPEN OUTPUT — Possible Solution ==================================================================== WHAT OPEN OUTPUT ACTUALLY DOES, PER THIS CHAPTER This chapter's own real access-modes table states OUTPUT plainly: writing only, and "a real, existing file's contents are replaced entirely." OUTPUT mode is meant for creating a file or genuinely starting it over from empty - not for reading whatever it may already contain. WHAT GENUINELY HAPPENS TO CUSTOMER-FILE'S EXISTING RECORDS If a program intending to read CUSTOMER-FILE's existing customer records instead opens it with OPEN OUTPUT, the real, existing content of that file is wiped out the moment the OPEN statement runs - before a single READ statement is ever reached. This isn't a delayed or partial effect; OUTPUT mode's whole real purpose is to replace whatever the file currently holds. WHY ATTEMPTING TO READ AFTERWARD WOULD ALSO GENUINELY FAIL Beyond the lost data, OUTPUT mode itself only permits real write operations. This chapter's own table lists reading as something only INPUT (or I-O) mode allows. Any subsequent real READ statement issued against a file opened with OUTPUT would be attempting an operation the open mode itself doesn't support - a mismatch, on top of the data having already been destroyed. WHY THIS IS A GENUINELY SEVERE, IRREVERSIBLE MISTAKE Unlike many programming errors that can be caught and corrected after the fact, replacing a real file's existing content happens immediately and destructively at OPEN time. There's no real "undo" once OPEN OUTPUT has executed against a file that held genuine, needed customer records - the correct real records the program actually meant to read are simply gone. ANSWER: Opening CUSTOMER-FILE with OPEN OUTPUT when the goal was actually to read its existing records would genuinely destroy that real data immediately - OUTPUT mode's whole purpose is to replace a file's existing content entirely, and this happens the moment the OPEN statement executes, before any READ is ever reached. Beyond the lost data, OUTPUT mode also only permits real write operations, so any later READ attempt would be mismatched against the mode the file was actually opened in. This is a genuinely severe, irreversible mistake - the correct approach would have been OPEN INPUT, which permits reading without touching the file's existing content at all. WHY THIS WORKS AS AN ANSWER ------------------------------ This correctly identifies both real consequences (immediate, irreversible data loss, and a mode mismatch for any subsequent read attempt) using the chapter's own stated definition of OUTPUT mode, rather than treating the mistake as a minor or easily-corrected one.