I am a little mifted in my add and delete functions. This program is suppose to add and delete video titles and their info from the database/file. The program allows me to "add", but it somehow transforms it into wierd characters that look like an "I" from a foriegn language. On top of that It only copies the title at the end of each string of wierd characters.
As for the delete function, the delete reflects in the output screen but not in the file where the information is located. Is there another way I can delete a record?
Code:
void add_Video(int& numMovies, Video inventory[])
{
char video_title[31]; // initialize to add a title of movie
char video_star[51]; // initialize to add a name of movie stars
char video_type[10]; // intialize to add a the category the movie is in
char video_length[7]; // intialized to add a the length of the movie
char videoNum[4]; // initialized to add the number of copies in the store's inventory
cout << " Enter the title of the movie you would like to add to the list:" << endl << endl;
gets(video_title);
cout << endl;
for (int num = 0; num < numMovies; num++)
{
if (strcmp(inventory[numMovies].title, video_title)==0)
{
cout << "That title is already in the stores files." << endl;
cout << "If you wish to change the number of copies, first delete the old file." << endl << endl;
}
if(strcmp(inventory[numMovies].title, video_title)!=0)
{
cout << " Enter the name(s) of the actor/actress in the movie : " << endl << endl;
gets(video_star);
cout << endl;
cout << " Enter the type of movie it is: " << endl << endl;
cout << "Action Comedy Adventure" << endl;
cout << "Children Drama Western" << endl << endl;
gets(video_type);
cout << endl;
cout << " Enter the length of the movie in minutes (130min): " << endl << endl;
gets(video_length);
cout << endl;
cout << " Enter the number of copies in inventory: " << endl << endl;
gets(videoNum);
cout << endl;
numMovies++;
strcpy(inventory[numMovies].title, video_title); // Copy ALL fields to DB
strcpy(inventory[numMovies].star, video_star);
strcpy(inventory[numMovies].type, video_type);
strcpy(inventory[numMovies].length, video_length);
strcpy(inventory[numMovies].numCopies, videoNum);
cout << "The title just added to the list is: " << endl; // For debug purposes
cout << inventory[numMovies].title << endl;
} // end Else statement
} // end for loop
} // end add function
Code:
void delete_Video(Video inventory [], int& numMovies)
{
fstream videofile; // declaring
videofile.open("a:\\videofile.txt"); // opening file to be read
char title_entry[31];
int number = -1;
if (numMovies!=0)
{
system("cls");
cout << "Please enter the name of the title you would like to delete:" << endl;
fflush(stdin); // Pauses screen to allow user to input
gets(title_entry); // User inputs the movie title they wish to delete
cout << endl;
}
else
{
cout << "There is nothing to delete." << endl << endl;
}
for (int deleteNum = 0; deleteNum < numMovies; deleteNum++)
{
if (strcmp(inventory[deleteNum].title,title_entry)==0)
{
number = deleteNum;
strcpy (inventory[numMovies+1].title, inventory[deleteNum].title);
strcpy (inventory[numMovies+1].star, inventory[deleteNum].star);
strcpy(inventory[numMovies+1].type,inventory[deleteNum].type);
strcpy(inventory[numMovies+1].length,inventory[deleteNum].length);
strcpy(inventory[numMovies+1].numCopies,inventory[deleteNum].numCopies);
numMovies--;
cout << endl << strupr(title_entry) << " has been deleted from the collection." << endl << endl;
}
}
if (number < 0)
{
cout << endl << "Video title " << strupr(title_entry) << " was not found in the collection." << endl << endl;
}
} // End Delete function