我错在那里了,高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/07/07 10:46:08
#include<iostream.h>
#include<iomanip.h>
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{
char name[10];
int xuehao[15];
int roomnumber[15];

struct student *next;
};

struct student *creat(void) //创建链表
{
struct student *head,*p1;
int n=0,i;
cout<<"请输入链表的个数"<<endl;
cin>>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<<"name:";
cin>>p1->name;
cout<<"xuehao:";
cin>>p1->xuehao[15];
cout<<"roomnumber:";
cin>>p1->roomnumber[15];

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

共修改四处,具体位置请参考下面程序中的注释位置:

//---------------------------------------------------------------------------

#include<iostream.h>
#include<iomanip.h>
#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#define LEN sizeof(struct student)
struct student
{
char name[10];
int xuehao; /*注意这里*/
int roomnumber; /*注意这里*/

struct student *next;
};

struct student *creat(void)
{
struct student *head,*p1;
int n=0,i;
cout<<"请输入链表的个数"<<endl;
cin>>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<<"name:";
cin>>p1->name;
cout<<"xuehao:";
cin>>p1->xuehao; /*注意这里*/
cout<<"roo