<< Chapter < Page | Chapter >> Page > |
Loading an array from a file presents an interesting dilemma. The problem resolves around how many elements you should plan for in the array. Let’s say 100, but what if the file has fewer or more than 100 values. How can the program handle it correctly?
The solution involves some simple steps:
This method is demonstrated in the demo file provided, thus you need to study this material in conjunction with the demo program.
Depending on your compiler/IDE, you should decide where to download and store source code files for processing. Prudence dictates that you create these folders as needed prior to downloading source code files. A suggested sub-folder for the Bloodshed Dev-C++ 5 compiler/IDE might be named:
If you have not done so, please create the folder(s) and/or sub-folder(s) as appropriate.
Download and store the following file(s) to your storage device in the appropriate folder(s). Following the methods of your compiler/IDE, compile and run the program(s). Study the source code file(s) in conjunction with other learning materials. You may need to right click on the link and select "Save Target As" in order to download the file.
Download from Connexions: Demo_Loading_Array_from_File.cpp
Download from Connexions: Demo_Farm_Acres_Input.txt
Notification Switch
Would you like to follow the 'Programming fundamentals - a modular structured approach using c++' conversation and receive update notifications?