0

i want to delete an element of array structure to use it again to more understand look to the part of this code

struct patient

{
	int ID;
	 char name[100];
	 float age;
	 char sex[7];
	 char adress[100];
	 char hometelephone[12];
	 char mobiletelephone[11];
	 char workingtelephone[12];
	 char date[12];
	 char time[13];

} patients[100];
void delet()
{
int ida;
cout<<"Enter your Id"<<endl;
cin>>ida;
/* i want to delete this patient
patients[ida].name=0;
patients[ida].age=0;
patients[ida].id=0;
patients[ida].sex=0;
patients[ida].hometelephone=0;
patients[ida].workingtelephone=0;
patients[ida].mobiletelephone=0;
patients[ida].date=0;
patients[ida].time=0;
*/
}
3
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by Aranarth
0

Either move all other patients down one position or make an array of pointers to patients and allocate them dynamically. Then you can delete the patient at a certain position and mark the position as free by setting the pointer to 0.
Since your array seems to play a double role of also acting as a id->patient map, the latter is probably the better solution.

Of course, you could just use a real map.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.