大侠们帮我看下这个简单的程序错在哪
#include<iostream.h>
#include<iomanip.h>
#include<string.h>
typedef struct person //个人信息结构
{
char name[10];
char address[30];
char phonenum[12];
struct person *next;
}person;
//通讯录
class tongxun
{
public:
tongxun()
{
h=new person;
strcpy(h->name,"name");
strcpy(h->address,"address");
strcpy(h->phonenum,"phonenum");
h->next=NULL;
}
person *creat()
{
x=new person;
cout<<"请输入一个人的姓名:"<<endl;
cin>>x->name;
cout<<"请输入一个人的地址:"<<endl;
cin>>x->address;
cout<<"请输入一个人的电话:"<<endl;
cin>>x->phonenum;
x->next=NULL;
return(x);
}
void insert(person *y)
{
p=h;
s=h;
p=p->next;
if(p==NULL)
{
s->next=y;
}
else
{
while(p!=NULL && strcmp(p->name,y->name)<0)
{
s=p;
p=p->next;
}
if(p==NULL)
{
s->next=y;
}
else
{
y->next=s->next;
s->next=y;
}
}
p=NULL;
s=NULL;
y=NULL;
}
void out()
{
p=h;
p=p->next;
while(p!=NULL)
{
cout<<"姓名是:"<<p->name<<endl;
cout<<"地址是:"<<p->address<<endl;
cout<<"电话是:"<<p->phonenum<<endl;
p=p->next;
cout<<endl;
}
p=NULL;
}
void search(char *lname)
{
p=h;
p=p->next;
while(p!=NULL && strcmp(p->name,lname)!=0)
{
p=p->next;
}
if(p!=NULL)
{
cout<<"姓名是:"<<p->name<<endl;
cout<<"地址是:"<<p->address<<endl;
cout<<"电话是:"<<p->phonenum<<endl;
p=NULL;
}
else
{
cout<<"没找到此人信息!"<<endl;
p=NULL;
}
}
~tongxun()
{
}
private:
person *h,*p,*x,*s;
};
void main()
{
person *d;
tongxun t;
int k;
do
{
cout<<endl;
cout<<"\n\n 1. 建立个人通讯录 ";
cout<<"\n\n 2. 查找某人信息";
cout<<"\n\n 3. 结束程序运行";
cout<<"\n======================================";
cout<<"\n 请输入您的选择 (1,2,3)";
cin>>k;
switch(k)
{
case 1:
{
int i;
cout<<endl;
cout<<setw(5)<<"1.录入!"<<endl;
cout<<setw(5)<<"2.停止录入"<<endl;
cin>>i;
if(i==1)
{
while(i==1)
{
d=t.creat();
t.insert(d);
cout<<"1.录入!"<<setw(5)<<endl;
cout<<setw(5)<<"2.停止录入"<<endl;
cin>>i;
}
t.out();
}
} break;
case 2:
{
cout<<"请输入要查找某人的姓名:"<<endl;
cin>>d->name;
t.search(d->name);
} break;
} /* switch */
cout<<endl;
}while(k>=1 && k<3);
}
出现的问题:
查找异常