void Inquiry(List *pHead)
{
char*str = NULL;
List *pMark = pHead;
List *pTemp = NULL;
List *newpHead = NULL;
List *newpEnd = NULL;
List *pDel = NULL;
while(1)
{
while(1)
{
printf("请输入关键字\n");
str = GetString();
printf("a 确认 其他键重新输入\n");
if(GetKey() == 'a')
{
break;
}
else
{
free(str);
str = NULL;
}
}
while(pHead != NULL)
{
if(0 == strncmp(pHead->name,str,strlen(str)) || 0 == strncmp(pHead->tel,str,strlen(str)))
{
pTemp = (List*)malloc(sizeof(List));
pTemp->id = pHead->id;
pTemp->name = pHead->name;
pTemp->tel = pHead->tel;
pTemp->pNext = NULL;
AddNode(&newpHead,&newpEnd,pTemp);
}
pHead = pHead->pNext;
}
Browse(newpHead);
while(newpHead != NULL)
{
pDel = newpHead;
newpHead = newpHead->pNext;
//free(pDel->name);
//free(pDel->tel); //你不能把原来的姓名和电话给删除呀!
free(pDel);
pDel = NULL;
}
newpEnd = NULL;
if('b' == g_Key || 'd' == g_Key || 'u' == g_Key)
{
break;
}
删除复制的节点时,把原来的也给删除了,造成后续的运营中出现乱码,程序崩溃。