南宁到郑州飞机:高分悬赏,高手请进:)

来源:百度文库 编辑:神马品牌网 时间:2024/05/01 04:24:57
为什么不能打印?
编译能通过,为什么打印函数就是不能打印出结果?
运行环境:Visual C++6.0
#include<iostream>//不能写成#include<iostream.h>,不知道为什么?
using namespace std;

struct Llist
{
char name[20];
int sign;
struct Llist *next;
};

struct Llist *creat()
{
struct Llist *p,*p1,*p2;
int flag=0;//在建表过程中判断用户是否要退出建立工作
cout<<"if you have finish instruction please let the flag be 0! Continue let it be 1"<<endl;
p=new Llist;//建立第一个结点,不知道是不是这样????????????还是struct Llist
p1=p;
p2=p;
cout<<"Please input the name the person:"<<endl;
cin.get(p->name,20);
cin.get();//吸收回车键
cout<<"Please input the sign the person:"<<endl;
cin>>p->sign;
cin.get();//吸收回车键
cout<<"/t* Another?Please input the flag: *"<<endl;
cin>>flag;
cin.get();//吸收回车键
while(flag)
{
p2=new Llist;
p1->next=p2;
cout<<"Please input the name the person:"<<endl;
cin.get(p2->name,20);
cin.get();//吸收回车键
cout<<"Please input the sign the person:"<<endl;
cin>>p2->sign;
cin.get();//吸收回车键
cout<<"Another?Please input the flag:"<<endl;
cin>>flag;
cin.get();//吸收回车键
if(flag)
{
p1=p2;
}
}
p2->next=NULL;//尾结点指针置空
return(p);
}

void display(Llist *p)
{
do
{
cout<<p->name<<endl;
cout<<p->sign<<endl;
p++;
}while(p->next!=NULL);
// cout<<p->name<<endl;//打印最后一个结点
// cout<<p->sign<<endl;
}

void main()
{
struct Llist *p;
int m;
cout<<"Please input the m:"<<endl;
cin>>m;
cin.get();//吸收回车键
if(m==1)
{
p=creat();
display(p);
}

}

//帮你修改了几处错误,可以了
#include<iostream> //c++标准类库必须这样写
using namespace std;

struct Llist
{
char name[20];
int sign;
Llist *next; //去掉struct修饰,下面几行也是如此
};

Llist *creat()
{
Llist *p,*p1,*p2;
int flag=0;
cout<<"if you have finish instruction please let the flag be 0! Continue let it be 1"<<endl;
p=new Llist;
p1=p;
p2=p;
cout<<"Please input the name the person:"<<endl;
cin.get(p->name,20);
cin.get();
cout<<"Please input the sign the person:"<<endl;
cin>>p->sign;
cin.get();
cout<<"/t* Another?Please input the flag: *"<<endl;
cin>>flag;
cin.get();
while(flag)
{
p2=new Llist;
p1->next=p2;
cout<<"Please input the name the person:"<<endl;
cin.get(p2->name,20);
cin.get();
cout<<"Please input the sign the person:"<<endl;
cin>>p2->sign;
cin.get();
cout<<"Another?Please input the flag:"<<endl;
cin>>flag;
cin.get();
if(flag)
{
p1=p2;
}
}
p2->next=0; //这样表示空指针!
return(p);
}

void display(Llist *p)
{
do
{
cout<<p->name<<endl;
cout<<p->sign<<endl;
//p++; //不要用p++,p不是数组.
}while(p=p->next); //这样写

}

void main()
{
Llist *p;
int m;
cout<<"Please input the m:"<<endl;
cin>>m;
cin.get();
if(m==1)
{
p=creat();
display(p);
}

cin>>m; //暂停用
}

暂停可以用
system("pause");