Published online by Cambridge University Press: 05 June 2012
VB Quip
On two occasions I have been asked (by members of Parliament), “Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?” I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
–Charles BabbageBy now you've come to realize that the real bottlenecks of your programs are input and output. Some of that is because users can only type and click so much and some of it is because input is repetitive. You've created useful output but have been unable to hang on to it. So far, every program run has meant starting from scratch with your data, entering it as needed, calculating the results, and then losing all of that work with a click of the Exit Button. No more. File input and output gives you the ability to store data and retrieve it as needed. File input takes data stored in a file and puts it into your program. File output stores the results in a file so you can use the data at a later date. This chapter covers the details of opening a data file, reading the data, processing the data, displaying the output, and writing the results to a file.
The Basics of File Input and Output
A data file, for our purposes, is a text file. Each line in the file is a record. A record consists for one or more fields.
To save this book to your Kindle, first ensure [email protected] is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.