一个判断条件的错误
# include <iostream.h>
struct s {
char name[20];
char address[30];
s* nexts; };
s* head;
s* create()// 创建连表
{
s* new_node=new s;
head=NULL;
s* end=new_node;
while(new_node->name!=0)//问题:这个条件总是真,如何输入是new_node->name==0?
{
if(head==NULL)
head=new_node;
else
end->nexts=new_node;
end=new_node;
new_node=new s;
cout<<"please input name &address:\n";
cin>>new_node->name>>new_node->address;
}
end=NULL;
delete new_node;
return head;
}
void showlist(s*head)
{
while(head)
{
cout<<head->name<<" "<<head->address<<endl;
head=head->nexts;
}
}
void main()
{
showlist(create());
}