Well in this particular function, as seen in my previous post, you can recall the code
I call this function to ask the user to input a song title, then I sort through the array to see if there is a corresponding element in the array and remove that item from the array, then I "shorten" the array so It can print out the array properly when I call my print function, hence why I used
songs[i].title.clear();
songs[i].artist.clear();
songs[i].genre.clear();
songs[i].time = 0;
I thought it would clear out the memory, which I did, but I failed to shift the array.
However, you code make much more sense to simply shift the index of the array over 1 so that value gets overwrited if the user inputs a title that corresponds to an element in the array
Just as an FYI the user input is...asking the user to input the title of a song only.
As you said its it not the final solution because
(1,2,3,4) example of output
now after said "removal"
(1,2,4,4)
I just need to learn how to remove that duplicated element which seems to be the following element after the match
in titles
And I think I fixed it, I am bit abrupt on explaining my meaning but I did this to the "remove" function
int remove(music songs[10], int lCount)
{
string name;
int i =0;
cout<<"Enter title: ";
cin.ignore();
getline(cin,name);
for(int i = 0; i < lCount; i++)
{
if(name == songs[i].title)
{
songs[i].title = songs[i+1].title;
songs[i].artist = songs[i+1].artist;
songs[i].genre = songs[i+1].genre;
songs[i].time = songs[i+1].time;
}
}
return (lCount - 1);
}
and when I call this function I simple did
lCount = remove(songs, lCount);
So the iterator of "lCount"; which the current arrays size depending on the last file read gets reduced by 1
Not gonna lie it is a buggy in some instances, the remove and then print correct amount of array works some times the value does repeat