Finding then deleting

Hi;
Trying to find a phone number if found I want to delete it. It works until it gets to the searching part of the operation. I was getting jibberish phone number outout when I entered the correct number. Now it just seems to sit and wait. Not sure whats up.
Also When I find this number I have to delete it from the array (this is a structure array) not sure if that helps.
What is the easiest way to do this. I would not like to have an empty space in my array. Thanks,
Here is my function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void optionD( ifstream &fin, infoType tele[], int& size)
{		
	int index = 0;
	string dPhone;
	bool found = false;
	
	cout << "You have selected option D " << endl;
	cout << "Please enter the phone number of the record to be deleted." << endl;

	cin >> dPhone;
	
	while( index < size && !found )
	{
		
		if(tele[index].phone.compare(dPhone)== 0)
		cout << tele[index].phone;
		index++;
		found = true;
	
	}
	
}	
Type structure of variable "tele" ?
"tele" is an array, or pointer?
You want to delete a specific unit you specified?
found is set to true there whether you find the number or not on the first iteration of the loop, so your while loop never lasts for more than one iteration.

Also When I find this number I have to delete it from the array (this is a structure array) not sure if that helps.

If order matters, you need to move every element in the array at higher indices than the element you want to remove down a space.
This is my structure
1
2
3
4
5
6
7
8
9
//structure
struct infoType
{	
	string fname;
	string lname;
	string streetAdd;
	string cityStateZ;
	string phone;
};

This is my array. The size is constant here but I changed it so its not the same when it gets to the function above. I don't know if that helps.
infoType tele[SIZE];
I have never talked about pointers in class. Sorry. It is an array.
This is my objective:
Input the phone number from user of the number to be deleted.
Find that number ( which is what I'm having issues with above)
Delete that entire set of information at the specified index when the number is found.

So say that tele[2] is the same phone number as dPhone.
Now I want to delete it from the array and not have a empty space in my array. I just want it gone.
Thanks

I'm not following cire

If order matters, you need to move every element in the array at higher indices than the element you want to remove down a space.

I need to have them sorted alphabetically for display so could I pass it to a sort function after or before this function and that would take care of that?
Sorry I don't understand
thx

I did this for to try and fix the found thing
1
2
3
4
5
6
7
8
9
10
11
while( index < size && !found )
	{
		
		if(tele[index].phone.compare(dPhone)== 0)
		{
		cout << tele[index].phone;
		found = true;
		}
		
		index++;
	}


But it still just waits instead of showing me the phone number it found
Last edited on
Jackson,
I think that it will just do the statement that is after the if statement?
When I enter the phone number (one that matches) it is the first phone number on my list. It would still output then right? So if it did not and I tried to fix it like the one above your last post so the parenthesis are right. Why wouldn't it output my phone number?
Thanks
Last edited on
I GOT IT! Always something stupid.
Thank you for the help with the while loop.

Topic archived. No new replies allowed.