我错在那里了,高手帮忙

[复制链接]
查看11 | 回复3 | 2008-10-10 21:14:40 | 显示全部楼层 |阅读模式
#include
#include
#include
#include
#include
#define LEN sizeof(struct student)
struct student
{
char name[10];
intxuehao[15];
int roomnumber[15];
structstudent *next;
};
struct student *creat(void)//创建链表
{
struct student *head,*p1;
int n=0,i;
cout>n;
head=(struct student*)malloc(LEN);

head->next=NULL;
if(!head)exit(0);
for(i=n;i>0;--i)
{p1=(struct student*)malloc(LEN);

if(!p1)exit(0);

cout>p1->name;

cout>p1->xuehao[15];

cout>p1->roomnumber[15];

p1->next=head->next;head->next=p1;//wenti

}
return p1;
}
void print(struct student*head)//输出学生的成绩
{

struct student *p;

p=head;

coutnamexuehaoroomnumbernext;

}while(p!=NULL);
}
void main()
{
struct student *head;
cout#include#include#define LEN sizeof(struct student)struct student{char name[10];int xuehao;
/*注意这里*/int roomnumber;...
回复

使用道具 举报

千问 | 2008-10-10 21:14:40 | 显示全部楼层
呼呼,找到啦这里int xuehao[15]; int roomnumber[15];改成int xuehao; int roomnumber; 知道为什么了吧再不懂,再问...
回复

使用道具 举报

千问 | 2008-10-10 21:14:40 | 显示全部楼层
典型的野指针呀!struct中的int xuehao[15]; int roomnumber[15]; 不应定义为数组,如果像多位,请定义为Char,然后可按字符数组处理。还有问题百度消息我。...
回复

使用道具 举报

千问 | 2008-10-10 21:14:40 | 显示全部楼层
......p1->next=head->next;head->next=p1;//头插法建链表 } return head;//返回头指针,p1不是头指针而是头指针指向的节点...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行