Hello Mathavan,
I did work up something to test the function and find some potential problems.
To start with:
1 file(s) copied.
Enter the name of the movie that you want to delete:
|
Ignore the first line for now. I will explain it later.
When given this prompt what movie name do you enter? Does it come from a piece of paper with the movie name(s) to work from or does the user have to guess?
It would be nice if you could list the movie names that are in the file.
The next problem is let us say that "Batman" is the movie to delete, but the user enters "batman". To us they would be considered equal, but to the computer and a compare function they are different because the "B" and "b" are 2 different letters with 2 different ASCII values.
This is something that you need to account for and change if necessary. The function you could use is "std::toupper()" from the "<cctype>" header file.
If you use the while loop correctly you will only need 1.
At the end of the function the "remove" and "rename" work fine.
And if you while loop is correct there is no need for the "blank_line" function because there will be nothing at the end of the "temp" file to deal with.
Given the original file:
Avenger|09:30|08:00|07:00
Policeman|09:30|08:00|07:00
Superman|09:30|08:00|07:00
Batman|09:30|08:00|07:00_
|
The function would produce:
Avenger|09:30|08:00|07:00
Policeman|09:30|08:00|07:00
Batman|09:30|08:00|07:00
_
|
Other than the removed movie name the only difference between the 2 files is that the original file ends after the (0) of the 4th line and in the shortened file it ends on the next line. The (_) is to show where the file ends. When reading the file it makes no difference where the (_) ends up.
This is what I did with "main":
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int main()
{
system("copy \"Orig Movies.txt\" Movies.txt"); // <--- Used for testing. Remove when finished.
int result{};
if (result = delete_movie())
{
return result;
}
return 0;
}
| |
Line 3 will restore "Movies.txt" to its original state before the program runs.
Since the "delete_movie()" renames "temp" to "Movies.txt" it is hard to use the file for testing when it keeps getting shorter.
The "delete_movie()" function can be made to work and you can eliminate the need for the "blank_line()" function.
In the end this is still not the best way to deal with this as
seeplus has pointed out.
Andy