I've created 2 structures. Now what Im trying to do is open these 2 txt files and write their contents to arrays of structures. So for instance, the Books.txt file has title, author, ISBN, availability, etc. for a few books and i am trying to write each item to the corresponding data variable into the "bookList" array of the "new" BookInfo data type structure.
The txt file im using is Books.txt and looks like this:
The Long Walk
0-451-19671-6 34.00 1 -1
The Art of Fielding
0-316-21753-0 28.77 1 -1
The Tiger's Wife
0-385-34384-1 12.99 1 -1
Under the Dome
1-4391-4903-4 34.90 0 123460
You might want to make openFile() an int or something; if it does happen to fail, it returns no indicator to main() that it failed, and main() will continue to run as if nothing happened. To solve this, and streamline your code, you can do away with this function altogether. Replace line 46 with lines 82-88, and add return 1; as the last line included in the if statement. Therefore, if opening the file fails, the program will exit.
(If you want the user to instead try again, use a while loop instead of the if - but if you choose to do this, make sure you prompt for a different file name!)
My teacher wants us to use functions as much as possible. If i do keep it as is, and a file does not open, it will still cout an error message so i want to keep that as it is. At this point it compiles but doesnt run correctly. Im wondering if i am using fin correctly when putting each structure element into the array. The output im getting is