Removing Elements of an Array

On my finals project and one of the instructions on the database we are making is:

When the user selects the fourth menu item, your program should ask the CD number, search the database and if it is found, it should decrement the amount in stock by one. If this amount is zero, then that CD should be deleted from the list. An appropriate message should be printed to the screen after the purchase, or if the purchase could not be made.

My problem is, I'm not quite sure how to remove the elements of an array, do I have to go back and set everything in the array to 0 or blank text? Is there a code that will just delete everything within the array? Also I do not know if this makes a difference but, we are using structs within structs.

so my array definition is similar to:
artist[x](artist name/ cd list/ cd count).cdlist[x].(CD Name/Title/Amt Stocked)

If somebody can help me it would be greatly appreciated.
An array is probably not the best container for this type of job.

Nonetheless, to remove an element of an array, simply move all the elements after it one space to the left. Do this however you have to with your struct-within-struct setup.
Thank you, makes sense. Sorry, I am new to this and Arrays have been mostly what we been working with, not sure what else I should use.
closed account (48T7M4Gy)
Have an additional bool attribute in the struct which records whether the item is in the list or not.

Arrays are fixed size so the way to remove an element completely is to copy the array into a new one, leaving out the deleted item.
Last edited on
Topic archived. No new replies allowed.