void search()
{
char id[12];
node *p = head;
system("cls");
{
	cout<<"Search ID: ";
	cin>>id;

}
	while ((p!=NULL) && (strcmp(id,p->id)!=0))

	{
		p = p->next;

	}
	
	if(p==NULL)

	{
		cout<<"No such ID in our list"<<endl;
		delete p;

	}
	
	else

		cout<<"We have this ID in our list"<<endl;
		
}


void remove()
{
char id[12];
node *newptr;
node *q = NULL;
node *p = head;

	cout<<" Delete ID: "; 
	cin>>id;
        cout<<"Title 	:"<<p->name_1<<endl;

	while ((p!=NULL) && (strcmp(id,p->id)!=0))
		{
			q = p;
			p = p->next;
		}
		
	if(q==NULL) 
		{
			head = head->next;
			delete p;
		}
		
	else if (p==NULL)
		{
			cout<<"No such ID in list"<<endl;
		}
		
	else 
		{
			q->next=p->next;
			delete p;
		}
}

*** I got problem when I try to search ID that doesnt exist in the list. The program will display this, 'No such ID in our list' but then it will debug after that.
*** When I try to enter ID that doesnt exist in the list, the delete function will display the input that had been entered and display, 'No such ID in list'.
eg; Title: alice in wonderland
No such ID in list
I want the delete function only display this, 'No such ID in list'.
Anyone can explain why this problem occur? Thanks.

Its the remove() function, not delete.
Your question is not clear to me but I think this is what you want..
The problem is line 42. Check before printing.

if(p!=NULL)
cout<<"Title 	:"<<p->name_1<<endl;

Why don't you Make search() function return a value and check using it in the remove() function.

This article has been dead for over six months. Start a new discussion instead.