#include "structs.h" #include //take care of the file IO using namespace std; //main function: entry point of the program int main() { //1. declare a file obj ifstream fin; //2. open the file fin.open("book.txt"); if (!fin.is_open()) { cout << "Can't open the file" << endl; return 1; } //3. take inputs int size = -1; fin >> size; //test to see if size has been read into the program cout << size << endl; //allocate memory for the book array Book* book_arr = new Book [size]; //populate the book array, one at a time for (int i = 0; i < size; ++i) { //remember that we need to pass the file obj as well book_init_one_book(book_arr, i, fin); } //4. close the file fin.close(); ofstream file; string filename; cout << "Enter the file for output: "; cin >> filename; file.open(filename, ios::app); //print out the books for (int i = 0; i < size; ++i) { //print out the books to screen //print_book(book_arr[i]); //print out the books to file print_book_to_file(book_arr[i], file); } file.close(); //free memory delete_books(book_arr, size); return 0; }