Code:
int main()
{
int numMovies; // initialize variable to designate a record in the array
Video inventory[100]; // This is the array of videos
char choice; // initialize for user's selection from the menu
char again;
fstream videofile; // Declare variable which refers to the file
system("cls");
videofile.open("a:\\videofile.txt"); // opening file to be read
videofile >> numMovies;
for(int num=0; num < numMovies; num++)// Reads from file into array
{
videofile.ignore(100,'\n');
videofile.get(inventory[num].title,30);
videofile.ignore(100,'\n');
videofile.get(inventory[num].star,50);
videofile.ignore(100,'\n');
videofile.get(inventory[num].type,10);
videofile.ignore(100,'\n');
videofile.get(inventory[num].length,7);
videofile.ignore(100,'\n');
videofile.get(inventory[num].numCopies,4);
}
and
Code:
output_Records(numMovies, inventory);
}
videofile.close(); // Writing out to the text file
return 0;
} // end of main
Code:
//***********************************************************************
void output_Records(int& numMovies, Video inventory []) // Reading from file into the array
{
fstream videofile; // declaring
videofile.open("a:\\videofile.txt"); // opening file to be read
videofile << numMovies << endl;
for(int num=0; num < numMovies; num++)
{
videofile << strupr(inventory[num].title) << endl;
videofile << strupr(inventory[num].star) << endl;
videofile << strupr(inventory[num].type) << endl;
videofile << strupr(inventory[num].length) << endl;
videofile << strupr(inventory[num].numCopies) << endl;
}
}
//***********************************************************************
Hope this clears up things