Do you know how I can I move what I have located using my loop to the back of the array and have it be array[0] = ""; So when the array see's the space it just ignores it?
I'm a structure for the first time which seems to be making this harder to think about right now. If I put it after the loop how will I know what the index is? I'm trying to think of a general way because I will have different numebers that the user wants to be "DELETED" so to speak. How do I move the index to be deleted to the back of the array. and make it like arry[0] = ""; as was suggested to me. I don't understand thease ideas.
Thanks
// remove entry at position_of_item_to_remove
// by moving everything after it to the left by one position
// and return new (logical) size of array
int remove( infoType tele[], int& size, int position_of_item_to_remove )
{
for( int i = position_of_item_to_remove + 1 ; i < size ; ++i ) tele[i] = tele[i-1] ;
return --size;
}
And then:
1 2 3 4 5 6 7 8 9 10 11 12 13
// ...
if( tele[index].phone.compare(dPhone) == 0 )
{
cout << "The entry to be deleted is " << endl;
// ...
// remove the entry at position index
int new_size = remove( tele. size, index ) ;
found = true;
}
//...
I tried it, I and it compiles but then I got some crazy error after
Unhandled exception at 0x5c1dcafa (msvcr100d.dll) in newnew.exe: 0xC0000005: Access violation writing location 0xcccccccc.
I don't get this at all.
Thanks
The easy (if slightly glib) answer is: if you want to change the order of objects in a container, or remove objects, then an array isn't the best choice. You'd be much better off using a linked list.
In fact, you're better off altogether using an STL container class, such as std::list.
JLBorges, I think you've gotten things the wrong way around in your remove function - you're actually shifting everything to the right. The statement in your for loop should be: tele[i-1] = tele[i]
> JLBorges, I think you've gotten things the wrong way around in your remove function -
> you're actually shifting everything to the right. The statement in your for loop should be:
> tele[i-1] = tele[i]